Thursday, January 13, 2011

Motion Sensor on Arduino

I already showed you the example of connecting a radar sensor to the Arduino. While radar sensors are very good at detecting frontal motion, they have their weaknesses when it comes to detecting motion in a wider angle. They are triggered by any object which reflects their radar waves.
For bypassing motion you normally use a passive infrared motion sensor (PIR). They aren't that great when it comes to detecting frontal motion, but they are sensitive to motion in a wider angle. They are called passive infrared motion sensors, because they detect infrared radiation which is emitted by every living person. The hotter your body temperature, the more you emit.

I used the ePIR sensor board from Zilog. You can configure the sensors sensitivity, you can set it to sleep to preserve energy and you can couple it with a light sensor so it won't be triggered at day time. For details on how to configure it, have a look into the datasheet. I used a simple default connection and didn't want to configure anything.

Here is a default setup:

The source code is also pretty simple:
int sleepModePin = 4;
int motionDetectPin = 2;
int alarmLED = 12;
int val;

void setup() {
  //the sleep pin has to be active high to enable detection
  digitalWrite(sleepModePin, HIGH);

void loop() {
  val = digitalRead(motionDetectPin);
  //the ePIR sensor is active low so if motion is detected the output is low
  if(val == LOW) {
    digitalWrite(alarmLED, HIGH);
  } else {
    digitalWrite(alarmLED, LOW);
Motion sensor in action:


  1. Hi Mario. Can you help me a little with this setup? It works great but the only problem is that the LED lights up poorly. You can barely see that is on. What do you think might cause the problem? Thank you.

    1. You might be using a larger LED than usual which needs more voltage, or maybe you used a resistor with higher resistance by accident? I didn't have a 470 ohm around so I used two 330's in series for 660 ohm and mine still light up properly. I just finished reading a good primer on LEDs, try this:

  2. This is really interesting blog on Motion Sensor in Chennai, You are a very skilled blogger. I've joined your rss feed and look forward to seeking more of your excellent post. Also, I've shared your web site in my social networks! Thank You!!!