I'm planning to create project that will control the relay connected to the Arduino Uno using LDR(Light dependent Resistor) and the bluetooth module.
My plan is to turn off the LED when the LDR detect light and turn On the LED when there is no light detected. Also control it via bluetooth app that send "1" for LED ON and "0" for LED OFF.
My problem is when I use the Application the LDR is not working. I can only use the app for control of relay. Here is my CODE
I already search from another forum about overing LDR with Bluetoot
Here's the link
int lamp1=2;
int sensorPin = A0;
int sensorValue = 0;
int Received=0;
int lamp1_state=0;
int LDR_limit=1000;
void setup(){
pinMode(lamp1,OUTPUT);
Serial.begin(9600);
}
void loop(){
if(Serial.available()>0)
{
Received = Serial.read();
}
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
if(sensorValue <= 400)
{
digitalWrite(lamp1,HIGH);
lamp1_state=1;
Received=1;
}
if(sensorValue >= 800)
{
digitalWrite(lamp1,LOW);
lamp1_state=0;
Received=0;
if ( sensorValue <= 400 && Received == '1')
{
digitalWrite(lamp1,HIGH);
lamp1_state=1;
Received=1;
}
if ( sensorValue <= 400 && Received == '0')
{
digitalWrite(lamp1,LOW);
lamp1_state=1;
Received=0;
}
if ( sensorValue >= 800 && Received == '1')
{
digitalWrite(lamp1,HIGH);
lamp1_state=1;
Received=1;
}
if ( sensorValue >= 800 && Received == '0')
{
digitalWrite(lamp1,LOW);
lamp1_state=1;
Received=0;
}
delay(300);
}
The plan is to let LDR Control the relay when day and night and also control it via bluetooth any time.
Thanks for your Help