Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Garduino with LCD, Soil Sensor and LDR for sunlight detection
- // LDR connects to AO
- // Soil Sensor on Digital 8
- // Pump connects via mosfet/relay to pin 13
- // Backlight Anode to pin 6 to enable backlight control
- // LCD rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2
- #include <LiquidCrystal.h>
- const int lightsensor = A0; // the number of the sun sensor pin
- const int soilsensor = 8; // the number of the soil sensor pin
- const int pumpPin = 13; // the number of the water pump pin
- const int BLPin = 6;
- const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
- LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
- // variables will change:
- int soilstate = 0; // variable for reading the sensor status
- int lightstate = 0; // variable for sun light
- void setup() {
- pinMode(BLPin, OUTPUT); // initialize lcd backlight pin
- pinMode(pumpPin, OUTPUT); // initialize the pump pin as an output:
- pinMode(soilsensor, INPUT); // initialize the soil sensor pin as an input:
- lcd.begin(16, 2); // set up the LCD's number of columns and rows:
- Serial.begin(9600); //configure serial to talk to computer
- }
- void loop() {
- soilstate = digitalRead(soilsensor); // read the state of the soil sensor value:
- lightstate = analogRead(lightsensor); // read the state of the light sensor value:
- Serial.println(lightstate);
- Serial.println(soilstate);
- if (soilstate == HIGH && lightstate < 450 ) {// turn pump on
- digitalWrite(pumpPin, HIGH);
- digitalWrite(BLPin, HIGH);
- lcd.display();
- lcd.print("Soil Dry");
- lcd.clear();
- } else if (soilstate == LOW && lightstate < 450) {// turn pump off
- digitalWrite(pumpPin, LOW);
- digitalWrite(BLPin, HIGH);
- lcd.display();
- lcd.print("Soil Wet");
- lcd.clear();
- } else if (soilstate == HIGH && lightstate > 450) {// turn pump and lcd off
- digitalWrite(pumpPin, LOW);
- digitalWrite(BLPin, LOW);
- lcd.noDisplay();
- lcd.clear();
- } else if (soilstate == LOW && lightstate > 450) {//turn pump and lcd off
- digitalWrite(pumpPin, LOW);
- digitalWrite(BLPin, LOW);
- lcd.noDisplay();
- lcd.clear();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement