Skip to content

Project 2.13.3: OPERATING A SOUND SENSOR WITH THREE LEDs

Description You will learn how to build a simple circuit which turns ON and OFF three LEDs in response to sound.
Use case Flickering lights in response to sound beats from a speaker.

Components (Things You will need)

Arduino Uno Arduino USB Cable Breadboard Jump wire LED Sound Sensor

Building The Circuit(Things You Will Need)

  • Arduino Uno = 1
  • Arduino USB cable = 1
  • Sound Sensor = 1
  • LED = 3
  • Red jumper wire = 1
  • Black jumper wire = 2
  • Green jumper wire = 1
  • Orange jumper wire = 1
  • Blue jumper wire = 1
  • Purple Jumper Wire = 1
  • White Jumper = 1
  • Brown Jumper = 1
  • Breadboard = 1

Mounting The Component On The Breadboard

Step 1: Insert the sound sensor on the bread board and make sure each pair of the pins are connected on each side of the bridge. As shown in the picture below:

Picture1

Step 2: Connect the LEDs to the breadboard as shown below.

Picture2

WIRING THE COMPONENTS

Step 1: Connect the green male-to-male jumper wire to (D0) on the sound sensor and the other end of the wire to digital pin 6 on the Arduino board as shown below.

Picture3

Step 2: Connect the red male-to-male jumper wire to (+) on the sound sensor to 5V on the Arduino UNO board as shown in the image.

Picture3.1

Step 3: Connect the black male-to-male jumper wire to (G) on the sound sensor and the other end of the wire to GND on the Arduino UNO. As shown in the picture below.

Picture4

Step 4: Connect the black male-to-male jumper wire to (A0) on the sound sensor and the other end of the wire toA0 on the Arduino UNO. As shown in the picture below:

Picture5

Step 5: Connect the yellow male-to-male jumper wire to the positive (longer leg) of the Blue LED and the other end to the digital pin 8 on the Arduino board as shown below.

Picture6

Step 6: Using the brown male-to-male jumper wire, connect one end to the negative (shorter leg) of the blue LED and the other end to the “GND” on the Arduino, as shown below.

Picture7

Step 7: Connect the purple male-to-male jumper wire to the positive (longer leg) of the green LED and the other end to the digital pin 9 on the Arduino board as shown below.

Picture8

Step 8: Using the green male-to-male jumper wire, connect one end of the wire to the negative (shorter leg) of the green LED and the other end to the “GND” on the Arduino as shown below.

Picture9

Step 9: Connect the red male-to-male jumper wire to the positive (longer leg) of the red LED and the other end to the digital pin 2 on the Arduino board as shown below. end to the “GND” on the Arduino, as shown below.

Picture7

Step 10: Using the white male-to-male jumper wire, connect one end of the wire to the shorter leg (positive) of the red LED and the other end to the “GND” on the breadboard as shown below.

Picture8

Step 11: Connect the black male-to-male jumper wire, to the GND connector on the breadboard and the other end to the GND port on the Arduino UNO board.

Picture9

PROGRAMMING

Step 1: Open your Arduino IDE. See how to set up here: Getting Started.

Step 2: Type

            const int SoundSensorPin = A0; 
            const int SoundSensorD0 = 6; 
            const int LED = 8;
            const int LED2 =9; 
            const int LED3 =2;
as shown in the picture below.

Code1

NB: Make sure you avoid errors when typing. Do not omit any character or symbol especially the bracket {} and semicolons; and place them as you see in the image. The code that comes after the two backslashes “//” are called comments. They are not part of the code that will be run, they only explain the lines of code. You can avoid typing them.

Step 3: In the { } after the void setup (),Type

        pinMode(SoundSensorPin, INPUT);
        pinMode (soundSensorDO, INPUT);  
        pinMode (LED, OUTPUT); 
        pinMode (LED2, OUTPUT);
        pinMode (LED3, OUTPUT);
        Serial.begin (9600); 
as shown below in the image.

Code2

The code above activates the serial monitor and LEDS.

Step 4: In the {} after the void loop (), Type int SensorData = digitalRead(SoundSensorDO); int SoundValue = analogRead (SoundSensorPin); as shown below in the image.

Code3

NB:The above code reads data from the soundSensorPin.

Step 5: Type if (soundValue > 100 ) { } ; as shown below in the image.

Code4

Step 6: Type

 digitalWrite(LED, HIGH); 
                   digitalWrite(LED2, HIGH);
                   digitalWrite(LED3, HIGH)
                   Serial.println(SoundValue);
                    delay(200);
                    Serial.printIn(SoundValue)
as shown below in the image.

Code5

Step 7: And on the next line, Type else { } ; as shown below in the image.

Code6

Step 8: Type

``` cpp
 digitalWrite (LED, LOW);
    digitalWrite (LED, LOW);
    digitalWrite (LED3, LOW); 
    ```
 as shown below in the image.

Code7

CONCLUSION

If you encounter any problems when trying to upload your code to the board, run through your code again to check for any errors or missing lines of code. If you did not encounter any problems and the program ran as expected, Congratulations on a job well done.