dwyl / iot-decibel-meter

A decibel meter built with an arduino
40 stars 8 forks source link

Light flashing on/off when noise is too loud #6

Open naazy opened 7 years ago

naazy commented 7 years ago

I've managed to successfully get an LED to flash on/off depending on the noise level with the set up below: 4pin_sensor_circuit-600x441

var five = require("johnny-five");

var analog = "A0"
var ledPin = 3;

five.Board().on("ready", function(){
  var led = new five.Led(ledPin);

  var analogSensor = new five.Sensor({pin:analog,
    freq: 1000,
    });

  analogSensor.on("data", function() {
    if(this.value > 700){
      led.on();
    } else {
      console.log('light off');
    }
 });
});