Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //light Induction Desk Lamp
- int soundPin = A2; // Analog sound sensor is to be attached to analog
- int lightPin = A6; //Analog light sensor is to be attached to analog
- int ledPin = 4; // Digital LED is to be attached to digital
- void setup() {
- pinMode(ledPin, OUTPUT);
- pinMode(lightPin, INPUT);
- pinMode(soundPin, INPUT);
- }
- void loop(){
- int soundState = analogRead(soundPin); // Read sound sensor’s value
- int lightState = analogRead(lightPin); // Read light sensor’s value
- // if the sound sensor's value is greater than 500 or the sound sensor's is less than 200, the light will be on.
- //Otherwise, the light will be turned off
- if (soundState > 500 || lightState < 200) {
- digitalWrite(ledPin, HIGH);
- delay(500); //You can add the "//" to remove the delay
- }else{
- digitalWrite(ledPin, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement