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():
}