i am working on home automation system project for my final year diploma..
Well, my system consists of PIR sensor to detect motion and turn on the LED, Gas detector to detect gas and turn on the buzzer and bluetooth module with relay to control on/off of the home appliances ..
well the problem is that when i excute the program the bluetooth module and relay part stops working even when the program is correct.. have a look at the program n pls send the corrected one if any mistakes are present
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char val; // variable to receive data from the serial port
int val1;
int ledpin = 7; // LED connected to pin 2 (on-board LED)
int sensorValue = 0; // value read from the sensor
int tempPin = A1; // Declaring the Analog input to be 0 (A0) of Arduino board.
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int ledPin = 13; // LED connected to digital pin 13
int ledPin1 = 10; // choose the pin for the LED
int inputPin = 9; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val2 = 0; // variable for reading the pin status
void setup() {
{
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin = 9, INPUT); // declare sensor as input
pinMode(ledpin = 7, OUTPUT); // pin 2 (on-board LED) as OUTPUT
pinMode(ledpin = 8, OUTPUT); // pin 3 (on-board LED) as OUTPUT
pinMode(ledpin = 13, OUTPUT);
pinMode(ledpin = A1, INPUT);
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.setCursor(0, 0); // set LCD cursor position (column, row)
lcd.print("Hello Abhyuday"); // print text to LCD
lcd.setCursor(0, 1);
delay(2000); // wait 2000ms
lcd.clear(); // clear LCD display}
Serial.begin(9600); // start serial communication at 115200bps
}
}
void loop() {
{
val2 = digitalRead(inputPin); // read input value
if (val2 == HIGH) { // check if the input is HIGH
digitalWrite(ledPin1, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
lcd.println("Motion detected!");
delay (1000);
lcd.clear();
// We only want to print on the output change, not state
pirState = HIGH;
}
}
else {
digitalWrite(ledPin1, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
lcd.println("Motion ended! ");
delay (1000);
lcd.clear();
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
/*
{
val = analogRead(tempPin);
float mv = ( val / 1024.0) * 5000;
float cel = mv / 10;
float farh = (cel * 9) / 5 + 32;
lcd.print("Temp= ");
lcd.print(cel);
lcd.print("C");
delay(1000);
lcd.clear();
}
*/
{
sensorValue = analogRead(analogInPin);
// determine alarm status
if (sensorValue >= 200)
{
digitalWrite(ledPin, HIGH); // sets the LED on
lcd.print("Gas Detected");
}
else
{
digitalWrite(ledPin, LOW); // sets the LED off
lcd.print("Gas Not Detected");
}
// print the results to the serial monitor:
//Serial.println(sensorValue);
delay(1000);
lcd.clear();
// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(10);
}
{
if ( Serial.available() ) // if data is available to read
{
;
}
val = Serial.read(); // read it and store it in 'val'
if ( val == 'a' ) // if 'a' was received led 2 is switched off
{
digitalWrite(ledpin = 7, HIGH); // turn Off pin 2
}
if ( val == 'A' ) // if 'A' was received led 2 on
{
digitalWrite(ledpin = 7, LOW); // turn ON pin 2
}
if ( val == 'b' ) // if 'b' was received led 3 is switched off
{
digitalWrite(ledpin = 8, HIGH); // turn Off pin 3
}
if ( val == 'B' ) // if 'B' was received led 3 on
{
digitalWrite(ledpin = 8, LOW); // turn ON pin 3
}
}
}
/*
/* uncomment this to get temperature in farenhite
lcd.print("TEMPRATURE = ");
lcd.print(farh);
lcd.print("*F");
lcd.println();
/*
// }
{
//}
}
*/