Automated plant watering with Arduino
Next Steps
For the last example, shown in Listing 3, I've used notification by missed call, which lets you use the GPRS module without increasing your phone bill. However, using this code as a base, you can use any other communication system that would notify you of the status of your plants.
Listing 3
Alarm and Control of Your Plants
01 // Include library for 1-Wire communication protocol 02 #include <OneWire.h> 03 // Include library to communicate easily with the sensors 04 #include <DallasTemperature.h> 05 06 // Define the pin Arduino will use with the 1-Wire protocol 07 #define ONE_WIRE_BUS 8 08 09 // Create a "oneWire" class to work with the chosen pin 10 OneWire oneWire(ONE_WIRE_BUS); 11 12 // Pass the data from the 1-Wire protocol to the Dallas library 13 DallasTemperature sensors(&oneWire); 14 15 // Static Variables 16 int sensorHumidity = A0; // Declare the humidity sensor pin variable 17 int pinModuleOn = 2; // Declare the pin variable to activate GPRS module 18 char phone_number[]="*********"; // the phone number to which the message is sent 19 20 // Dynamic Variables 21 int valueHumidity = 0; // Variable for the humidity value 22 float valueTemperature = 0; // Variable for the temperature value 23 24 void activateModule(){ // Function in charge of activating the GPRS module 25 digitalWrite(pinModuleOn,HIGH); 26 delay(2000); 27 digitalWrite(pinModuleOn,LOW); 28 } 29 30 void setup() { 31 // Initialize the serial port 32 Serial.begin(115200); 33 // Short time delay 34 delay(2000); 35 // Initialize the triggering pin from the module as it exits 36 pinMode(pinModuleOn, OUTPUT); 37 // Turn on the GPRS module 38 activateModule(); 39 // Wait a moment for the module to initialize 40 for (int i=0;i < 5;i++){ 41 delay(20000); 42 } 43 // Initialize the 1-Wire protocol and the sensor 44 sensors.begin(); 45 } 46 47 void loop() { 48 // Query the temperature on the device 49 sensors.requestTemperatures(); 50 // Store the temperature value 51 valueTemperature = sensors.getTempCByIndex(0); 52 // Read the analog value of the sensor and store it 53 valueHumidity = analogRead(sensorHumidity); 54 // Check that the measurements are within sane ranges 55 if ( (valueHumidity<400) || (valueTemperature<24)) { 56 // The missed call is made when the measurements are dangerous for the plant 57 Serial.print("ATD"); 58 Serial.print(phone_number); 59 Serial.println(";"); 60 // Missed call 61 delay(20000); 62 // Finalize the missed call 63 Serial.println("ATH"); 64 delay(10000); 65 } 66 }
Alternatively, you can use the Arduino Ethernet Shield [8] to upload the data or to notify by Internet. In this case, it's only necessary to change the part of the code that uses the GPRS to use the Ethernet module.
Infos
- RTC: http://www.cooking-hacks.com/index.php/twig-grove-rtc.html
- Temperature probe: http://www.cooking-hacks.com/index.php/temperature-sensor-waterproof-ds18b20.html
- OneWire library: http://www.pjrc.com/teensy/arduino_libraries/OneWire.zip
- DallasTemperature library: http://download.milesburton.com/Arduino/MaximTemperature/DallasTemperature_372Beta.zip
- Water pump: http://www.cooking-hacks.com/index.php/immersible-pump-water-tube.html
- Humidity sensor: http://www.cooking-hacks.com/index.php/grove-moisture-sensor.html
- GPRS module: http://www.cooking-hacks.com/index.php/documentation/tutorials/arduino-gprs-quadband
- Arduino Ethernet shield: http://arduino.cc/en/Main/ArduinoEthernetShield
« Previous 1 2 3 Next »
Buy this article as PDF
Express-Checkout as PDF
Pages: 6
Price $2.95
(incl. VAT)
(incl. VAT)