Advertisement
safwan092

Untitled

Dec 7th, 2021
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3. #include <Servo.h>
  4.  
  5. Servo myservo; // create servo object to control a servo
  6.  
  7. LiquidCrystal_I2C lcd(0x27, 16, 2);
  8. const int buzzer = 13;
  9.  
  10. int x = 0;
  11.  
  12. // the setup routine runs once when you press reset:
  13. void setup() {
  14. // initialize serial communication at 9600 bits per second:
  15. Serial.begin(9000);
  16. pinMode(buzzer, OUTPUT);
  17. myservo.attach(9);
  18. myservo.write(90);
  19. // lcd.begin();
  20. lcd.init ();
  21. lcd.backlight();
  22. }
  23.  
  24.  
  25. // the loop routine runs over and over again forever:
  26. void loop() {
  27.  
  28. // read the input on analog pin 0:
  29. int sensorValue = analogRead(A0);
  30. // print out the value you read:
  31. Serial.println(sensorValue);
  32.  
  33. if (sensorValue < 500) {
  34. if (sensorValue < 500) {
  35. lcd.clear();
  36. lcd.print("Its raining");
  37. lcd.setCursor (0, 1);
  38. myservo.write(0);
  39. delay(10000);
  40. }
  41. digitalWrite(buzzer, HIGH);
  42. } else {
  43. lcd.clear();
  44. myservo.write(90);
  45. digitalWrite(buzzer, LOW);
  46. }
  47. delay(20); // delay in between reads for stability
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement