Hey There,
I am working on Automatic Room Light Controller with Bidirectional Visitor Counter project.
This is my first arduino project and I am beginner.
Most of the section working fine I used pair of IR sensor module to detect entry and exit of the person.
Whenever number of person enters and exits the room, count is displayed on LCD. I used Relay module If any person is present in the room then the load such as fan, light will be ON otherwise it will remain OFF.
But the problem I am facing is that, Initially relay is off but When any person enters in the room Relay becomes ON (i.e. green light on the Relay module glowing) but Load which is basic DC motor is not getting ON. I have used 9V battery to power DC motor using relay NO pin of relay is connected to +ve terminal of motor, COM is connected to +ve terminal of battery, -ve of battery connected to -ve of motor.
I tested relay with another simple program only for testing relay for specific time i.e. ON & OFF. It working fine.
#include <LiquidCrystal.h>
#define in 8
#define out 9
#define relay 7
int count=0;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// put your setup code here, to run once:
lcd.begin(16,2);
lcd.print("Visitor Counter");
delay(2000);
pinMode(in, INPUT);
pinMode(out, INPUT);
lcd.clear();
lcd.print("Person In Room");
lcd.setCursor(0,1);
}
void loop() {
if(digitalRead(in))
IN();
if(digitalRead(out))
OUT();
if(count<=0)
{
lcd.clear();
digitalWrite(relay, LOW);
lcd.print("Nobody in Room");
lcd.setCursor(0,1);
lcd.print("Fan is OFF");
}
else
digitalWrite(relay, HIGH);//inverting the operation
delay(5000);
}
// put your main code here, to run repeatedly:
void IN()
{
count++;
lcd.clear();
lcd.print("Person In Room");
lcd.setCursor(0,1);
lcd.print(count);
delay(3000);
}
void OUT()
{
count--;
lcd.clear();
lcd.print("Person in room");
lcd.setCursor(0,1);
lcd.print(count);
delay(3000);
}
Unless your 9 Volt battery is a really big one, the kind you buy in a grocery store does not have the current capacity to drive a relay and a motor. You probably need a much more robust power source such as a wall wart that is able to deliver the current required by your motor and relay - and whatever else you want to run.
This forum, and others, are full of posts from people that think a small, 9 volt battery can power massive loads. They are good for occasionally blinking an led, but not much more.
Due_unto:
Unless your 9 Volt battery is a really big one, the kind you buy in a grocery store does not have the current capacity to drive a relay and a motor. You probably need a much more robust power source such as a wall wart that is able to deliver the current required by your motor and relay - and whatever else you want to run.
This forum, and others, are full of posts from people that think a small, 9 volt battery can power massive loads. They are good for occasionally blinking an led, but not much more.
But When I tested relay and motor on 9V battery It working well also I connected a LED as load instead of motor It also not glowing.
Do I need to modify the code?
Try editing your post by selecting your code, then press this button then click "Save" so it shows correctly.
You have too many delays in your code ... check out some of the examples like BlinkWithoutDelay, Debounce and others that use the millis() or micros() function to create a delayed time interval.
From the Duracell datasheet for their 9 Volt Coppertop battery charts: A new, fresh battery shows 0 output after about 45 minutes when drawing a constant 250 milli-Amps. Your controller circuits will fail well before that.
Just because it "worked" when you "tested" the circuit is no guarantee that it will continue to do so for hours on end.
What relay are you using? Do you have 5V connected to Vcc? What about the JD-Vcc jumper? Does your board have one, and if so, is it in?
What I'm thinking is you don't have the 5v to energize the relay coil, so it won't switch (or click). The green light indicates the control side is working.