Advertisement
computermuseo

water sensor + relay arduino

Apr 16th, 2015
5,763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1.  
  2. int lightPin = 0; // Analog Input
  3. int threshold = 500;
  4.  
  5. // the setup routine runs once when you press reset:
  6. void setup() {
  7. // initialize the digital pin 13 as an output.
  8. Serial.begin(9600);
  9. pinMode(13, OUTPUT);
  10.  
  11. }
  12.  
  13. // the loop routine runs over and over again forever:
  14. void loop() {
  15. Serial.println(analogRead(lightPin));
  16.  
  17. if(analogRead(lightPin) > threshold ){
  18. digitalWrite(13, HIGH);
  19. Serial.println("high");
  20. }else{
  21. digitalWrite(13, LOW);
  22. Serial.println("low");
  23. }
  24.  
  25. delay(1000); // wait for a second
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement