12v PIR Motion Sensor coding

Evening all,

Wondering if you can give me some guidance...

I'm fairly new to the Arduino world and I'm looking to make a mini alarm system. I'm trying to run a 12v PIR sensor, that when activated illuminates an LED and sounds a buzzer. I'm ok with the circuit building side of things, its the coding that I can't seem to get my head around.

Has anyone got something similar that I could adapt to work this?

Thanks in Advance

Mark

Post a schematic of the wiring.

Post a data sheet for the PIR sensor.

What buzzer? Is it an active buzzer (requires a waveform) or passive (requires only a voltage)?

What Arduino are you using?

Hope the quick sketch makes sense.

It's a passive buzzer and a MEGA 2560 being used.

Below is from the data sheet

Partcode KX15DD
Lens Characteristics
Dual Technology (DT) ✓
PIR ✓
Volumetric lens 85 degree coverage, 60 zones and 7 planes ✓
Pet immunity coverage, 6 planes and 56 zones O
Curtain lens, 20 degree coverage, 46 zone, 6 planes O
Long range lens, 20 degree coverage, 24 zone, 6 planes O
Maximum range 15m
Optimum installation height 1.8-2.4m
Creep-zone protection ✓
Technical Characteristics
Animal Immunity O
Blue Wave Technology ✓
Automatic sensitivity ✓
Digital temperature compensation ✓
Optical quad ✓
EOL resistors on board ✓
Tamper protection included ✓

Electrical & battery
Operating voltage
9-16V DC 13.8V DC typical
Quiescent current consumption
13mA @ 12V (Min), 16mA @ 12V (Max)
Contact Resistance
<10 ohms
Relay outputs
50mA 60 VDC, 42 VAC (RMS)
Tamper switch
12V 50mA

If it has a relay why do you need the Arduino. Can't the LED and passive buzzer be controlled by the relay. Can you post a manual or data sheet that shows the relay pinout?

Yes the relay within would suffice, however I want to use the Arduino. As at some point I intend to make the system bigger. This is a starting point for me and understanding the coding required to make this work would really help.

Hi Mark,

you are welcome to this forum. Really! You can ask as many questions about programming and about electronics as you like. As long as you show some own effort in learning you will receive answers to your questions.

This is a very generalised comment. Asking in a hidden way "can somebody post the code that will make my LED switch on and the buzzer buzz?"

There are thousands of similarities to your coding-problem
on one signal-input switch on/off two outputs. Take any code that uses a single input
and switches an output. And you can start to adapt this code.

I guess this short explanation does not help at all.
There is no way around learning some basic things about arduino-programming.

  • what does function setup do?
  • what does function loop do?
  • how do I configure an IO-pin as output?
  • what is a pullup-resistor

How can I make code-execution conditional?
How can I detect a state-change?

Without this basic knowledge you depend 101% on other users to again and again and again modify the code to your needs.

One way to learn these basic things is
Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

In your schematic you connected the LED and the buzzer directly to arduino-IO-pins

From your schematic I assume that you knowledge about the circuitside is too less.
An LED needs a current-limiting resistor which you haven't drawn in your schematic.
Your buzzer will draw more than 40mA which will burn through the Arduino Megas IO-pin

Connecting a 12V signal through a 1kOhm-resistor to "adapt" to the 5V-level of the Ardiuno-Mega is unprofessional. This should be done through an optocoupler (again with a matching current-limiting resistor or with a voltage-divider with matching values.

You are really welcome to ask many questions how to optimise your project just the way you did it: Posting a schematic and asking for feedback what other (more experienced people) say to your design.

best regards Stefan

I looked into the technical specs

Well this is a pretty high current for "quiscent" -mode
If your device is battery-powered and you want to change the battery once per month you would need a battery with a capacity of
30 days * 24 hour/day * 0.016A * 1.2 = 13.84 Ah

Of course other PIR-sensors have a different detection-area and a different sensivity.
There are other 12V-PIR-sensor to buy that have a quiscent-current that is 300 times smaller
Your PIR 15 mA

this device 0,050 mA

Which means a battery with 1Ah lasts more than two years.
best regards Stefan

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