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);
}