Ollie Smeenk
Published

Creating a volume monitor with an alarm for high levels

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.

Full instructions provided823
Creating a volume monitor with an alarm for high levels

Things used in this project

Hardware components

SODAQ Moja
×1
0.5W Solar Panel
×1
1aH battery pack
×1
Grove - Red LED
×1
Grove - Sound Sensor
×1
Grove w/o Buckle Cable (any length)
×2

Story

Read more

Code

code.c

C/C++
code.c
// 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);
}

Credits

Ollie Smeenk
8 projects • 6 followers
Business-oriented Tinkerer! Ready to engage in any project for- and not for profit!

Comments