Arduino Light Clapper

Поделиться
HTML-код
  • Опубликовано: 29 сен 2024
  • 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!

Комментарии • 24

  • @olivertomlinson5437
    @olivertomlinson5437 9 лет назад

    dude this is mental!

  • @ericinventor
    @ericinventor  9 лет назад +1

    #include
    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) 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;
    }

    • @nokel2
      @nokel2 6 лет назад

      I'm having trouble with this code, when I clap, the TX light flashes, but nothing happens... Do I have to make a separate file for my servo?

    • @rethno
      @rethno 5 лет назад

      I did this but my servo didn't stop turning until i plug the usb. What might be wrong?

  • @ericinventor
    @ericinventor  9 лет назад

    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
    @ericinventor  9 лет назад +2

    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

  • @kohlharvey7452
    @kohlharvey7452 9 лет назад +4

    can you post the code for this??

  • @bignerd8050
    @bignerd8050 3 года назад

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

  • @matadin7405
    @matadin7405 2 года назад

    tell me about its process

  • @CarlosU1
    @CarlosU1 9 лет назад +2

    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

  • @dormitor187
    @dormitor187 6 лет назад

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

  • @gilbertfoo9164
    @gilbertfoo9164 6 лет назад

    Hello Eric, I'm quite new to the Arduino and after copying your code and following your instructions the servo motor just keeps rotating back and forth, this is what I have done: imgur.com/9CjTQYG

    • @ericinventor
      @ericinventor  6 лет назад

      I believe you have connected an analog microphone into a digital GPIO, when you should be connecting it to an analog input port, A0 for example

  • @gilbertfoo9164
    @gilbertfoo9164 6 лет назад

    How long will the battery last?

  • @trotanium13
    @trotanium13 9 лет назад

    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.

    • @ericinventor
      @ericinventor  9 лет назад

      trotanium13 I am lucky because I have always had plenty of tools since my grandfather was a carpenter. But I also took advantage of my high school's resources by starting a robotics club. My school gave our club lots of funding to get tools and equipment. Don't give up. If inventing is truly your passion you will find away to pursue it. It is not too late. All you need is a little motivation, hard work, and some creativity. Be sure to watch the vending machine video series I have started.

    • @trotanium13
      @trotanium13 9 лет назад

      ericinventor well i lack resources in the first place, and the robotics club are full haha. well i guess i could start by doing something easy. hows the vending machine ? i would love to see part 2

  • @KDVSmith
    @KDVSmith 9 лет назад

    ERICOOOOOO!

  • @nadavram7322
    @nadavram7322 7 лет назад

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

    • @nadavram7322
      @nadavram7322 7 лет назад

      All it's doing for me is just spinning the servo back and forth....

    • @ericinventor
      @ericinventor  7 лет назад

      Nadav Ram Hi, you will most likely have to mess with your threshold value since you may be using a different sensor. Play around with the threshold value to see if that works

    • @Toby-yz7wt
      @Toby-yz7wt 4 года назад

      @@ericinventor Hello I had the same issue as Nadav. I changed the threshold, but nothing happens after 250.
      I noticed in the code there was DA for analog output. What is that for? We did not connect anything to analog. We did digital instead.

  • @ragushel2201
    @ragushel2201 8 лет назад

    what servo did you use

    • @ericinventor
      @ericinventor  8 лет назад

      +Ragushel Not sure exactly sorry but it is a Futuba servo for RC airplanes