diff options
author | Luca Tringali <tringalinvent@libero.it> | 2020-02-15 23:22:04 +0100 |
---|---|---|
committer | Luca Tringali <tringalinvent@libero.it> | 2020-02-15 23:22:04 +0100 |
commit | 52f2260c5375fdc7a2e99da68be85e7f24848bc0 (patch) | |
tree | d23f54713713efe858091902d4710f283d1ce494 /5-microfono-relay.ino | |
parent | 091f0c084f44ba6ce1656cdc73ab034abc881620 (diff) |
Diffstat (limited to '5-microfono-relay.ino')
-rw-r--r-- | 5-microfono-relay.ino | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/5-microfono-relay.ino b/5-microfono-relay.ino new file mode 100644 index 0000000..83fe599 --- /dev/null +++ b/5-microfono-relay.ino @@ -0,0 +1,27 @@ +int sensorPin = A0; //KY-038 microphone +int relay = 13; +int sensorValue = 0; +bool on = false; + +void setup () +{ + pinMode (relay, OUTPUT); + digitalWrite (relay, LOW); + Serial.begin (9600); +} + +void loop () +{ + sensorValue = analogRead (sensorPin); + Serial.println (sensorValue, DEC); + if (sensorValue > 500) { + /*if (on == true) { + on = false; + } else { + on = true; + }*/ + on = !on; + } + digitalWrite (relay, on); + delay(100); +}
\ No newline at end of file |