Arduino Light Clapper

preview_player
Показать описание
This is my first Arduino project. It is a clapper light that I put in my room. I built it using an Arduino, a servo, a 9 volt, and a sound sensor/microphone. It will only flip the light switch if it recognizes two claps. Enjoy!
Рекомендации по теме
Комментарии
Автор

Hello Carlos, thanks for your comment. Your sound sensor should have 3 pins or 3 wires coming out of it. One(red) should go to 3.3V on the Arduino, the other (black or yellow) should go into ground. and the third wire should go into a digital sensor port. I used digital port 2. Same with your servo. Red and black into power and ground, and your third wire will go into a digital PWM port like port~9. Hope this helps

ericinventor
Автор

I envy you, when i was 12 i like to invent stuff but i quit cause all of em didnt work out due to lack of tools. Now im 17 and i regret quitting and amazed by your creations and dedications. Keep it up and post more videos i'll stay subscribe to your channel.

trotanium
Автор

I posted the code in a comment below. Sorry I couldn't think of a better way to do this. Copy and paste it into Arduino and it should work. You will have to tweak the threshold value for your sensor though.

ericinventor
Автор

Nice ! This is what I search for, THANKS! now I have a new Project

dormitor
Автор

Hello Eric, cool video man really enjoyed it. I wanted to build exactly this for my dorm, I have just order the supplies and I'm only missing the sound sensor. I understand the code but I can't tell from the video where I'm suppose to hook up the wires in the arduino and the sound sensor to connect them. If you could let me know where to connect the wires on the Arduino and on the sound sensor to connect them, I'd really appreciate it man.

Thanks for the video and help in advance

CarlosU
Автор

Love the project, I’ve got everything i need, except I can’t find the code for this project, repost please?

bignerd
Автор

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
 
int DO = 2; //Pin for Digital Output - DO
int DA = A3; // Pin for Analog Output - AO
int threshold = 108; //Set minimum threshold for LED lit
int sensorvalue = 0;
boolean light = true;
int clap = 0;
int count = 0;
int x;
unsigned long starttime;
unsigned long endtime;

void setup() 
{
  Serial.begin(9600);
  myservo.attach(9);
  myservo.write (10);
  delay (800);
}
 
void loop() {
  count = checkclap();
  Serial.println(count);
        
     if (count == 2)
      { if (light == true)
          lightoff(); 
        else
          {lighton(); }
      }  
}


int checkclap() 
{
  clap= 0;
 delay(40); 
  do{
      sensorvalue = analogRead(DA); 
      }while(sensorvalue < threshold);
       clap = 1;
       delay(100);
     
    starttime = millis();
    endtime = starttime;
  while ((millis()- starttime) <=500) // do this loop for up to 1000mS
  {
      sensorvalue = analogRead(DA);
      if (sensorvalue > threshold)
          {starttime = 0; clap = 2;}
  }
  
  if(clap !=2)
   {return clap;}
   delay(20);
  return clap; 
}

void lighton()
{
  myservo.write (85);
  delay (800);
  light = true;
}

void lightoff()
{
  myservo.write (10);
  delay (800);
  light = false;
}

ericinventor
Автор

Hello, I did all the wiring like you said in your comment and I used the exact same code and it isn't working???

nadavram