Advertisement
safwan092

Untitled

Feb 2nd, 2023
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. int pumpRelay = 6;
  2. int sensorPin = A0;
  3. int sensorValue = 0; // variable to store the value coming from the sensor
  4. #include<LiquidCrystal.h>
  5. /* Create object named lcd of the class LiquidCrystal */
  6. LiquidCrystal lcd(8, 9, 10, 11, 12, 13); /* For 4-bit mode */
  7. //LiquidCrystal lcd(8,9,10, 2, 3, 4, 5, 10,11,12,13); /* For 8-bit mode */
  8. byte degree[8] =
  9. {
  10. 0b00011,
  11. 0b00011,
  12. 0b00000,
  13. 0b00000,
  14. 0b00000,
  15. 0b00000,
  16. 0b00000,
  17. 0b00000
  18. };
  19. void setup()
  20. {
  21. pinMode(pumpRelay, OUTPUT);
  22. digitalWrite(pumpRelay, 0);
  23. lcd.begin(16, 2);
  24. lcd.createChar(1, degree);
  25. lcd.setCursor(2, 0);
  26. lcd.print("Arduino Point");
  27. lcd.setCursor(2, 1);
  28. lcd.print("Soil Moisture");
  29. delay(2000);
  30. lcd.clear();
  31. // Begin serial communication at a baud rate of 9600:
  32. Serial.begin(9600);
  33. }
  34. void loop()
  35. {
  36. // Get a reading from the Moisture sensor:
  37. sensorValue = analogRead(sensorPin);
  38.  
  39. // ------Display Moisture Sensor Value in Serial Monitor------ /
  40. Serial.print("Moisture Sensor Value:");
  41. Serial.println(sensorValue);
  42.  
  43. //Display the Moisture Percentage
  44. float moisturePercentage;
  45. moisturePercentage = (sensorValue / 1023) * 100;
  46. Serial.print("Moisture Percentage = ");
  47. Serial.print(moisturePercentage);
  48. Serial.print("%\n");
  49.  
  50. //Display the plant need
  51. if (sensorValue < 300) {
  52. Serial.println("I am thirsty, please give me water");
  53. Serial.println("Pump is ON");
  54. digitalWrite(pumpRelay, 1);
  55. }
  56. else if (sensorValue > 300 && sensorValue < 700) {
  57. Serial.println("I feel so comfortable");
  58. }
  59. if (sensorValue > 700) {
  60. Serial.println("Too much water, I might get hurt");
  61. Serial.println("Pump is OFF");
  62. digitalWrite(pumpRelay, 0);
  63. }
  64.  
  65. Serial.print("\n");
  66.  
  67. // ------Display Moisture Sensor Value in LCD------ /
  68. lcd.clear();
  69. lcd.setCursor(0, 0);
  70. lcd.print("Soil Moisture");
  71.  
  72. lcd.setCursor(0, 1);
  73. lcd.print(sensorValue);
  74. lcd.setCursor(6, 1);
  75. lcd.print("&");
  76. lcd.setCursor(8, 1);
  77. lcd.print(moisturePercentage);
  78. lcd.print(" %");
  79. delay(500);
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement