Help project

Guys can u help me ? idk why but my sound sensor isnt working with my led.
The LCD and buzzer is working.
Appreciate

// DHT Temperature & Humidity Sensor
// Unified Sensor Library Example
// Written by Tony DiCola for Adafruit Industries
// Released under an MIT license.

// Depends on the following Arduino libraries:
// - Adafruit Unified Sensor Library: GitHub - adafruit/Adafruit_Sensor: Common sensor library
// - DHT Sensor Library: GitHub - adafruit/DHT-sensor-library: Arduino library for DHT11, DHT22, etc Temperature & Humidity Sensors

#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
// Include Wire Library for I2C
#include <Wire.h>
// Include NewLiquidCrystal Library for I2C
#include <LiquidCrystal_I2C.h>

// Define LCD pinout
const int en = 2, rw = 1, rs = 0, d4 = 4, d5 = 5, d6 = 6, d7 = 7, bl = 3;

// Define I2C Address - change if reqiuired
const int i2c_addr = 0x27;

#define DHTPIN 5 // Pin which is connected to the DHT sensor.

// Uncomment the type of sensor in use:
#define DHTTYPE DHT11 // DHT 11

uint32_t delayMS;

// Define LCD display connections
LiquidCrystal_I2C lcd(i2c_addr, en, rw, rs, d4, d5, d6, d7, bl, POSITIVE);

// Define Variables
float hum; // Stores humidity value in percent
float temp; // Stores temperature value in Celcius

// Setup DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);

const int motionpin=A3 ; //variavel que o sensor vai ligar no arduino
const int ledpin=13; // Entrada 13 digital
const int buzzpin=4; // ledpin,motionpin and buzpin nao mudam durante o processo.
int motionsensvalue=0; // iniciar a 0

int soundSensor = A1;
int LED = 7;

void setup() {
// Set display type as 16 char, 2 rows
lcd.begin(16,2);

// Initialize DHT-22
dht.begin();

Serial.begin(9600);
pinMode (soundSensor, INPUT);
pinMode (LED, OUTPUT);
pinMode(ledpin, OUTPUT);
pinMode(motionpin,INPUT);
pinMode(buzzpin,OUTPUT);

}

void lcdisplay(){
delay(2000); // Delay so DHT-22 sensor can stabalize

hum = dht.readHumidity(); // Get Humidity value
temp= dht.readTemperature(); // Get Temperature value

// Clear the display
lcd.clear();

// Print temperature on top line
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print(" C");

// Print humidity on bottom line
lcd.setCursor(0,1);
lcd.print("Humid: ");
lcd.print(hum);
lcd.print(" %");
}

void buzzer(){
motionsensvalue=analogRead(motionpin); // lê dados analógicos do sensor de movimento
if (motionsensvalue>=200){
digitalWrite(ledpin,HIGH);
tone(buzzpin,100); //liga led e buzzer
}
else {
digitalWrite(ledpin,LOW); //voltas levou led e buzzer
noTone(buzzpin);//A função Tone() gera um sinal de onda
}
}

void soundsensor (){

int statusSensor = digitalRead (soundSensor);

if (statusSensor == 1)
{
digitalWrite(LED, HIGH);
}

else
{
digitalWrite(LED, LOW);
}

}

void loop() {
lcdisplay();
buzzer():

}

Tell me more about how you developed your program. Did you do a few instructions an then compile and test? Have you used the Serial.print() to display the variable values at each step? If so, at which point did the program stop working? Can you get back to a working version?

Paul

What type of sound sensor are you using and how is it wired to the Arduino ?

What do you mean by "isn't working" ?

Paul_KD7HB:
Tell me more about how you developed your program. Did you do a few instructions an then compile and test? Have you used the Serial.print() to display the variable values at each step? If so, at which point did the program stop working? Can you get back to a working version?

Paul

I had the program split in examples and i want to "stick" it all together and i can't because the sound sensor recognizes the sound but the led dont turn on

UKHeliBob:
What type of sound sensor are you using and how is it wired to the Arduino ?

What do you mean by "isn't working" ?

sound sensor module idk the model , its wired with jumper cables to the analog pin , and the sound sensor recognizes the sound and the led dont turn on , but if i try it in other programm just with the sound sensor example works so it might be logic error

Would it help if you called the soundsensor() function in the program ?

UKHeliBob:
Would it help if you called the soundsensor() function in the program ?

Do u mean :

void loop() {
lcdisplay();
buzzer();
soundsensor();
}

If yes , still dont turn on the led

That is what I meant

How long do you expect the led to stay on ?

UKHeliBob:
That is what I meant

How long do you expect the led to stay on ?

When i do some noise , the LED turn on , when i do it again the led turn OF , the weird thing is , if i make a new programm

int soundSensor=A1;
int LED=7;
boolean LEDStatus=false;

void setup() {
pinMode(soundSensor,INPUT);
pinMode(LED,OUTPUT);

}

void loop() {

int SensorData=digitalRead(soundSensor);
if(SensorData==1){

if(LEDStatus==false){
LEDStatus=true;
digitalWrite(LED,HIGH);
}
else{
LEDStatus=false;
digitalWrite(LED,LOW);
}
}
}

It works perfectly , so whats wrong on the other one , i dont get it

Compare

  int SensorData = digitalRead(soundSensor);
  if (SensorData == 1)
  {
    if (LEDStatus == false)
    {
      LEDStatus = true;
      digitalWrite(LED, HIGH);
    }
    else
    {
      LEDStatus = false;
      digitalWrite(LED, LOW);
    }
  }

with

  int statusSensor = digitalRead (soundSensor);
  if (statusSensor == 1)
  {
    digitalWrite(LED, HIGH);
  }
  else
  {
    digitalWrite(LED, LOW);
  }

You say that the first code works and the second doesn't but the code is different so perhaps that is not surprising.

UKHeliBob:
Compare

  int SensorData = digitalRead(soundSensor);

if (SensorData == 1)
  {
    if (LEDStatus == false)
    {
      LEDStatus = true;
      digitalWrite(LED, HIGH);
    }
    else
    {
      LEDStatus = false;
      digitalWrite(LED, LOW);
    }
  }




with



int statusSensor = digitalRead (soundSensor);
  if (statusSensor == 1)
  {
    digitalWrite(LED, HIGH);
  }
  else
  {
    digitalWrite(LED, LOW);
  }




You say that the first code works and the second doesn't but the code is different so perhaps that is not surprising.

I have tried with both , these are 2 different codes , both work in a split program and when i put it with LCD and movement sensor , it doesnt work