Sensor + Arduino + Xbee transmitting data to Raspberry Pi + Xbee that tweets if moisture has been detected.
How does it work?
The moisture sensor is an Arduino connected to Xbee Adaptor and a printed circuit board with 555 timer. Leads are connected to a sponge that send resistance data to the circuit board. Arduino reads the data, adds the time and transmits the data to an Xbee connected to a Raspberry Pi. The Raspberry Pi sends out a Tweet with moisture status, e.g., “Extreme Moisture”.
Xbee (transfer/recieve), breadboard, leads, sponge, Arduino Uno, Raspberry Pi, USB wifi dongle, printed circuit board for 555 timer to take moisture readings
Moisture sensor using a 555 timer IC (Express PCB)
A way of quantifying the amount of moisture in a porous medium is to measure its electrical resistance. Typically, the higher the water content lower its resistance. Under most circumstances the resistance is in the mega-ohm (million ohms) range. As a reference a 100 feet of copper wire that would be used in house wiring has the resistance of a few Ohms at most. A moist medium has one-million times more resistance. We wanted to make a sensor that will give a number that is compatible with the kinds of data that an Arduino can comfortably handle, that would be an integer and between 1 and 20,000 or so.
One way of doing this is to make an resistor-capacitor (RC) circuit we could somehow charge up the capacitor and let it discharge through the moist resistive medium. A common 555 timer integrated circuit chip (IC) uses an RC circuit for its time base. We have exploited this feature to make a moisture sensor that can be triggered and read by an Arduino. The 555 can be configured in a number of ways for this application, we chose to use as a monostable-multi vibrator, a one-shot. Send the circuit a trigger pulse and the 555 will produce an output whose duration is determined by the values or the resistor and capacitor used for its time base. In this case the resistor will be the moist medium and we can choose a capacitor that will produce a pulse of 100’s or a few thousand milliseconds long (0.1 sec to a few seconds).
We tested it with damp paper towels and sponges to determine that a 1uF capacitor works well giving a pulse out of about 500-1000 milliseconds. We decided to measure moisture in milliseconds. The shorter the time, the higher the water content of the medium. Since we were going to deploy a number of sensors we designed a small printed circuit board for the sensor sent our design off to expresspcb.com to make the bare board.
Arduino + Xbee transmits to Raspberry PI + Xbee
Each setup has its own script for receiving or transmitting data.
Initial Raspberry Pi Set Up
To streamline the development process, we set up remote access via ssh. To complete this, we connected a usb wifi dongle to the Pi. The wifi connection is also important to the set up as we need internet access for the twitter implementation.
Serial Communication with the Raspberry Pi
During development, we researched Raspberry Pi GPIO and USB serial communications. One method for accessing the the GPIO pins is through UART, or universal asynchronous receiver/transmitter. UART is the piece of hardware that translates data between parallel and serial forms. By default, the the Raspberry Pi serial is configured to use the UART for console input and output. However, that means the Serial Port could not be used in our program. In order to access the dedicated UART pins on the raspberry pi, the serial ports needed to be reconfigured. After a few modifications, we can then receive communications. We later came to the decision to make use of an FTDI usb cable connected directly to an Xbee receiver.
We chose to use pySerial, a module that allows for access to the serial port in your python script. Like other python modules, pySerial needs to be installed and then imported in your program.
The serial data created by the moisture sensing circuit board is transmitted from the Arduino to Raspberry Pi between Xbees via radio frequency.
The Pi uses pySerial to accept that data. It begins by importing data from the specified USB port. Each Xbee that is transmitting data has been given a specific numerical name that is converted into a readable ID of Xbee 1 or Xbee 2 when its presence is detected.
Based on the values we were seeing in our tests, we specified any value of 3500 or above to mean that there is no moisture detected. A moisture status message is sent to the console and Twitter every time data is received. A value in the range of 700-1499 has a moisture status of “Extreme Moisture”. Likewise, 1500-2249 is “Medium Moisture”, and 2250-3500 is “Minimum Moisture.” Each time moisture is detected, the program resets itself to false and waits for the new data to be received.
To access the Twitter API via Python, we chose to use Tweepy, the well known Twitter for Python library. In order to set up Authentication keys, we signed up for the Twitter Developer account.
You must be logged in to post a comment.