0

PIR sensor alarm
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

PIR sensor alarm

by lloydc on Sun Jan 20, 2019 12:15 am

[code][/code]I am now in day 4 of my Arduino/PIR alarm project. I am new to Arduino, so I am assuming that I have made an error somewhere along the way. I am using a Metro Board and PIR sensor (both of which I purchased from Adafruit). The code I'm using is based on the PIR code from your webpage PIR Sensor test; modified to run the alarm project. So I may have made an error. I did verify the code and was successful, so I'm wondering if the code is actually correct. I also successfully uploaded the code to the board.
When I apply power to the board (a 9 VDC wall supply also purchased from Adafruit) The buzzer and LED immediately turn "ON" and stay on. The Pir sensor is wired correctly ( I think) so it should not do so. I have gone over the schematic and the code, checking and rechecking, trying to make sure all is correct.
I have also used two other Genuine Arduino boards to test the project. They all get the same results. All three boards show up correctly under the Device manager.
I am attaching a copy of the code and the schematic I am using. The PIR has the jumper in the "H" configuration and both pots are set to 50%. Any assistance would be greatly appreciated!! .Thanks

Note: What format does the code(document) need to be in to be accepted?
Here is my code:
int ledPin =13 ; //chooses the pin for the LED
int input = 8; // chooses the input pin for the PIR sensor trigger
int buzzerPin = 12 ; // chooses the output pin for the buzzer,(positive wire from buzzer
int pirState = Low; //start with, assuming no motion detected
int Val = 0; // variable for reading the pin state

void setup () {
pinMode (ledPin, OUTPUT); //declares LED as output
pinMode (inputPin, INPUT); //declares sensor as input. (trigger wire)
pinMode (buzzerPin, OUTPUT); // declares buzzerPin as an output (positive wire)
Serial.begin(9600);
}

void loop () {
val = digitalRead(inputPin); // reads input value
if (val = HIGH); //checks if the input is HIGH
digitalWrite (ledPin, HIGH); //turns led ON
digitalWrite(buzzerPin, HIGH); // turns the buzzer ON
}
}

// buzzer should remain ON until power is removed from the board
Attachments
IMG_20190119_0001 (800x516).jpg
IMG_20190119_0001 (800x516).jpg (260.61 KiB) Viewed 210 times

lloydc
 
Posts: 21
Joined: Sat Oct 29, 2011 1:47 pm

Re: PIR sensor alarm

by adafruit_support_mike on Sun Jan 20, 2019 1:01 am

You have a typo in this line:

Code: Select all | TOGGLE FULL SIZE
if (val = HIGH); //checks if the input is HIGH
The single '=' sets the value of variable 'val' to HIGH, no matter what value it had before.

To test equality between two values, you need the double-equal: '==':

Code: Select all | TOGGLE FULL SIZE
if ( HIGH == val ); //checks if the input is HIGH
You'll notice that I also swapped the order of the values to put 'HIGH' first. That's a programming trick to help avoid that very mistake (which everyone makes once in a while).

'HIGH' is a constant, so the compiler won't allow you to assign values to it. If you make the same typo with the values in that order:

Code: Select all | TOGGLE FULL SIZE
if ( HIGH = val ); //checks if the input is HIGH
The compiler will throw an error saying you can't do that.

adafruit_support_mike
 
Posts: 58480
Joined: Thu Feb 11, 2010 2:51 pm

Re: PIR sensor alarm

by lloydc on Tue Jan 22, 2019 4:47 pm

I made the correction per the note above. When I apply power to the metro the buzzer immediately comes on, and the PIR does not react. What am I missing?

wiring connections are per the circuit above, i.e.,
PIR VCC is connected at =5 volts
PIR ground is connected to ground
PIR signal pin is connected to pin 8
Buzzer positive is connected to pin 12
Buzzer ground is connected to ground
Sketch is as above.

Respectfully; why doesn't this work?

lloydc
 
Posts: 21
Joined: Sat Oct 29, 2011 1:47 pm

Re: PIR sensor alarm

by lloydc on Tue Jan 22, 2019 8:11 pm

I tried a different project. the sketch both successful verified and uploaded. and it did not function either.
the code is here:
https://create.arduino.cc/editor/robotz ... 9e833c002d

Connections HC-SR04
vcc = 5 volts
trig = pin 13
echo = pin 12
ground to ground
buzzer = pin 10
buzzer ground to ground
double checked com & port: is correct
I'm completely at a loss! help please.

lloydc
 
Posts: 21
Joined: Sat Oct 29, 2011 1:47 pm

Re: PIR sensor alarm

by adafruit_support_mike on Wed Jan 23, 2019 1:02 am

Let's take it back to the phyical level: measure the PIR sensor's output voltage when it's sitting idle, then try to trigger it and see if the output voltage changes.

adafruit_support_mike
 
Posts: 58480
Joined: Thu Feb 11, 2010 2:51 pm

Re: PIR sensor alarm

by lloydc on Wed Jan 23, 2019 5:30 pm

Hello Mike,
I checked the voltage at the sensor pin , as you suggested, Idle, it was 1.6 volts dc. When I tried to activate the sensor, I got no voltage reading. so....................I found the PIR sensor tester code, by Limor Fried, and copied and pasted it into the Arduino online IDE.
copy of this code can be found at:
http://create.arduino.cc/editor/robotz1 ... b240816826
as well as on the "Using a PIR" page on your "learn" webpage. This code was written by Limor Fried. Has it been reviewed and found to be correct and updated?
My Arduino Uno R3 board was found under "device Manger". ( confirmed it as well as the com port.)
I then compiled and verified the code successfully.
I then uploaded the code to my board.....successfully.
I next made sure all the connections were correct and tried running the sketch.
Result: led came on immediately after power was applied to the board. The buzzer and led was then turning off and on without energizing the PIR. Bottom line..............this did not work! Could it be that I received a faulty PIR from Adafruit???????? Can you verify Limor's code as being correct? I would like for you to test the sketch and layout to determine if it works for you; and give me the results?
I thank you and Adafruit for your time and consideration and look forward to your reply.
Should I perhaps return the PIR sensor to Adafruit and get a replacement?
lloydc

lloydc
 
Posts: 21
Joined: Sat Oct 29, 2011 1:47 pm

Re: PIR sensor alarm

by adafruit_support_mike on Thu Jan 24, 2019 12:32 am

The code is correct, and there's a small statistical chance that any electronic device will fail within the first few minutes of use. It's called 'early component failure', and our return/replace policy exists to deal with those issues.

There are other things that can go wrong though. Post a photo showing your actual hardware and connections and we'll see what those have to say. 800x600 images usually work best.

adafruit_support_mike
 
Posts: 58480
Joined: Thu Feb 11, 2010 2:51 pm

Re: PIR sensor alarm

by lloydc on Thu Jan 24, 2019 1:29 pm

Hello once again Mike.
OK. I started all over again today. I compiled and verified the sketch, again, with success. I reset the Metro (Silicone Labs CP210x USB to UART Bridge on Com 6) and uploaded the sketch , again! When I attempted to upload the sketch I got the following messages in the monitor:
Avidude STK500_rec ( ): Programmer is not responding.
Not in sync resp = 0xbc
Attachments
Set up Metro 1.jpg
Set up Metro 1.jpg (311.14 KiB) Viewed 133 times
set up Metro 2.jpg
set up Metro 2.jpg (305.88 KiB) Viewed 133 times

lloydc
 
Posts: 21
Joined: Sat Oct 29, 2011 1:47 pm

Re: PIR sensor alarm

by lloydc on Thu Jan 24, 2019 1:35 pm

I tried the same thing on my Uno.............. when I applied power the buzzer beeped intermittently............
Attachments
Set up Uno 1.jpg
Set up Uno 1.jpg (271.12 KiB) Viewed 132 times

lloydc
 
Posts: 21
Joined: Sat Oct 29, 2011 1:47 pm

Re: PIR sensor alarm

by kcl1s on Thu Jan 24, 2019 1:43 pm

The Metro photos appear to show the brown wire going to AREF. Should that be going to gnd?

Fellow hobbyist
Keith

kcl1s
 
Posts: 1229
Joined: Tue Aug 30, 2016 12:06 pm

Re: PIR sensor alarm

by adafruit_support_mike on Fri Jan 25, 2019 2:11 am

I also need to see the connections to the PIR sensor please.

adafruit_support_mike
 
Posts: 58480
Joined: Thu Feb 11, 2010 2:51 pm

Re: PIR sensor alarm

by lloydc on Fri Jan 25, 2019 2:05 pm

Here you go.......
Attachments
PIR #1.jpg
PIR #1.jpg (283.21 KiB) Viewed 105 times

lloydc
 
Posts: 21
Joined: Sat Oct 29, 2011 1:47 pm

Re: PIR sensor alarm

by adafruit_support_mike on Sat Jan 26, 2019 2:21 am

Thank you. All the connections look good, and I don't see anything visibly wrong with the components on the PCB.

That doesn't prove much though.. dead components usually look just like working ones.

Do you have a multimeter? Readings from a microcontroller are always iffy because there are so many layers between the actual signal and the output. Meter readings are more direct and reliable.

adafruit_support_mike
 
Posts: 58480
Joined: Thu Feb 11, 2010 2:51 pm

Re: PIR sensor alarm

by lloydc on Mon Jan 28, 2019 8:01 pm

Greetings Mike,
I am now on day 12 of the "great PIR sensor code odyssey." Progress update:
I'm no further ahead then I was on Day one ! I have purchased 4 additional PIR sensor, hoping at least one of them would be good. I have laboriously copied the code (line by line) that Limor Fried wrote; and that you stated was correct, without sucess. as soon as I apply power to the board the led comes on and stays on; as before.
After what seems like endless hours of searching , I found 4 other source codes; all of which would not compile and verify. So, no resolution there.
I also purchased another genuine Arduino Uno ( I now have 4 boards) that I wanted to test with a tilt switch. No luck there either as I can't find a correct source code for the tilt switch either. I have tried four different codes. I have attached a code that should be right and attached a copy of that code......https://create.arduino.cc/editor/robotz ... 3bc6e031cb. Please check it for content....appreciated.
If I may Mike?
I am a 71 year old, combat wounded( disabled) Vietnam vet. I wanted to try using Arduino to make myself an audible door alarm system; as my next door neighbor had a violent break-in; and I wanted some type of protection or at least warning. All of the online material I read, spoke of how easy and simple Arduino is. I have discovered that to be an erroneous concept!
Could you possibly help an old vet out and supply me with a correct and working PIR code so that I have a base to work from??
I am on a limited income ,else I would purchase a commercial security system, but that is not an option for me.
I could really use some definitive help.
Thank you for your time and consideration.
LloydC

lloydc
 
Posts: 21
Joined: Sat Oct 29, 2011 1:47 pm

Re: PIR sensor alarm

by kcl1s on Tue Jan 29, 2019 12:37 am

Lloyd,
I teach Arduino to teens and adults. I can see you are struggling to get things working. I have been following this thread but was letting Mike from Adafruit help you along. I find that when first starting out it is best to try for small successes. You have a lot going on. You have posted code for a PIR sensor, a tilt switch and a HC-SR04 distance sensor and say none are working as expected. Lets stick with the PIR sensor for now.

When troubleshooting a problem you have to go back to the basics and get that first success. We can do that with the Metro or Uno by loading the basic Blink sketch that will bilink the on board LED. This requires just the board and no wiring. You can find the sketch by clicking Examples, then Basics, then Blink from the left hand menu of the online editor. When you get that uploaded and working we know that the board will load code and operate properly. We have our first success. Change both of the delay values in the code from 1000 to 100 and upload again. You should see a faster blink. Another success. We can now move on to the sensor.

You mention code by Limor Fried aka Lady Ada. As she owns Adafruit you can be sure that any tutorial code of hers has been thoroughly tested. She also wrote the tutorial for the PIR sensor https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/overview On this page of the guide https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/testing-a-pir she shows how to test the PIR without using any code. I would wire this up but use the Arduino board for 5v power and ground instead of batteries. As noted on this page there is a 30 - 60 second stabilizing period after applying power before the sensor works as expected. After getting this working read about the retriggering jumper and the sensitivity adjustments. This step will show that the PIR sensor is working.

Hopefully you have had success with the 2 steps above but if you did not post and describe what you are not seeing.

If all is well so far you can wire the sensor and load the code described on this page of the tutorial https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/using-a-pir-w-arduino It does not have the buzzer code yet and just lights the on board LED but we can add the buzzer easily once this code is working.

Let us know how it goes

Fellow hobbyist
Keith
Last edited by kcl1s on Tue Jan 29, 2019 12:52 am, edited 3 times in total.

kcl1s
 
Posts: 1229
Joined: Tue Aug 30, 2016 12:06 pm

Please be positive and constructive with your questions and comments.