Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1.  
  2.  
  3. int lightPin = 0; //define a pin for Photo resistor
  4. int buzzer = 9;
  5. int button = 2;
  6.  
  7. void setup()
  8. {
  9. Serial.begin(9600); //Begin serial communcation
  10. pinMode(buzzer, OUTPUT);
  11. pinMode(button, INPUT);
  12. }
  13.  
  14. void loop()
  15. {
  16. int val = analogRead(lightPin);
  17. if(val < 250){ //adjust val for room
  18. while(1){
  19. if(digitalRead(button) == HIGH){
  20. noTone(buzzer);
  21. break;
  22. }
  23. else tone(buzzer, 261);
  24. }
  25. }
  26. else{
  27. noTone(buzzer);
  28. }
  29. Serial.println(analogRead(lightPin)); //Write the value of the photoresistor to the serial monitor.
  30.  
  31. delay(100); //short delay for faster response to light.
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement