0% found this document useful (0 votes)
36 views9 pages

ICT 2nd Quarter Reviewer

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views9 pages

ICT 2nd Quarter Reviewer

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Arduino with PIR Motion Schematics

Sensor

Introducing the PIR Motion


Sensor

The PIR motion sensor is ideal to detect


movement. PIR stands for “Passive
Infrared”. Basically, the PIR motion sensor
measures infrared light from objects in its
field of view.

So, it can detect motion based on changes


Code
in infrared light in the environment. It is ideal
to detect if a human has moved in or out of int led = 13; //
the sensor range. the pin that the LED is attached
to
int sensor = 2; //
the pin that the sensor is
attached to
int state = LOW; //
by default, no motion detected
int val = 0; //
variable to store the sensor
status (value)

void setup() {
pinMode(led, OUTPUT); //
initialize LED as an output
pinMode(sensor, INPUT); //
initialize sensor as an input
The sensor in the figure above has two Serial.begin(9600); //
built-in potentiometers to adjust the delay initialize serial
time (the potentiometer at the left) and the }
sensitivity (the potentiometer at the right).
void loop(){
Wiring the PIR motion sensor to an Arduino val = digitalRead(sensor);
is pretty straightforward – the sensor has // read sensor value
only 3 pins: if (val == HIGH) {
● GND – connect to ground // check if the sensor is HIGH
● OUT – connect to an Arduino digitalWrite(led, HIGH);
digital pin // turn LED ON
● 5V – connect to 5V
delay(100);
● It also has an electronic filter
// delay 100 milliseconds that only allows signals around
38.5 kHz to pass through.
if (state == LOW) {
Serial.println("Motion ⚪ This is the type of signal produced by
the remote control.
detected!");
state = HIGH; // ⚪ This prevents IR interference from
update variable state to HIGH common sources such as sunlight and
indoor lighting.
}

Important Concepts
IR Control

Pulse width modulation (PWM): Pulse


What is visible Light durations are used in many applications, a
few of which are motor control, and
communication. Since the IR detector sends
low pulses that can be measured to
determine what information the IR remote is
sending, it's an example of using PWM for
communication.

⚪ Carrier signal: The IR remote uses a


38.5 kHz "carrier signal" to transmit
the pulse durations from the remote to
the IR detector.
What is infrared
⚪ Communication protocol: A
communication protocol is a set of
rules for devices that have to
exchange electronic messages.
Protocols tend to have rules for
voltages, the amount of time signals
last, carrier signal frequencies and/or
wavelengths, and much more. When
two or more devices follow the rules of
a given protocol, they should be able
to communicate and exchange
information.

The TV Remote Control


The IR signal
(4 Function Universal Remote)

⚪ The IR detector is only looking for ⚪ You must configure your universal
infrared that’s flashing on and off remote so that it sends PWM
38,500 times per second. messages to a television set using the
SONY protocol.
● It has built-in optical filters that
allow very little light except the ⚪ TV remote setup
980 nm infrared.
● Press and release the TV key. ● Press and release the VCR
button (the indicator LED will
● Press and hold the SET key blink and then remain lit).
until the indicator LED on the
remote turns on and stays on. ● Use the digit keys to enter the
code 004. After your code is
● Use the digit keys to enter entered, the indicator LED will
0001. The LED may turn off turn off.
briefly as you press each digit.

⚪ VCR remote setup

● Press and release the VCR key.

● Press and hold the SET key


until the indicator LED on the The sony protocol
remote turns on and stays on.

● Use the digit keys to enter


1028. The LED may turn off
briefly as you press each digit.

The TV Remote Control


(SYSTEMLINK 3 RCA)

⚪ You must configure your universal


remote so that it sends PWM
messages using the SONY protocol.

⚪ TV remote setup

● Press and hold the CODE ⚪ This message consists of thirteen


SEARCH button until the negative pulses that the Arduino can
indicator LED lights, then easily measure.
release the CODE SEARCH
button. ● 1: the start pulse, which lasts for
2.4 ms.
● Press and release the TV
button (the indicator LED will ● 2-13: will either last for 1.2 ms
blink and then remain lit). (binary-1) or 0.6 ms (binary-0).
● Use the digit keys to enter the
● 2-8: indicates which key is
code 002. After your code is
entered, the indicator LED will pressed.
turn off.
● 9-13: indicate if the message is
⚪ VCR remote setup being sent to a TV, VCR, CD,
DVD player, etc.
● Press and hold the CODE
SEARCH button until the ⚪ Pulses are transmitted in the least
indicator LED lights, then significant bit first fashion.
release the CODE SEARCH
button. ● the first data pulse is bit-0.
● the next data pulse is bit-1 ⚪ The syntax for the pulseIn command
is
● Etc.
● pulseIn (Pin, State);
⚪ If you press and hold a key on the
remote, the same message will be
sent over and over again with a 20 to ⚪ Pin: the I/O pin for
30 ms rest between messages. measuring the pulse.

⚪ State is used to
How the IR detector works determine whether the
pulse is a HIGH or LOW

⚪ Our IR receiver is the same detector


⚪ Option third input: max
duration in millisecs
found in many TVs and VCRs.

⚪ This detector sends a low signal ● The output of the IR detector is


whenever it detects IR flashing on/off inverted (i.e., LOW).
at 38.5 kHz and a high signal the rest
of the time. ⚪ pulseIn(pin#, LOW);

⚪ When the IR detector sends low ⚪ pin# is the pin connected


signals, the processor inside a TV or to the IR detector
VCR measures how long each of the
low signals lasts. Then, it uses these
measurements to figure out which key Using pulseIn()
was pressed on the remote.

⚪ Like the processor inside a TV, the while(pulseIn(9, LOW) < 2200)
Arduino can be programmed to detect, { } //Wait for start bit
measure, store, and interpret the
sequence of low pulses it receives
from the IR detector.

Schematic diagram for IR

Interpreting the IR message

⚪ The Idea: represent the pulse


sequence as a bit sequence.

⚪ The IR message consists of thirteen


pulses with the following format:
pulseIn Command
● 1: the start pulse lasts for 2.4
ms.
● 2-13: will either last for 1.2 ms
(binary-1) or 0.6 ms (binary-0).

⚪ Map the duration of pulses 2-8 to their


corresponding binary value

● Use pulseIn() to measure pulse


length

● Use the bitSet() to create the


corresponding binary
representation

Program for reading IR signals

⚪ ReadIR

⚪ Programming Features:

● pulseIn() and bitSet()


HOW TO SET UP THE DHT11
● Arrays
HUMIDITY SENSOR ON AN
● A debug flag to turn on printout ARDUINO
● Throws away devise The DHT11 humidity and temperature
designation sensor makes it really easy to add humidity
and temperature data to your DIY
● Adjusts bit pattern to match electronics projects. It’s perfect for remote
numeric keys weather stations, home environmental
control systems, and farm or garden
monitoring systems.
Program for controlling bot
Here are the ranges and accuracy of the
• IRcontrol DHT11:
• Programming Features:
• Switch statement
● Humidity Range: 20-90% RH
• Servo library
● Humidity Accuracy: ±5% RH

● Temperature Range: 0-50 °C

● Temperature Accuracy: ±2% °C


● Operating Voltage: 3V to 5.5V HOW THE DHT11
MEASURES HUMIDITY
More Info: DHT11 Datasheet AND TEMPERATURE
The DHT11 detects water vapor by
WHAT IS RELATIVE measuring the electrical resistance between
HUMIDITY? two electrodes. The humidity sensing
The DHT11 measures relative humidity.
component is a moisture holding substrate
Relative humidity is the amount of water
with electrodes applied to the surface.
vapor in air vs. the saturation point of water
When water vapor is absorbed by the
vapor in air. At the saturation point, water
substrate, ions are released by the
vapor starts to condense and accumulate
substrate which increases the conductivity
on surfaces forming dew.
between the electrodes. The change in
resistance between the two electrodes is
The saturation point changes with air
proportional to the relative humidity. Higher
temperature. Cold air can hold less water
relative humidity decreases the resistance
vapor before it becomes saturated, and hot
between the electrodes, while lower relative
air can hold more water vapor before it
humidity increases the resistance between
becomes saturated.
the electrodes.

The formula to calculate relative humidity is:


The DHT11 measures temperature with a
surface mounted NTC temperature sensor
(thermistor) built into the unit.

With the plastic housing removed, you can


see the electrodes applied to the
Relative humidity is expressed as a
substrate:
percentage. At 100% RH, condensation
occurs, and at 0% RH, the air is completely
dry.
The DHT11 uses just one signal wire to
transmit data to the Arduino. Power comes
from separate 5V and ground wires. A 10K
Ohm pull-up resistor is needed between the
signal line and 5V line to make sure the
signal level stays high by default (see the
datasheet for more info).

There are two different versions of the

An IC mounted on the back of the unit DHT11 you might come across. One type

converts the resistance measurement to has four pins, and the other type has three

relative humidity. It also stores the pins and is mounted to a small PCB. The
PCB mounted version is nice because it
calibration coefficients, and controls the
includes a surface mounted 10K Ohm pull
data signal transmission between the
up resistor for the signal line. Here are the
DHT11 and the Arduino:
pin outs for both versions:

HOW TO SET UP THE


DHT11 ON AN ARDUINO
Wiring the DHT11 to the Arduino is really
easy, but the connections are different install, just download the DHTLib.zip file
depending on which type you have. below and open up the Arduino IDE. Then
go to Sketch>Include Library>Add .ZIP
CONNECTING A THREE PIN Library and select the DHTLib.zip file.
DHT11: After it’s installed, upload this example
program to the Arduino and open the

serial monitor: DHTLib

#include <dht.h>

dht DHT;
CONNECTING A FOUR PIN
#define DHT11_PIN 7
DHT11:
void setup(){

Serial.begin(9600);

void loop(){

int chk = DHT.read11(DHT11_PIN);


● R1: 10K Ohm pull up resistor
Serial.print("Temperature = ");
DISPLAY HUMIDITY AND
Serial.println(DHT.temperature);
TEMPERATURE ON THE
Serial.print("Humidity = ");
SERIAL MONITOR
Serial.println(DHT.humidity);
Before you can use the DHT11 on the
Arduino, you’ll need to install the DHTLib delay(1000);

library. It has all the functions needed to


}
get the humidity and temperature
readings from the sensor. It’s easy to You should see the humidity and
temperature readings displayed at one lcd.print(DHT.humidity);
lcd.print("%");
second intervals. delay(1000);
}

If you don’t want to use pin 7 for the data USING THE DATA IN
signal, you can change the pin number in OTHER PROGRAMS
line 5 where it says #define DHT11_PIN What if you don’t want to output the actual
7. humidity and temperature readings, but
need them to calculate or control other
DISPLAY HUMIDITY AND things? The code below is the bare

TEMPERATURE ON AN minimum needed to initialize the sensor.

LCD You can add this to existing programs and

A nice way to display the humidity and use DHT.humidity and DHT.temperature

temperature readings is on a 16X2 LCD. as variables in any function.

To do this, first follow our tutorial on How


#include <dht.h>
to Set Up an LCD Display on an Arduino,
dht DHT;
then upload this code to the Arduino:

#define DHT11_PIN 7
#include <dht.h>
#include <LiquidCrystal.h> void setup(){
LiquidCrystal lcd(12, 11, 5, 4, 3,
2); }

dht DHT;
void loop(){
#define DHT11_PIN 7
int chk = DHT.read11(DHT11_PIN);
void setup(){
lcd.begin(16, 2);
} delay(1000);

void loop(){ }
int chk = DHT.read11(DHT11_PIN);
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(DHT.temperature);
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Humidity: ");

You might also like