Labels

Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts

Wednesday, April 29, 2020

The Ultimate Guide to PIR Sensors

PIR Motion Sensor ( DYP-ME001)


PIR Sensor

An Introduction to PIR Motion Sensor

Passive Infrared (PIR) sensors are primarily used to detect motion, making them especially popular for sensing human movement. Compact, energy-efficient, and cost-effective, these sensors are staples in security and automation projects.While most commonly referred to as PIR sensors, they are also known as pyroelectric or IR motion sensors. At their core, they work by detecting changes in infrared radiation levels within their field of view.Although there are many types of PIR sensor modules available—such as the HC-SR501 and the DYP-ME001—this guide will focus specifically on the DYP-ME001 and how to interface it with an Arduino. (Note: These sensors can also function independently without a microcontroller.)

DYP-ME001


Specification Of  DYP-ME001

Input Voltage - DC 4.5 - 20V
Static Current - 500uA
Block Time - 2.5s
Delay Time - 5s
Sentry Angle < 110
Sentry Range -3m to 7m

The Science Behind Detecting Heat and Motion

When a heat source, such as a human or animal, passes through the sensor's field of view, it first crosses one of the sensor's two infrared-sensitive halves. This creates a positive differential change in infrared radiation between the two sides.

As the warm body continues moving and crosses the second half, the reverse occurs, generating a negative differential change. The sensor's onboard circuitry detects these rapid, alternating voltage spikes—first positive, then negative—and translates them into a motion detection signal.


PIR Setting

Trigger Mode Jumper

Unlike some PIR sensors, the DYP-ME001 module lacks user-configurable jumper pins for selecting trigger modes. Instead, it is hardwired to operate in the 'H' (Repeatable Trigger) mode by default. In contrast, modules like the widely used HC-SR501 feature adjustable jumpers, allowing you to easily toggle between repeatable ('H') and non-repeatable ('L') trigger configurations

L position

When a warm body moves in front of the sensor, it will trigger an output signal.

The behavior of this signal depends on the mode the sensor is configured for:

Non-Retriggering (Single Trigger) Mode: In this mode, the sensor triggers once when motion is first detected. It will then remain 'ON' for a pre-set duration and will not re-trigger, even if motion is still present. This means that after the initial trigger, the output will turn 'OFF' after its set time has expired and will not turn on again until a new motion event is detected.

Retriggering Mode (Commonly set as 'H' on HC-SR501): This is the more common mode. As long as motion is continuously detected, the sensor's output will stay 'ON'. The timer will reset every time motion is detected, ensuring the signal remains active. The output only turns 'OFF' after motion has ceased for the duration of the pre-set time.

H position

Sensor will turn on entire time that something is moving. So we call this as retriggering or repeatable trigger mode.

Sensitivity and Time Adjustment

Sensitivity

According to PIR motion sensor (DYP-ME001) specification adjustable range is from 3m to 7m. Here is way adjust.

Clockwise or Right side -- decrease sensitivity, so it fully right and range will be approximately 3m.

Counter Clockwise or Left side --increase sensitivity , so it fully right and range will be   approximately 7m.

Time Adjustment

This adjustment  determined how long of  PIR sensor will remain high after motion detected.

Clockwise or Right side -- Increase  delay,So it fully right and delay will be approximately 5 second.

Counter Clockwise or Left side -- decrease delay , So it fully left and delay will be approximately 3 second


Code Sample 

int motion_in =2;
int led_out=3; 

void setup() {
pinMode(motion_in ,INPUT);
pinMode(led_out,OUTPUT);    }

void loop() {
  // put your main code here, to run repeatedly:
 
int pir_read = digitalRead(motion_in);
if(pir_read==1)

  digitalWrite(led_out ,HIGH);
  delay(1000);
}
else
{
    digitalWrite(led_out,LOW);
    delay(300);
}}




Thursday, April 20, 2017

How do i program IR Sensor - Arduino


FC-51 IR sensor module is a proximity sensor module. We can identify obstacle in front of sensor. So it has built in IR transmitter and IR receiver. It also has built in potentiometer to adjust distance rage. IR sensor module operate in 2cm-30cm range. FC-51 is compatible with Arduino.

Technical Specification 

1. Operation Voltage - 3.3V - 5V
2. Detection Angle   -35 degrees
3 Active Output level - Outputs Low logic level when obstacle is detected
4.Detection range: 2cm – 30cm (Adjustable using potentiometer)

PIN Out & In

1. VCC - 3.3V-5V DC power input
2. GND -0V Power pin
3. OUT -  Digital Output Pin

Programming 

There are may way to do it. So here i try to use IR sensor with Arduino Uno board. When obstacle is detected by sensor, it will generate LOW output, otherwise output is HIGH.


Example 1 

int irSenRead =7;
int isObstacle = HIGH;
void setup() {

  pinMode(irSenRead ,INPUT);
   Serial.begin(9600);

}

void loop() {

  isObstacle = digitalRead(irSenRead); // // Read IR sensor output
   Serial.println(digitalRead(irSenRead)); // // print the output

  // // isObstacle ==low there is obstacle infront of sensor
  // // using serial monitor we can see this output
  if (isObstacle == LOW) {
    Serial.println("OBSTACLE");
  }
  else
  {
    Serial.println("NO");
  }

  delay(500);
}

Example 2
In below code sample .LED bulb will be on when obstacle detected

int irSenRead =7;
int LED=6;
int isObstacle = HIGH;
int delayRead =100;
void setup() {

  pinMode(irSenRead ,INPUT);
   pinMode(LED ,OUTPUT);
   Serial.begin(9600);

}

void loop() {

  isObstacle = digitalRead(irSenRead);
   Serial.println(digitalRead(irSenRead));

   // isObstacle ==low there is obstacle infront of sensor
  if (isObstacle == LOW) {
    digitalWrite(LED ,HIGH);
  }
  else
  {
    digitalWrite(LED ,LOW);
  }

  delay(delayRead);
}



Monday, April 17, 2017

LEDs blink in a sequence with Arduino [Knight Rider]

e all remember the iconic 80s TV series Knight Rider. One of the most memorable features was the car’s signature sweeping LED flash. For this project, I used an Arduino UNO to recreate that display using 10 LEDs. While there are many ways to program the Arduino microchip, here is the approach I took to get that classic 'scanner' look.

Knight Rider 1

void setup() {

  
     pinMode(2,OUTPUT);
       pinMode(3,OUTPUT);
         pinMode(4,OUTPUT);
           pinMode(5,OUTPUT);
             pinMode(6,OUTPUT);
               pinMode(7,OUTPUT);
                pinMode(8,OUTPUT);
                 pinMode(9,OUTPUT);
                  pinMode(10,OUTPUT);
                   pinMode(11,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
    for(int i=1;i<12;i=i+1)
 {
  digitalWrite(i,HIGH);
  digitalWrite(i+1,HIGH);
  digitalWrite(i+2,HIGH);
  
  delay(100);
  digitalWrite(i,LOW);
  digitalWrite(i+1,LOW);
  digitalWrite(i+2,LOW);
  
 }

for(int i =12 ;i>=1;i--)
 {
  digitalWrite(i,HIGH);
   digitalWrite(i-1,HIGH);
    digitalWrite(i-2,HIGH);
  delay(100);
  digitalWrite(i,LOW);
   digitalWrite(i-1,LOW);
     digitalWrite(i-2,LOW);
  
 }
}

Knight Rider 2

int pinArray[] = {2, 3, 4, 5, 6, 7,8,9,10,11};

int delayTime = 100;
void setup() {
  // put your setup code here, to run once:
for (int i=0;i<11;i++) {
    pinMode(pinArray[i], OUTPUT);
  }
}

void loop() {
  for (int i=2;i<11;i++) {
   digitalWrite(pinArray[i], HIGH);   
   digitalWrite(pinArray[i+1], HIGH);
   digitalWrite(pinArray[i+2], HIGH);
     delay(delayTime);

    digitalWrite(pinArray[i], LOW);   
   digitalWrite(pinArray[i+1], LOW);
   digitalWrite(pinArray[i+2], LOW);
  }
  for (int i=11;i>=2;i--) { 

  digitalWrite(pinArray[i],HIGH);
  digitalWrite(pinArray[i-1],HIGH);
  digitalWrite(pinArray[i-2],HIGH);
    delay(delayTime);
  digitalWrite(pinArray[i],LOW);
  digitalWrite(pinArray[i-1],LOW);
  digitalWrite(pinArray[i-2],LOW);
  }

}