PIR to Arduino Uno

Hello Arduino Forum,

Using Uno to turn on seven LEDs using eight motion detectors (PIR [passive infrared]).

Working to get one PIR to turn on one LED.

Sketch copied herewith below.

This is a schematic of the circuit.

It works as designed using a bread board for the components and
a USB connector to the Uno. That is,
when the PIR goes high and sends 2.29v signal to Pin A0, there
is a 1.76v signal at Pin2. (The output from Pin2 will be used to
turn on a transistor which will send 12v to LED.)

The system is designed to work on a single 12 volt power source.
So a barrel jack plug pig tail was run from the power source
on the bread board to barrel jack on the Uno.

When the Uno was plugged into the 12 volts the reading at
Pin 2 goes to .42v and does not change whether the PIR is
low or high. And the LED comes on and does not go off.

Why does the power source to the Uno make the system work so

Allen Pitts, Dallas TX

+++++++++ sketch PIR to Arduino ++++++++++++++++++++++++++++
int led = A0; // the pin that the sensor is attached to
int sensor = 2; // the pin that the sensor is attached to

void setup() {
pinMode(led, OUTPUT);
pinMode(sensor, INPUT);

void loop() {
int sensorval = digitalRead(sensor);

if (sensorval == LOW) {
digitalWrite(led, HIGH);
digitalWrite(led, LOW);

That circuit is seriously flawed. D1 clamps the input voltage on pin 2. You can expect marginal performance - intermittent failures due to noise and temperature changes, and different behaviour with different LEDs attached.

Thanks for the documentation. Next time, use the autoformat in the IDE before copying. It adds beauty and clarity to the presentation of the code. Often misplaced curly brackets are quickly spotted.

You use Vcc in the schematics. I hope it is Vin, or the barrel jack.
Did You use the USB plug when You tested feeding 12 volt to the UNO? I have a fear that Vin, barrel jack should be disconnected before USB brings 5 volt to the board.
The 0.42 volt reading indicates something bad. Let's find out why.

And please use code tags, the symbol is </>, before pasting.

If You would use an analog input maybe You can read something from the sensor. The if statement needs to be changed into comparing the reading against a threshold.
In the code You use a digital input and it will read 0.42 volt as LOW.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.