Home

Input Devices

This week objective is to read and use signal coming from a sensor.
Sensor a device which detects or measures a physical property and records, indicates, or otherwise responds to it.
I decided that I'll work on the Pyroelectric sensor which detects motion,Because it one of the things I'll use in my final project. PIR Sensor: The PIR sensor stands for Passive Infrared sensor. It is a low cost sensor which can detect the presence of Human beings or animals. I used the module provided on the academy website labeled (HC-sr501).

Pin Configuration:

Pin Number

Pin Name

Description

1

Vcc

Input voltage is +5V for typical applications. Can range from 4.5V- 12V

2

High/Low Ouput (Dout)

Digital pulse high (3.3V) when triggered (motion detected) digital low(0V) when idle(no motion detected)

3

Ground

Connected to ground of circuit


PIR Sensor Feature:

  • Wide range on input voltage varying from 4.V to 12V (+5V recommended)
  • Output voltage is High/Low (3.3V TTL)
  • Can distinguish between object movement and human movement
  • Has to operating modes - Repeatable(H) and Non- Repeatable(H)
  • Cover distance of about 120° and 7 meters
  • Low power consumption of 65mA
  • Operating temperature from -20° to +80° Celsius

How to use PIR Motion Sensor

The PIR sensor stands for Passive Infrared sensor. It is a low cost sensor which can detect the presence of Human beings or animals. This sensor has three output pins Vcc, Output and Ground as shown in the pin diagram above. Since the output pin is 3.3V TTL logic it can be used with any platforms like Arduino, Raspberry, PIC, ARM, 8051 etc.. The module can be powered from voltage 4.5V to 20V but, typically 5V is used. Once the module is powered allow the module to calibrate itself for few minutes, 2 minutes is a well settled time. Then observe the output on the output pin. Before we analyse the output we need to know that there are two operating modes in this sensor such as Repeatable(H) and Non- Repeatable(L) and mode. The Repeatable mode is the default mode. The output of the sensor can be set by shorting any two pins on the left of the module as shown below. You can also notice two orange colour potentiometers that can be used to set the sensitivity and time which will be explained further below.


Repeatable(H) Mode :

In Repeatable(H) mode the output pin Dout will go high (3.3V) when a person is detected within range and goes low after a particular time (time is set by “Off time control” potentiometer). In this mode the output pin will go high irrespective of whether the person is still present inside the range or has left the area. The sensitivity can be set using the “sensitivity control” potentiometer.

Non- Repeatable(L) mode

In “I” mode the output pin Dout will go high (3.3V) when a person is detected within range and will stay high as long as he/she stays within the limit of the Sensors range. Once the person has left the area the pin will go low after the particular time which can be set using the potentiometer. The sensitivity can be set using the “sensitivity control” potentiometer.


There are two important materials present in the sensor one is the pyroelectric crystal which can detect the heat signatures from a living organism (humans/animals) and the other is a Fresnel lenses which can widen the range of the sensor. Yes the white colour things is just a lense that is used to widen the range of the sensor, if you remove the lense you can find the Pyroelectric sensor inside it covered inside a protective metal casing as shown above.

Designing:

I used Eagle software like usual to design my PCB. and I did exactly what I did in Electronics production week that you are kindly asked to refer to it.

Components and Tools:

  • 1 x ATTiny 45
  • 1 x FTDI headers
  • 1 x Capacitor (1uf)
  • 1 x Resistor (10k ohm)
  • 1 x Resistor (499 ohm) (Probably will be removed in Try 2)
  • 1 x LED (Probably will be removed in Try 2)
  • 1 x HC-SR01 Module Sensor
  • 1 x Roland Modela MDX-20
  • 1 x Soldering Station

Board Production Result: (Try No.1)





Because of the module size I had to bend the ping headers a bit to make them touch the PCB as shown below.

Board Interior & Traces:

Try 1

This design I connected the LED in parallel which acted as a voltage divider circuit that led to abnormal respones because the voltage was way below desired to detect it as a HIGH signal.




Try 2





PIR wires connection:

As shown below again the pins of the PIR sensor (Make sure the orientation is correct and the orange potentiometer at the bottom and the pins are at the top)


and then connect them to the board:


The white labeled pins will be connected to the sensor corresponding pins.
And the red labeled pins will be connected to the FTDI corresponding pins.

IR wires connection:

The IR sensor connections are almost the same what only changed was the sequence of pins on the IR sensor not the board and the enable pin that I didn't use.
With green enable cap plugged as shown below, EN terminal is equal to "1" when the sensor does not work, equal to "0" when working, which I found it with no use in my particular example, yet it could be used to check if the sensor is working or not, but signal pin is used for knowing whether there's a reading or not which's the desired.





The white labeled pins will be connected to the sensor corresponding pins.
And the red labeled pins will be connected to the FTDI corresponding pins.

Lastly, if you're confused between what's Rx a what's Tx, I advice you to visit Networks and Communication week to understand more.

Coding:

I used the help of this excellent reference to understand how to initialize serial communication between my board and PC.


// This is a comment that doesn't affect the code, just text to explain.

#include <SoftwareSerial.h> //This is a library that make us initialize the communication to use the TX & RX pin.
#define RX    3 // In my board I don't use the RX, I chose an unconnected pin.
#define TX    2 // the pin that the ATtiny RX will send data to the PC

SoftwareSerial Serial(RX, TX); // giving the pin variables to the softwareSerial library after defining them in the line upward.

int val=0; //variable to store the values of the reading.
void setup()
{
  Serial.begin(9600); //define the baud rate that the communication will start on.
}
void loop()
{
  
val = digitalRead(2); // read the input pin and store it in Val variable.
delay(250); //Optional delay to ease reading the serial monitor values.
Serial.println(val); // print the values stored in Val variable.
}

Before uploading make sure you've selected the right settings for your ATTiny45:

If you can't find a COM for your board:
First, make sure your FTDI cable is connected correctly as well as your other board cable either it's usb or tinyUsb.
Secondly, make sure you've installed the proper drivers for your FTDI cable (Check Embedded Programming academy tutorials)

Final Result:

As you can see I changed the sensor at the end because the (HC-SR501) was detecting motion with a big delay and have to wait between the readings which's not the purpose I wanted to have in particular, so I used IR Infrared sensor to detect motion.

Using the connection I instructed you to use above in the IR and PIR connection part, you just change the wires connection and the same arduino code uploaded will work. How ?

Because both sensor send similar data:
PIR: Sends either 0 for detecing or 1 for detecting nothing.
IR: Sends either 0 for detecing or 1 for detecting nothing.

Download Files:

Eagle Files
Arduino code
Eagle Files & Milling Pictures (Try 1 & 2)