Shadowcat

KY-038 Microphone Module (Digital)

Mar 7th, 2020
672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // KY-038 Microphone Module (Sensor) (Digital version)
  2. int ledPin = 13;
  3. int sensorPin = 9;
  4. boolean val = 0;
  5. void setup() {
  6.   pinMode(ledPin, OUTPUT);
  7.   pinMode(sensorPin, INPUT);
  8. }
  9. void loop () {
  10.   val = digitalRead(sensorPin);
  11.   // When the sensor detects a signal above the threshold value, LED flashes
  12.   if (val == HIGH) {
  13.     digitalWrite(ledPin, LOW);
  14.   }
  15.   else {
  16.     digitalWrite(ledPin, HIGH);
  17.   }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment