SODAQ
Connect Anything Anywhere

6. Creating a volume monitor with a red LED alarm for high levels
In this tutorial you will learn how to connect the grove sound sensor to the SODAQ, and how to make a Red colored LED turn on at high sound volumes.
Required components:
SODAQ Moja
0.5W Solar Panel
1aH battery pack
Grove - Red LED
Grove - Sound Sensor
2x Grove w/o Buckle Cable (any length)
First, plug the Sound Sensor into the A0/A1 pin in the always on row.
Then, plug the Red LED Grove into the D4/D5 pin in the always on row.
Next, plug the 0.5W solar panel and the 1A LiPo battery into the respective sockets (see http://www.sodaq.net/#!getting-started/c21ma for a board diagram)
Turn on the SODAQ board, compile and upload the following sketch from the arduino IDE onto the SODAQ Board, and then unplug the USB cable from the computer when it is working:
(caution: if it doesnt work, the LED could be in the socket the wrong way, TURN IT AROUND! and look at the shape of the LED with respect to the shape of the white area behind the socket) - You should be able to make the light glow by singing loudly into the Sound Sensor!

// Function: If the sound sensor senses a sound that is up to the threshold you set in the code, the LED is on for 200ms.
// Hardware: Grove - Sound Sensor, Grove - Red LED
/*macro definitions of the sound sensor and the LED*/
#define SOUND_SENSOR A0
#define LED 4 // the number of the LED pin
#define THRESHOLD_VALUE 400
//The threshold to turn the led on 400.00*5/1024 = 1.95v
void setup()
{
Serial.begin(9600);
pins_init();
}
void loop()
{
int sensorValue = analogRead(SOUND_SENSOR);
//use A0 to read the electrical signal
Serial.print("sensorValue ");
Serial.println(sensorValue); if(sensorValue > THRESHOLD_VALUE)
{
turnOnLED();
//if the value read from A0 is larger than 400,then light the LED
delay(200);
}
turnOffLED();
}
void pins_init()
{
pinMode(LED, OUTPUT);
pinMode(SOUND_SENSOR, INPUT);
}
void turnOnLED()
{
digitalWrite(LED,HIGH);
}
void turnOffLED()
{
digitalWrite(LED,LOW);
}