Devices & Components
Arduino Uno Rev3
Grove - 4-Channel SPDT Relay
LDR, 5 Mohm
Resistor 220 ohm
DHT11 Temperature & Humidity Sensor (3 pins)
Solderless Breadboard Full Size
Alphanumeric LCD, 16 x 2
SparkFun Soil Moisture Sensor (with Screw Terminals)
Jumper wires (generic)
Resistor 10k ohm
Trimmer Potentiometer, 10 kohm
Software & Tools
Arduino IDE
Project description
Code
Arduino Greenhouse Automated Systems
c_cpp
link the Arduino uno board using usbA/usbB to pc and upload the code using the Arduino ide, to see the sensors graphs check the serial plotter
1//Libraries included 2#include <LiquidCrystal.h> 3#include <Adafruit_Sensor.h> 4#include <DHT.h> 5#include <DHT_U.h> 6 7//LCD digital pins connection 8LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 9//DHT11 digital pins connection and dht sensor type 10#define DHTPIN 13 11#define DHTTYPE DHT11 12DHT dht(DHTPIN, DHTTYPE); 13//4Relay module digital pins connection 14#define PIN_RELAY_1 7 // the Arduino digital pin 7 - IN1 pin of relay module 15#define PIN_RELAY_2 8 // the Arduino digitall pin 8- IN2 pin of relay module 16#define PIN_RELAY_3 9 // the Arduino digital pin 9 - IN3 pin of relay module 17#define PIN_RELAY_4 10 // the Arduino digital pin 10 - IN4 pin of relay module 18//define soil moisture sensor analog pin A0 19const int Soil_Pin = A0; 20const int Ldr_pin = A1; 21 22void setup() { 23 Serial.begin(9600); 24 lcd.begin(16, 2); // initialize the LCD 25 dht.begin(); // initialize the dht sensor 26 // initialize digital pins as an output. 27 pinMode(PIN_RELAY_1, OUTPUT); 28 pinMode(PIN_RELAY_2, OUTPUT); 29 pinMode(PIN_RELAY_3, OUTPUT); 30 pinMode(PIN_RELAY_4, OUTPUT); 31 //ldr read as input 32 pinMode(Ldr_pin, INPUT); 33} 34 35void loop() { 36 // wait between measurements.(500ms = 0.5 Second) 37 delay(500); 38 float temperature = dht.readTemperature(); // read temperature in Celsius // temperature in Celsius 39 float humidity = dht.readHumidity(); //read humidity //humidity declaration 40 41 //ldr read as analog 42 int ldr_Value = analogRead(Ldr_pin); 43 44 //soil sensor data in percentage 45 float moisture_percentage; 46 int sensor_analog; 47 sensor_analog = analogRead(Soil_Pin); 48 moisture_percentage = (100 - ((sensor_analog / 1023.00) * 100)); 49 50// Plot live data in the Arduino ide serial plotter 51 Serial.print(moisture_percentage); 52 Serial.print(" "); // a space ' ' or tab '\ ' character is printed between the two values. 53 Serial.print(temperature); 54 Serial.print(" "); // a space ' ' or tab '\ ' character is printed between the two values. 55 Serial.println(humidity); 56 Serial.print(" "); // a space ' ' or tab '\ ' character is printed between the two values. 57// lcd screen display order 58 lcd.setCursor(0, 0); 59 lcd.print("M %"); 60 lcd.setCursor(0, 1); 61 lcd.print(moisture_percentage); 62 lcd.setCursor(6, 0); 63 lcd.print("Tc"); 64 lcd.print((char)223);//shows degrees character 65 lcd.setCursor(6, 1); 66 lcd.print(temperature); 67 lcd.setCursor(12, 0); 68 lcd.print("H %"); 69 lcd.setCursor(12, 1); 70 lcd.print(humidity); 71// Conditional statment to control the relays (Greenhouse systems) 72 73 if (moisture_percentage < 60.00){ 74 digitalWrite(PIN_RELAY_1, LOW); // turn in1 ON 75 } else { 76 digitalWrite(PIN_RELAY_1, HIGH); // turn in1 OFF 77 } 78 if (temperature < 20) { 79 digitalWrite(PIN_RELAY_2, LOW); // turn in2 ON 80 } else { 81 digitalWrite(PIN_RELAY_2, HIGH); // turn in2 OFF 82 } 83 if (temperature > 30) { 84 digitalWrite(PIN_RELAY_3, LOW); // turn in3 ON 85 } else { 86 digitalWrite(PIN_RELAY_3, HIGH); // turn in3 OFF 87 } 88 if (ldr_Value < 300) { 89 digitalWrite(PIN_RELAY_4, LOW); // turn in4 ON 90 } else { 91 digitalWrite(PIN_RELAY_4, HIGH); // turn in4 OFF 92 } 93 94 delay(2000); // wait after loop for 2 Seconds 95 96}
Downloadable files
Greenhouse automated systems circuit
Greenhouse automated systems circuit

Comments
Only logged in users can leave comments