RGB LED Sound Level Detector
by TechMartian in Circuits > Arduino
3897 Views, 16 Favorites, 0 Comments
RGB LED Sound Level Detector
![2016-07-08 17.23.05.jpg](/proxy/?url=https://content.instructables.com/FD0/7B4O/J4SQF2VO/FD07B4OJ4SQF2VO.jpg&filename=2016-07-08 17.23.05.jpg)
This is the seventh module to the series of Arduino 101 tutorials I've been writing.
In this project we will use a sound detector module from SparkFun and depending on the sound levels it is detecting, change the colour of an RGB LED, so you can tell how loud or quiet you have been. You can also use it to make the classic light clapper.
Tools and Materials
![2016-07-08 14.28.32.jpg](/proxy/?url=https://content.instructables.com/F0G/ALOU/J4SQF2WS/F0GALOUJ4SQF2WS.jpg&filename=2016-07-08 14.28.32.jpg)
- Arduino 101 or Arduino Uno
- Sound Detector from Sparkfun - https://www.sparkfun.com/products/12642
- RGB LED
- 3 100Ω Resistors
- Jumper Wires
Circuit
![2016-07-08 17.23.38.jpg](/proxy/?url=https://content.instructables.com/FB5/SG5H/J4SQF2VP/FB5SG5HJ4SQF2VP.jpg&filename=2016-07-08 17.23.38.jpg)
![Screen Shot 2017-07-09 at 11.47.49 PM.png](/proxy/?url=https://content.instructables.com/F76/E7EO/J4SQF36F/F76E7EOJ4SQF36F.png&filename=Screen Shot 2017-07-09 at 11.47.49 PM.png)
![2016-07-08 17.26.46.jpg](/proxy/?url=https://content.instructables.com/FQY/FWZ7/J4SQF2VU/FQYFWZ7J4SQF2VU.jpg&filename=2016-07-08 17.26.46.jpg)
Firstly, we will connect the power from the Arduino board
- Connect the 3.3V pin of the Arduino board to the red power rail on the bread board with a red jumper wire
- Connect the GND pin of the Arduino board to the black power rail on the bread board with a black jumper wire.
Secondly, we will wire the RGB LED.
- Place the RGB LED anywhere on the bread board with all it's legs in different pin holes.
- The longest leg is the ground so connect this to the black power rail on the breadboard.
- For the remaining three pins connect the 100Ω resistors to each one of them.
- Connect the ends of these resistor starting from the one closest to the ground to pins 5, 6, and 9 on the Arduino board, respectively.
Lastly, we will connect the wires to the sound detector module.
- Place the Sound detector module in a place away from the RGB LED on the breadboard.
- Connect the VCC of the sound detector module to the red power rail on the breadboard.
- Connect the GND of the sound detector module to the black ground rail on the breadboard.
- Connect the pin called "envelope" from the sound detector module to the A0 pin of the Arduino
Coding
![Screen Shot 2017-07-10 at 9.26.57 PM.png](/proxy/?url=https://content.instructables.com/F2W/AI2B/J4YFRWNZ/F2WAI2BJ4YFRWNZ.png&filename=Screen Shot 2017-07-10 at 9.26.57 PM.png)
//pin variables
const int redPin = 5; const int greenPin = 6; const int bluePin = 9; const int soundPin = 0;
//variables for storing raw sound and scaled value int sound; int scale;
void setup() { //start the serial port a@ 9600bps Serial.begin(9600); //set RGB pins to OUTPUT pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); }
void loop() { //read and store the audio from Envelope pin sound = analogRead(soundPin); //map sound which in a quiet room a clap is 300 //from 0 to 3 to be used with switch case scale = map(sound, 0, 300, 0, 3);
//print values over the serial port for debugging Serial.print(sound); Serial.print(" "); Serial.println(scale);
//switch case on scaled value switch (scale) { //if 0 RGB = Blue case 0: digitalWrite(redPin, LOW); digitalWrite(greenPin, LOW); digitalWrite(bluePin, HIGH); break; //if 1 RGB = Green case 1: digitalWrite(redPin, LOW); digitalWrite(greenPin, HIGH); digitalWrite(bluePin, LOW); break; //if 2 RGB = Yellow case 2: digitalWrite(redPin, HIGH); digitalWrite(greenPin, HIGH); digitalWrite(bluePin, LOW); break; //if 3 RGB = Red case 3: digitalWrite(redPin, HIGH); digitalWrite(greenPin, LOW); digitalWrite(bluePin, LOW); break; //default off default: digitalWrite(redPin, LOW); digitalWrite(greenPin, LOW); digitalWrite(bluePin, LOW); break; } }
Demo
![RGB Sound Detector Demo](/proxy/?url=https://content.instructables.com/FQ7/0XFQ/J4YFRVFT/FQ70XFQJ4YFRVFT.jpg&filename=RGB Sound Detector Demo)
The colour of the LED changes depending on how loud the environment is, with red being the loudest and no light being very quiet.