Components and supplies
SparkFun Soil Moisture Sensor (with Screw Terminals)
DHT11 Temperature & Humidity Sensor (4 pins)
remote control power socket
434MHz RF-transmitter
Arduino UNO
small indoor fountain pump (submersible) + hose
timer (optional)
Ultrasonic Sensor - HC-SR04 (Generic)
Tools and machines
Soldering iron (generic)
Apps and platforms
Arduino IDE
Project description
Code
Instant green thumb
arduino
1#include <RCSwitch.h> 2#include "DHT.h" 3 4RCSwitch mySwitch = RCSwitch(); 5 6//#define 7#define MOISTURE A0 8#define DHTPIN 2 9#define DHTTYPE DHT11 10DHT dht(DHTPIN, DHTTYPE, 15); 11 12//initial states 13int moisturecurrent = 0; 14int distancecurrent = 0; 15int duration = 0; 16 17//pins 18int TRIGGER = 5; 19int ECHO = 4; 20int POWER = 7; 21 22/************************SETUP****************************/ 23void setup() { 24 25 dht.begin(); 26 27 // set pin as an input/output 28 pinMode(MOISTURE, INPUT_PULLUP); 29 pinMode(POWER, OUTPUT); 30 pinMode(TRIGGER, OUTPUT); 31 pinMode(ECHO, INPUT); 32 33 Serial.begin(115200); 34 35 // Transmitter Arduino Pin 36 mySwitch.enableTransmit(12); 37 mySwitch.setPulseLength(306); 38 39} 40 41/*******************************LOOP**************************/ 42void loop() { 43 44 //switch off radio-controlled power socket 45 mySwitch.send(4212052, 24); 46 delay(1000); 47 mySwitch.send(4212052, 24); 48 delay(1000); 49 50 /*IF1:Temperature>5°C********************************/ 51 52 int humidity_data = (int)dht.readHumidity(); 53 int temperature_data = (int)dht.readTemperature(); 54 55 Serial.print(F("Temperature: ")); 56 Serial.println(temperature_data); 57 58 Serial.print(F("Humidity: ")); 59 Serial.println(humidity_data); 60 61 if (temperature_data > 5) 62 { 63 Serial.println(F("Temperature ok")); 64 65 /*IF2:Distance<25cm***************************/ 66 67 //Read sensor data: distance 68 digitalWrite(TRIGGER, LOW); 69 delay(5); 70 digitalWrite(TRIGGER, HIGH); 71 delay(10); 72 digitalWrite(TRIGGER, LOW); 73 duration = pulseIn(ECHO , HIGH); 74 distancecurrent = (duration / 2) / 29.1; 75 delay(1000); 76 77 int distance_data = (int)distancecurrent; 78 79 //publish 80 Serial.print(F("Distance: ")); 81 Serial.print(distance_data); 82 Serial.println(" cm"); 83 84 //dry-run safeguard for water pump: 85 //distance to bottom of water bucket: 30cm; min. water level: 5cm 86 //this will probably need adjusting to your specific setup 87 if (distance_data < 25) 88 { 89 90 /*IF3:moisture<300****************************/ 91 92 //Read sensor data: moisture 93 digitalWrite(POWER, HIGH); 94 moisturecurrent = analogRead(MOISTURE); 95 delay(1000); 96 digitalWrite(POWER, LOW); 97 98 int moisture_data = (int)moisturecurrent; 99 100 //publish 101 Serial.print(F("Soil moisture: ")); 102 Serial.println(moisture_data); 103 104 if (moisture_data < 400) 105 { 106 //switch on radio-controlled power socket 107 mySwitch.send(4212049, 24); 108 delay(1000); 109 mySwitch.send(4212049, 24); 110 delay(1000); 111 112 //water for 10 seconds 113 Serial.println(F("...Watering...")); 114 delay(10 * 1000); 115 116 //switch off power socket 117 mySwitch.send(4212052, 24); 118 delay(1000); 119 mySwitch.send(4212052, 24); 120 delay(1000); 121 122 Serial.println(F("Waiting 1 min.")); 123 for (int i = 1; i <= 1; i = i + 1) { 124 delay(20 * 1000); 125 Serial.print(F(".")); 126 delay(20 * 1000); 127 Serial.print(F(".")); 128 delay(20 * 1000); 129 Serial.println(F(".")); 130 } 131 132 } //ENDIF3 133 134 else 135 { 136 137 138 139 Serial.println(F("Watering not necessary at the moment.")); 140 Serial.println(F("Waiting 10 min.")); 141 for (int i = 1; i <= 10; i = i + 1) { 142 delay(20 * 1000); 143 Serial.print(F(".")); 144 delay(20 * 1000); 145 Serial.print(F(".")); 146 delay(20 * 1000); 147 Serial.println(F(".")); 148 } 149 } 150 151 } //ENDIF2 152 else 153 { 154 if (distance_data > 30) 155 { 156 Serial.println(F("Error. Unplausible water level.")); 157 } 158 else 159 { 160 Serial.println(F("Water bucket empty. Refill necessary!")); 161 } 162 Serial.println(F("Waiting 5 min.")); 163 for (int i = 1; i <= 5; i = i + 1) { 164 delay(20 * 1000); 165 Serial.print(F(".")); 166 delay(20 * 1000); 167 Serial.print(F(".")); 168 delay(20 * 1000); 169 Serial.println(F(".")); 170 } 171 } 172 173 } //ENDIF1 174 else { 175 Serial.println(F("Too cold for watering")); 176 } 177 178} //End loop 179 180
Instant green thumb
arduino
1#include <RCSwitch.h> 2#include "DHT.h" 3 4RCSwitch mySwitch = RCSwitch(); 5 6//#define 7#define MOISTURE A0 8#define DHTPIN 2 9#define DHTTYPE DHT11 10DHT dht(DHTPIN, DHTTYPE, 15); 11 12//initial states 13int moisturecurrent = 0; 14int distancecurrent = 0; 15int duration = 0; 16 17//pins 18int TRIGGER = 5; 19int ECHO = 4; 20int POWER = 7; 21 22/************************SETUP****************************/ 23void setup() { 24 25 dht.begin(); 26 27 // set pin as an input/output 28 pinMode(MOISTURE, INPUT_PULLUP); 29 pinMode(POWER, OUTPUT); 30 pinMode(TRIGGER, OUTPUT); 31 pinMode(ECHO, INPUT); 32 33 Serial.begin(115200); 34 35 // Transmitter Arduino Pin 36 mySwitch.enableTransmit(12); 37 mySwitch.setPulseLength(306); 38 39} 40 41/*******************************LOOP**************************/ 42void loop() { 43 44 //switch off radio-controlled power socket 45 mySwitch.send(4212052, 24); 46 delay(1000); 47 mySwitch.send(4212052, 24); 48 delay(1000); 49 50 /*IF1:Temperature>5°C********************************/ 51 52 int humidity_data = (int)dht.readHumidity(); 53 int temperature_data = (int)dht.readTemperature(); 54 55 Serial.print(F("Temperature: ")); 56 Serial.println(temperature_data); 57 58 Serial.print(F("Humidity: ")); 59 Serial.println(humidity_data); 60 61 if (temperature_data > 5) 62 { 63 Serial.println(F("Temperature ok")); 64 65 /*IF2:Distance<25cm***************************/ 66 67 //Read sensor data: distance 68 digitalWrite(TRIGGER, LOW); 69 delay(5); 70 digitalWrite(TRIGGER, HIGH); 71 delay(10); 72 digitalWrite(TRIGGER, LOW); 73 duration = pulseIn(ECHO , HIGH); 74 distancecurrent = (duration / 2) / 29.1; 75 delay(1000); 76 77 int distance_data = (int)distancecurrent; 78 79 //publish 80 Serial.print(F("Distance: ")); 81 Serial.print(distance_data); 82 Serial.println(" cm"); 83 84 //dry-run safeguard for water pump: 85 //distance to bottom of water bucket: 30cm; min. water level: 5cm 86 //this will probably need adjusting to your specific setup 87 if (distance_data < 25) 88 { 89 90 /*IF3:moisture<300****************************/ 91 92 //Read sensor data: moisture 93 digitalWrite(POWER, HIGH); 94 moisturecurrent = analogRead(MOISTURE); 95 delay(1000); 96 digitalWrite(POWER, LOW); 97 98 int moisture_data = (int)moisturecurrent; 99 100 //publish 101 Serial.print(F("Soil moisture: ")); 102 Serial.println(moisture_data); 103 104 if (moisture_data < 400) 105 { 106 //switch on radio-controlled power socket 107 mySwitch.send(4212049, 24); 108 delay(1000); 109 mySwitch.send(4212049, 24); 110 delay(1000); 111 112 //water for 10 seconds 113 Serial.println(F("...Watering...")); 114 delay(10 * 1000); 115 116 //switch off power socket 117 mySwitch.send(4212052, 24); 118 delay(1000); 119 mySwitch.send(4212052, 24); 120 delay(1000); 121 122 Serial.println(F("Waiting 1 min.")); 123 for (int i = 1; i <= 1; i = i + 1) { 124 delay(20 * 1000); 125 Serial.print(F(".")); 126 delay(20 * 1000); 127 Serial.print(F(".")); 128 delay(20 * 1000); 129 Serial.println(F(".")); 130 } 131 132 } //ENDIF3 133 134 else 135 { 136 137 138 139 Serial.println(F("Watering not necessary at the moment.")); 140 Serial.println(F("Waiting 10 min.")); 141 for (int i = 1; i <= 10; i = i + 1) { 142 delay(20 * 1000); 143 Serial.print(F(".")); 144 delay(20 * 1000); 145 Serial.print(F(".")); 146 delay(20 * 1000); 147 Serial.println(F(".")); 148 } 149 } 150 151 } //ENDIF2 152 else 153 { 154 if (distance_data > 30) 155 { 156 Serial.println(F("Error. Unplausible water level.")); 157 } 158 else 159 { 160 Serial.println(F("Water bucket empty. Refill necessary!")); 161 } 162 Serial.println(F("Waiting 5 min.")); 163 for (int i = 1; i <= 5; i = i + 1) { 164 delay(20 * 1000); 165 Serial.print(F(".")); 166 delay(20 * 1000); 167 Serial.print(F(".")); 168 delay(20 * 1000); 169 Serial.println(F(".")); 170 } 171 } 172 173 } //ENDIF1 174 else { 175 Serial.println(F("Too cold for watering")); 176 } 177 178} //End loop 179 180
Downloadable files
Fritzing diagram
Fritzing diagram
Fritzing diagram
Fritzing diagram
Documentation
Planter (sketchup file)
Planter (sketchup file)
Comments
Only logged in users can leave comments
b_anz
0 Followers
•0 Projects
Table of contents
Intro
8
0