Translate

Monday, March 7, 2016

Turn Your Lights On With Clapping -Arduino Sound Sensor Project

"Clap Clap" Lights On



Materials;

1- Arduino Uno

2- Sound Sensor

3- LED


4- Some Wires




5-Breadbord

!!!

  • Sound sensor out pin go to Arduino pin 4 
  • VCC pin go to Arduino pin 5V
  • GND pin go to Arduino pin GND
  • led + pole go to Arduino pin 5 
  • led - pole go to Arduino pin GND 

ARDU─░NO CODES


int sound_sensor = 4; int led = 5; int clap = 0; long sensation_distance_starting = 0; long sensation_distance = 0; boolean light_status = false; void setup() { pinMode(sound_sensor, INPUT); pinMode(led, OUTPUT); } void loop() { int sensor_status = digitalRead(sound_sensor); if (sensor_status == 0) { if (clap == 0) { sensation_distance_starting = sensation_distance = millis(); clap++; } else if (clap > 0 && millis()-sensation_distance >= 50) { sensation_distance = millis(); clap++; } } if (millis()-sensation_distance_starting >= 400) { if (clap == 2) { if (!light_status) { light_status = true; digitalWrite(led, HIGH); } else if (light_status) { light_status = false; digitalWrite(led, LOW); } } clap = 0; } }