Created
July 16, 2018 10:16
-
-
Save elktros/e1d175ee942f722f897eb22cf63a145c to your computer and use it in GitHub Desktop.
Code for controlling a Relay using Sound Sensor and Arduino.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int relayPin = 11; | |
const int soundPin = 7; | |
int soundVal = 0; | |
int relayToggle = LOW; | |
int previousState = HIGH; | |
void setup () | |
{ | |
pinMode (relayPin, OUTPUT); | |
pinMode (soundPin, INPUT); | |
} | |
void loop () | |
{ | |
soundVal = digitalRead(soundPin); | |
if (soundVal == LOW && previousState==HIGH) | |
{ | |
relayToggle=!relayToggle; | |
digitalWrite (relayPin, relayToggle); | |
} | |
previousState=soundVal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment