Arduino with Sound Sensor and LED

Arduino with Sound Sensor and LED

Hello everyone! Today I will show you how to use a sound sensor with arduino.

The required kits are :

  1. An arduino and its adapter
  2. Few jumper Wires
  3. A digital Sound sensor
  4. A led
There are 4 pins on the digital sound sensor. They are :

  1. AO-Analog pin
  2. G-Ground pin
  3. +-positive power pin
  4. DO-digital output pin
There are two legs on a LED. The longer leg is positive and the shorter leg is negative.

The steps to setup hardware are listed below:

  • Connect "+" pin to 5V pin on the arduino.
  • Connect "G" ground pin to GND pin on the arduino.
  • Connect "DO" digital output pin to any analog or digital pins on the arduino.In this tutorial I connected it with A2
  • Connect longer LED leg to pin 13 on the arduino. If you want to use anyother pin on the arduino, you need to use a 220 ohm resistor.
  • Connect shorter LED leg to GND pin on the arduino.

The setup is complete. Now, upload the code and enjoy.

Remember to adjust the potentiometer. Doing so will solve your led continuosly blinking problem.

Check out the tutorial here:

const int ledpin=13; // ledpin and soundpin are not changed throughout the process
const int soundpin=A2;
const int threshold=200; // sets threshold value for sound sensor
void setup() {
Serial.begin(9600);
pinMode(ledpin,OUTPUT);
pinMode(soundpin,INPUT);
}
void loop() {
int soundsens=analogRead(soundpin); // reads analog data from sound sensor
if (soundsens>=threshold) {
digitalWrite(ledpin,HIGH); //turns led on
delay(1000);
}
else{
digitalWrite(ledpin,LOW);
}
}

Comments

  1. Replies
    1. c:\program files\arduino\hardware\tools\avr\bin\../lib/gcc/avr/7.3.0/../../../../avr/bin/ar.exe: unable to rename 'core\core.a'; reason: Permission denied
      exit status 1
      Error compiling for board Arduino Uno

      Delete
    2. c:\program files\arduino\hardware\tools\avr\bin\../lib/gcc/avr/7.3.0/../../../../avr/bin/ar.exe: unable to rename 'core\core.a'; reason: Permission denied
      exit status 1
      Error compiling for board Arduino Uno

      Delete
    3. c:\program files\arduino\hardware\tools\avr\bin\../lib/gcc/avr/7.3.0/../../../../avr/bin/ar.exe: unable to rename 'core\core.a'; reason: Permission denied
      exit status 1
      Error compiling for board Arduino Uno

      Delete
  2. In which language we have to type this code..
    Will it work on c++ emulator

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. what is meant by setting the threshold value? I do we have to adjust the potentiometer?

    ReplyDelete
  5. What code should be written if i want to drive another pins along with pin 13, means i want my output on pin 13 also

    ReplyDelete
  6. Sorry last pin no was pin 12 not 13

    ReplyDelete
  7. Czy można dodać kolejne diody i jak?

    ReplyDelete
  8. c:\program files\arduino\hardware\tools\avr\bin\../lib/gcc/avr/7.3.0/../../../../avr/bin/ar.exe: unable to rename 'core\core.a'; reason: Permission denied
    exit status 1
    Error compiling for board Arduino Uno

    any solution for this

    ReplyDelete
  9. Hi do you do customized projects?

    ReplyDelete
  10. i need it so when there is no sound it goes of not when there is sound how would i chang the code

    ReplyDelete

Post a Comment

If you have any problems, please do notify me.