Hi, I wish to create something where when a sound is detected on the Sound Sensor, the LCD screen is printed with "loud"
LCD Info:
i2c 16x2, address is 0x20, works fine with normal text, etcetc.
LCD Link
Analog Sound Sensor link
This is my setup:
I am a complete nub when it comes to coding and this kind of stuff, I haven't experimented much with this and I'm still learning, so please forgive me. Any help would be appreciated.

Let's see your best attempt at the code so far. Use code tags!
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x20 // <<----- Add your address here. Find it from I2C Scanner
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
int n = 1;
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
int soundDetectedPin = 10; // Use Pin 10 as our Input
int soundDetectedVal = HIGH; // This is where we record our Sound Measurement
boolean bAlarm = false;
unsigned long lastSoundDetectTime; // Record the time that we measured a sound
int soundAlarmTime = 500; // Number of milli seconds to keep the sound alarm high
void setup ()
{
lcd.begin (16,2); // <<----- My LCD was 16x2
// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home
Serial.begin(9600);
pinMode (soundDetectedPin, INPUT) ; // input from the Sound Detection Module
}
void loop ()
{
soundDetectedVal = digitalRead (soundDetectedPin) ; // read the sound alarm time
if (soundDetectedVal == LOW) // If we hear a sound
{
lastSoundDetectTime = millis(); // record the time of the sound alarm
// The following is so you don't scroll on the output screen
if (!bAlarm){
Serial.println("LOUD, LOUD");
lcd.print("LOUD");
bAlarm = true;
}
}
else
{
if( (millis()-lastSoundDetectTime) > soundAlarmTime && bAlarm){
Serial.println("quiet");
bAlarm = false;
}
}
}
So far, the code works, I upload it and the serial monitor prints "LOUD" and the LCD prints "LOUD" but its constantly on loud. Is this because the ambient noise is too loud?
Some sound sensors have an analog output and a digital output. You can adjust the sensitivity of the digital output by adjusting a pot on the sensor.
Your sensor has only an analog output. But you seem to have connected that to a digital input on the Arduino. So change that to one of the analog inputs and use analogRead() instead of digitalRead(). If you print the value to serial monitor, you will get so see the range of values you get with loud & quiet sounds. Then you can choose a value between those ranges and check the result of analogRead() against that value .
If you print the value to serial monitor, you will get so see the range of values you get with loud & quiet sounds.
And if you turn on the serial plotter instead of the serial monitor you get to see a graph or waveform diagram of what is coming in.
PaulRB:
Some sound sensors have an analog output and a digital output. You can adjust the sensitivity of the digital output by adjusting a pot on the sensor.
Your sensor has only an analog output. But you seem to have connected that to a digital input on the Arduino. So change that to one of the analog inputs and use analogRead() instead of digitalRead(). If you print the value to serial monitor, you will get so see the range of values you get with loud & quiet sounds. Then you can choose a value between those ranges and check the result of digitalRead() against that value .
This worked perfectly, thank you very much.
Grumpy_Mike:
And if you turn on the serial plotter instead of the serial monitor you get to see a graph or waveform diagram of what is coming in.
I found this very interesting, thanks.
claw106:
This worked perfectly, thank you very much.
Post your corrected code. It may be useful to others.