Advertisement
safwan092

Untitled

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