Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int lightPin = 0; //define a pin for Photo resistor
- int buzzer = 9;
- int button = 2;
- void setup()
- {
- Serial.begin(9600); //Begin serial communcation
- pinMode(buzzer, OUTPUT);
- pinMode(button, INPUT);
- }
- void loop()
- {
- int val = analogRead(lightPin);
- if(val < 250){ //adjust val for room
- while(1){
- if(digitalRead(button) == HIGH){
- noTone(buzzer);
- break;
- }
- else tone(buzzer, 261);
- }
- }
- else{
- noTone(buzzer);
- }
- Serial.println(analogRead(lightPin)); //Write the value of the photoresistor to the serial monitor.
- delay(100); //short delay for faster response to light.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement