Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int pumpRelay = 6;
- int sensorPin = A0;
- int sensorValue = 0; // variable to store the value coming from the sensor
- #include<LiquidCrystal.h>
- /* Create object named lcd of the class LiquidCrystal */
- LiquidCrystal lcd(8, 9, 10, 11, 12, 13); /* For 4-bit mode */
- //LiquidCrystal lcd(8,9,10, 2, 3, 4, 5, 10,11,12,13); /* For 8-bit mode */
- byte degree[8] =
- {
- 0b00011,
- 0b00011,
- 0b00000,
- 0b00000,
- 0b00000,
- 0b00000,
- 0b00000,
- 0b00000
- };
- void setup()
- {
- pinMode(pumpRelay, OUTPUT);
- digitalWrite(pumpRelay, 0);
- lcd.begin(16, 2);
- lcd.createChar(1, degree);
- lcd.setCursor(2, 0);
- lcd.print("Arduino Point");
- lcd.setCursor(2, 1);
- lcd.print("Soil Moisture");
- delay(2000);
- lcd.clear();
- // Begin serial communication at a baud rate of 9600:
- Serial.begin(9600);
- }
- void loop()
- {
- // Get a reading from the Moisture sensor:
- sensorValue = analogRead(sensorPin);
- // ------Display Moisture Sensor Value in Serial Monitor------ /
- Serial.print("Moisture Sensor Value:");
- Serial.println(sensorValue);
- //Display the Moisture Percentage
- float moisturePercentage;
- moisturePercentage = (sensorValue / 1023) * 100;
- Serial.print("Moisture Percentage = ");
- Serial.print(moisturePercentage);
- Serial.print("%\n");
- //Display the plant need
- if (sensorValue < 300) {
- Serial.println("I am thirsty, please give me water");
- Serial.println("Pump is ON");
- digitalWrite(pumpRelay, 1);
- }
- else if (sensorValue > 300 && sensorValue < 700) {
- Serial.println("I feel so comfortable");
- }
- if (sensorValue > 700) {
- Serial.println("Too much water, I might get hurt");
- Serial.println("Pump is OFF");
- digitalWrite(pumpRelay, 0);
- }
- Serial.print("\n");
- // ------Display Moisture Sensor Value in LCD------ /
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Soil Moisture");
- lcd.setCursor(0, 1);
- lcd.print(sensorValue);
- lcd.setCursor(6, 1);
- lcd.print("&");
- lcd.setCursor(8, 1);
- lcd.print(moisturePercentage);
- lcd.print(" %");
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement