I have arduino project - House automation
When I put this code only on arduino, sound sensor works:
int soundSensor=A1;
int LED=5;
boolean LEDStatus=false;
void setup() {
Serial.begin(9600);
pinMode(soundSensor,INPUT);
pinMode(LED,OUTPUT);
}
void loop() {
int SensorData=analogRead(soundSensor);
if(SensorData>600){
if(LEDStatus==false){
LEDStatus=true;
digitalWrite(LED,HIGH);
}
else{
LEDStatus=false;
digitalWrite(LED,LOW);
}
delay(50);
}
}
When I upload same code in big project, even when I upload little part of project on arduino, sound sensor doesnt work.. whats happening?
Thanks
Whole code:
#include <Servo.h>
#include "DHT.h"
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#define SERVO_PIN 8
#define SS_PIN 10
#define RST_PIN 9
#define lightingOutput A2
#define ldrPin A0
#define PIR 7
#define ledGrn 6
#define heatingOutput A3
#define coolingOutput A4
#define DHTPIN 2
#define DHTTYPE DHT11
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create instance of our reader
Servo myservo; // Create instance of our motor /// create servo object to control a servo
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
int pos;
int light;
float h, t;
int soundSensor=A1;
int LED=5;
boolean LEDStatus=false;
const int buzzer = 4;
long zadnje_ocitanje=0;
void setup()
{
Serial.begin(9600);
dht.begin();
SPI.begin();
mfrc522.PCD_Init();
myservo.attach(SERVO_PIN);
myservo.write(0);
pinMode(heatingOutput, OUTPUT);
pinMode(coolingOutput, OUTPUT);
pinMode(ledGrn, OUTPUT);
pinMode(soundSensor,INPUT);
pinMode(LED,OUTPUT);
pinMode(lightingOutput, OUTPUT);
zadnje_ocitanje=millis();
}
void loop() {
Serial.println("\nHOME AUTOMATION\n");
readSOUND();
readRFID();
readDHT();
readLIGHT();
delay(1000);
}
////////////////////////////////////////////
void readRFID()
{
//Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent() ) {
return;
}
if ( ! mfrc522.PICC_ReadCardSerial() ) {
return;
}
// If a card is detected, execute the following:
Serial.println("Time to open");
// Print the card's ID
String content = "";
byte letter;
for ( byte i = 0; i < mfrc522.uid.size; i++ ) {
content.concat(String(mfrc522.uid.uidByte[i], HEX));
if ( i < mfrc522.uid.size - 1 ) content += "-";
}
content.toUpperCase();
Serial.println();
Serial.println("UID tag :’" + content + "‘");
if (content == "C0-E5-86-25") {
Serial.println("Authorized access");
digitalWrite(ledGrn, HIGH);
for (pos = 0; pos <= 90; pos += 1) {
myservo.write(pos);
delay(25);
}
for (pos = 90; pos >= 0; pos -= 1) {
myservo.write(pos);
delay(70);
digitalWrite(ledGrn, LOW);
}
}
else {
Serial.println("Access Denied");
tone(buzzer, 1000, 6000);
}
}
//////////////////////////////////////////////////////
void readDHT()
{
h = dht.readHumidity();
t = dht.readTemperature();
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.println();
if (t < 18) //if temperature is less than 18 celcius
{
digitalWrite(heatingOutput, HIGH);
Serial.print("Heating activated\n");
}
else
{
digitalWrite(heatingOutput, LOW);
}
if (t > 22) //if temperature is more than 22 celcius
{
digitalWrite(coolingOutput, HIGH);
Serial.print("Cooling activated\n");
}
else
{
digitalWrite(coolingOutput, LOW);
}
}
//////////////////////////////////////////////////////
void readLIGHT()
{
int value_pir = digitalRead(PIR);
light = map(analogRead(ldrPin) , 0 , 1024 , 1 , 100);
Serial.print("Lighting percentage: ");
Serial.print(light);
Serial.print("\nMotion detector: ");
Serial.print(digitalRead(PIR));
if ((millis()-zadnje_ocitanje)>6000)
{
if ((light < 50) && ( value_pir == HIGH) )
{
digitalWrite(lightingOutput, HIGH);
Serial.println("\nLighting ON");
}
else
{
digitalWrite(lightingOutput, LOW);
Serial.println("\nLighting OFF");
}
zadnje_ocitanje=millis();
}
}
//////////////////////////////////////////////////////////////
void readSOUND()
{
int SensorData=analogRead(soundSensor);
if(SensorData>600){
if(LEDStatus==false){
LEDStatus=true;
digitalWrite(LED,HIGH);
}
else{
LEDStatus=false;
digitalWrite(LED,LOW);
}
delay(50);
}
}
*Edited thanks to septillion