summaryrefslogtreecommitdiff
path: root/5-microfono-relay.ino
blob: 83fe59902da28d39b8943426b99fe7d191459e2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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);
}