top of page
IMG_20170503_173438.jpg

Post

Learning electronics for kids: Control lights with Arduino and a sound sensor by clapping.


Arduino light control
Arduino light control



Hi there!!!


Welcome to Makersgeneration, your go-to destination for cool STEM projects and learning electronics for kids.


We're back again with another exciting Arduino project as usual!!


In today's post, we will be controlling lights just by clapping our hands. Wow!!


Sounds cool right!!? Keep reading as we learn How to make a clap switch with Arduino and Sound Sensor.



Clap switch


A clap switch uses a microphone to detect the sound of a clap. The sound is amplified and converted into a digital signal by an Arduino board. The Arduino compares the signal to a predefined threshold level. If the signal exceeds the threshold, the Arduino triggers an action, such as turning on or off an electrical device connected to the Arduino such as an LED as we will see here.


The main component of this project is the Sound sensor.


A sound sensor is a device used to detect sound levels and convert them into electrical signals that can be read and processed by an Arduino microcontroller. The sensor consists of a condenser microphone or a sound-sensitive element and supporting circuitry. The microphone gives out only analog signals when a sound wave hits the diaphragm of the sensor, this analog signal gets processed by the op-amp and we get the digital output.


Sound sensor module (KY-037)
Sound sensor module (KY-037)



Required components


electronic components
electronic components

  • Arduino Uno or Nano

  • Sound sensor module (KY-037)

  • LED (1)

  • 220 ohms resistor (1)

  • Jumper wires

  • Solderless breadboard

  • Compatible USB cable



Building the circuit


Sensor pins:

  • A0 to A0 of Arduino

  • G to GND of Arduino

  • + to 5V of Arduino

LED pins:

  • Short LED leg to GND of Arduino

  • Long LED leg to one leg of Resistor

  • The other leg of the resistor to Arduino pin3


Circuit diagram.
Circuit diagram.



Final electronic circuit
Final electronic circuit




Arduino timer code


const int ledPin = 3;
const int sensorPin = A0;
byte ledState = LOW;

void setup(){
    Serial.begin(9600);
    pinMode(ledPin, OUTPUT);
    pinMode(sensorPin, INPUT);
}

void loop(){
    int sensorValues = analogRead(sensorPin);
    Serial.print("Sensor values: ");
    Serial.println(sensorValues);
    delay(100);
    
    if ((sensorValues >= 200) && (ledState == LOW)){
        ledState = HIGH;
        digitalWrite(ledPin, ledState);
    }
    
    else if ((sensorValues >= 200) && (ledState == HIGH)){
        ledState = LOW;
        digitalWrite(ledPin, ledState);
    }
}


How code works:

  • In the first section, we declare the Arduino pins the LED (pin2) and sensor (pin A0) will be connected to.

  • Next, we create a variable to hold the current state of the LED. initially, it is assigned low, meaning the LED is off when the circuit turns on.

  • Inside the void setup() - we initialize Serial communication and then set pin A0 to receive data from the sensor (INPUT) and then pin 2 to send out data to the LED (OUTPUT).

  • Now, inside the void loop(), we begin by creating a variable (sensorValues) to store the data read from the sensor and then print those values out on the Serial monitor at intervals of 100 milliseconds.

  • According to the values printed on the Serial monitor, my sensor was reading below 200 when the room is quiet and goes above 200 when I clap - these are the values I will use to trigger my LED on/off (monitors your's to get the accurate value for your room).

  • clapsIn the if statement, the system monitors for claps. If the system detects claps, it will check the ledState to see if it is HIGH or LOW, If it is LOW, the system will replace the value with HIGH which means turn on the LED. Then, if the ledState value is HIGH, it will change it to LOW which means turn off the LED.



To run the code:

  • Open the Arduino IDE, copy the code above, and paste it into the IDE's open window.

  • Navigate to Tools >> Select Board type (Arduino Uno or Nano) >> Select the correct Port assigned to your board.

Arduino IDE
Arduino IDE



Demo video




Alright! We have come to the end of today's topic. Hope you had fun and learned something cool.



Like to see more technology activities for kids? Follow the information below:




Online after-school and summer camps in Takoma Park Maryland


You and your children are looking for nice activities to have fun and learn new things and skills. Come join us starting in May and this summer for more online classes such as:

  • Python coding for kids and teens

  • Coding for elementary school students

  • Make video games

  • Electronics

  • Digital modeling (Create cars, rockets, rings, etc) for 3D printing and much more with the following link: Online after-schools


And the STEM summer camp for your kids is organized in Takoma Park Maryland nearby Washington DC to have fun and learn more about robotics, coding, droning, and more. Check the link right here:



Other cute things to make and hand-crafts for kids


If you are looking for more cool Arduino and kids' electronics project ideas to do with your kids, take a look at these other activities:




Newsletter, follow, subscribe, and like the social media


If you like online STEM activities, consider subscribing to the newsletter and social media for updates, and don't miss any STEM events. Don't forget to subscribe to the newsletter at the bottom of our website ''www.makersgeneration.net'' for more events, tutorials, and freebies.



Subscribe to the Facebook group if you have yet registered. Content and tutorials are shared daily: Create and build STEM projects for kids



We can be reached at: contact@makersgeneration.net if any questions.



See you on soon.










Categories

Recent Posts

Archive

Search By Tags

Follow Us

Comments

Share Your ThoughtsBe the first to write a comment.
bottom of page