From 52f2260c5375fdc7a2e99da68be85e7f24848bc0 Mon Sep 17 00:00:00 2001 From: Luca Tringali Date: Sat, 15 Feb 2020 23:22:04 +0100 Subject: Ultime lezioni --- 5-microfono-relay.ino | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 5-microfono-relay.ino (limited to '5-microfono-relay.ino') 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 -- cgit v1.1