I have the schematics and code to make automatic lights using a relay and PIR sensor , but it can not work.. please help.. i am newbie
it is skema .. and code not work
// Arduino light control system with PIR
// www.openhwdesign.comintPir = 2; // connect the Pir to pin 2
int Relay = 2; // connect the relay to pin 3
int Presence // a variable to store presence
void setup()
{
pinMode(Pir, INPUT); // set the pir sensor as an input
pinMode(Relay, OUTPUT); // set the relay as output
}
void loop()
{
Presence = digitalRead (Pir);
if (Presence == HIGH) // check if there is a presence
{
digitalWrite(Relay, HIGH); // turn on the relay
}
else
{
digitalWrite(Relay, LOW); // turn off the relay
}
delay (10); // a delay for stability
}

Hi.
Newbie too.
I see several errors in your code.
Third line: int Pir = 2; Space between int and Pir, and it has to start on a new line, otherwise it's part of the comment.
Fourth line: int Relay = 3; (2 = the Pir)
Fifth line: int Presence; needs a semicolon.
If you have the same Pir sensor as in the picture, set the sensitivity pot in the middle, and the 'time' pot fully anti-clockwise. Start turning the time (light 'on' time) up slowly if it all works. Fully clockwise would be 7 minutes.
Leo..
it is no error code , but its light will not turn on when there is motion in PIR Sensor ![]()
Did you change those three lines?
Your picture shows the relay connected to pin 3.
But in the code you state that it is connected to pin 2
This http://www.openhwdesign.com code should work if you did copy and paste it:
// Arduino light control system with PIR
// www.openhwdesign.com
int Pir = 2; // connect the Pir to pin 2
int Relay = 3; // connect the relay to pin 3
int Presence; // a variable to store presence
void setup()
{
pinMode(Pir, INPUT); // set the pir sensor as an input
pinMode(Relay, OUTPUT); // set the relay as output
}
void loop()
{
Presence = digitalRead (Pir);
if (Presence == HIGH) // check if there is a presence
{
digitalWrite(Relay, HIGH); // turn on the relay
}
else
{
digitalWrite(Relay, LOW); // turn off the relay
}
delay (10); // a delay for stability
}
If it still doesn't work, remove the relay and lightbulb, and change the line with:
int Relay = 3; // connect the relay to pin 3
to
int Relay = 13; // connect the relay to pin 13
Arduino has an onboard LED connected to pin 13
You can now see if the PIR sensor works by looking at the LED near pin 13
A lot safer experimenting with just low voltage before you hook it up to the mains.
Leo..