PIR sensor to Arduino

Thread Starter


Joined Feb 26, 2011
Hello AAC Forum,

Working on a circuit to control an LED display which
uses a PIR sensor to an Arduino microcontroller.
Code copied below.

For some reason I don't understand LED2, which indicates an out put from the Arduino, was not coming on. LED1, which indicates a signal from the motion detector was coming on. So I decided to switch out the LEDs in case one bad.
When LED1 was removed LED2 came on. So when LED1 is inserted LED2 goes off and when LED1 is inserted LED2 goes off. Its like the ground of LED2 is keeping LED2 from being grounded or something.

How can I get both indicators to work?


Allen Pitts, Dallas Texas

+++++++++begin Arduino sketch++++++++++++++
* PIR sensor to Arduino
Allen Pitts pittsallen@usa.net 160407 */

int ledPin1 = 10; // choose the pin for the LED
int inputPin = 5; // choose the input pin (for PIR sensor)
int pirState = LOW; // start, assuming no motion detected
int val = 0; // variable for reading the pin status

void setup() {

pinMode(ledPin1, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input


void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin1, HIGH); // turn LED ON

if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
} else {
digitalWrite(ledPin1, LOW); // turn LED OFF
// digitalWrite(ledPin2, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
+++++++++End Arduino sketch++++++++++++++


Joined Apr 2, 2016

Sorry for jumping in off topic. I am hoping to redirect you to a problem I am having with a PIR to Relay circuit. I am looking for your input because I have seen some threads where you have attempted something similar, hopefully with final success. If you have the time please review my thread at http://forum.allaboutcircuits.com/t...ion-sensor-to-trigger-3v-relay-module.122711/ Your input would be most valuable.

I am trying to go no microcontroller as I see you have migrated towards. Trying to learn this stuff at the base form before throwing in the microcontroller variable.




Joined Sep 4, 2010
Off the top of my head I cant remember that the input voltage threshold of an Arduino pin is but it is probably more than the forward voltage or your LED

In your circuit, when the PIR is on LED1 will light because it is fed via the resistor which limits its current. This will clamp the input pin at the forward voltage of the LED which probably isn't enough to turn on the input and your code will therfore not turn on the output.
However if LED1 is removed the voltage on pin5 will go up, probably almost to the VCC rail because the current on the input is vary small, and this will of course turn on LED2.

The solution is to leave the resistor in series with the led but connect pin5 directly to the output of the PIR, along with the resistor.
On your drawing everything stays 'as is' apart from the fact that the green wire to pin5 needs to connect to the green wire from the PIR

Assuming that the PIR can supply the current required for the LED all will be well and you will have circa 5V on PIN5

Hope this helps


Thread Starter


Joined Feb 26, 2011
Hello Dyslexibloke,

You are correct sir. The drop in voltage was keeping the input from the PIR from being read as HIGH at pin 5. Connecting the output to pin 5 between the PIR output and the resistor to LED 1 fixed it. Revised pictorial attached below.


Allen in Dallas