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

Sensor and Actuator

The document provides an overview of sensors and actuators, detailing their classifications, types, and functionalities. It explains the differences between active and passive sensors, contact and non-contact sensors, and introduces the Arduino microcontroller and its applications in digital and analog input/output. Additionally, it covers programming basics, interfacing requirements, and examples of using LEDs and switches with Arduino.

Uploaded by

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

Sensor and Actuator

The document provides an overview of sensors and actuators, detailing their classifications, types, and functionalities. It explains the differences between active and passive sensors, contact and non-contact sensors, and introduces the Arduino microcontroller and its applications in digital and analog input/output. Additionally, it covers programming basics, interfacing requirements, and examples of using LEDs and switches with Arduino.

Uploaded by

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

Sensor and Actuator

Terminology
• Transducers convert one form of energy into another
• Sensors/Actuators are input/output transducers
• Sensors can be passive (e.g. change in resistance)
or active (output is a voltage or current level)
• Sensors can be analog (e.g. thermocouples) or
digital (e.g. digital tachometer)
Transducer types
Quantity
Input Device Output Device
being
(Sensor) (Actuator)
Measured
Light Dependant Resistor (LDR),
Lights & Lamps, LED's
Light Level Photodiode, Phototransistor, Solar
& Displays, Fiber Optics
Cell
Thermocouple, Thermistor,
Heater, Fan, Peltier
Temperature Thermostat, Resistive temperature
Elements
detectors (RTD)
Lifts & Jacks,
Force/Press Strain Gauge, Pressure Switch,
Electromagnetic,
ure Load Cells
Vibration
Potentiometer, Encoders,
Motor, Solenoid, Panel
Position Reflective/Slotted Opto-switch,
Meters
LVDT
Tacho-generator, Reflective/Slotted
AC and DC Motors,
Speed Opto-coupler, Doppler Effect
Stepper Motor, Brake
Sensors
Carbon Microphone, Piezo-electric Bell, Buzzer,
Sound
Crystal Loudspeaker
Classification of Sensors and
Actuators
• Based on physical laws
• Based on any convenient distinguishing
property
• Possible to a certain extent

1. Active and Passive sensors


2. Contact and non-contact sensors
3. Absolute and relative sensors
4. Other schemes
1. Active and passive sensors
Active sensor: a sensor that requires external
power to operate. Examples: the carbon
microphone, thermistors, strain gauges,
capacitive and inductive sensors, etc.
Other name: parametric sensors (output is a
function of a parameter - like resistance)

Passive sensor: generates its own electric signal


and does not require a power source. Examples:
thermocouples, magnetic microphones,
piezoelectric sensors.
Other name: self-generating sensors
Note: some define these exactly the other way
around
2. Contact and noncontact
sensors
Contact sensor: a sensor that requires physical
contact with the stimulus. Examples: strain
gauges, most temperature sensors

Non-contact sensor: requires no physical contact.


Examples: most optical and magnetic sensors,
infrared thermometers, etc.
3. Absolute and relative
sensors
Absolute sensor: a sensor that reacts to a stimulus
on an absolute scale: Thermistors, strain gauges,
etc., (thermistor will always read the absolute
temperature)

Relative scale: The stimulus is sensed relative to a


fixed or variable reference. Thermocouple
measures the temperature difference, pressure is
often measured relative to atmospheric pressure.
4. Other schemes

Classification by broad area of detection


• Electric sensors
• Magnetic
• Electromagnetic
• Acoustic
• Chemical
• Optical
• Heat, Temperature
• Mechanical
• Radiation
• Biological
• Etc.
4. Other schemes (cont.)
Classification by physical law
• Photoelectric
• Magnetoelectric
• Thermoelectric
• Photoconductive
• Magnitostrictive
• Electrostrictive
• Photomagnetic
• Thermoelastic
• Thermomagnetic
• Thermooptic
• Electrochermical
• Magnetoresistive
• Photoelastic
• Etc.
4. Other schemes (cont.)
Classification by specifications
• Accuracy
• Sensitivity
• Stability
• Response time
• Hysteresis
• Frequency response
• Input (stimulus) range
• Resolution
• Linearity
• Hardness (to environmental conditions, etc.)
• Cost
• Size, weight,
• Construction materials
• Operating temperature
• Etc.
4. Other schemes (cont.)
Classification by area of application
• Consumer products
• Military applications
• Infrastructure
• Energy
• Heat
• Manufacturing
• Transportation
• Automotive
• Avionic
• Marine
• Space
• Scientific
Digital vs. Analog Sensors

1) Digital sensors: The signal produced or


reflected by the sensor is binary

2) Analog sensors: The signal produced by


the sensor is continuous and proportional to
the measurand
Is the signal discrete or continuous?
Classification of actuators
All of the above
In addition:
Classification of actuators by type of
motion
• Linear
• Rotary
• One-axis
• Two-axes
• Three-axes
• Etc.
Classification of actuators

• Low power actuators


• High power actuators
• Micropower actuators
• Etc.
Requirements for interfacing

Needs:
• Matching (impedances, voltages, currents, power)
• Transformations (AC/DC, DC/AC, A/D, D/A, VtoF,
etc.)
• Matching of specifications (temperature ranges,
environmental conditions, etc.)
• Alternative designs
• Etc.
Connection of
sensors/actuators

• The processor should be viewed as a general block


– Microprocessor
– Amplifier
– Driver
– Etc.
• Matching: between sensor/processor and processor/actuator
Example - Temperature
control

• Sense the temperature of a CPU


• Control the speed of the fan to keep the
temperature constant
Intro to the Arduino

Topics:
The Arduino
Digital IO
Analog IO
Serial Communication
What is a Microcontroller

www.mikroe.com/chapters/view/1

• A small computer on a single chip


• containing a processor, memory, and input/output
• Typically "embedded" inside some device that they control
• A microcontroller is often small and low cost
• Examples
What is a Development Board
• A printed circuit
board designed to
facilitate work with
a particular
microcontroller.
• Typical components include:
• power circuit
• programming interface
• basic input; usually buttons and LEDs
• I/O pins
Arduino Board
• “Strong Friend” Created in Ivrea, Italy
• in 2005 by Massimo Banzi & David Cuartielles
• Open Source Hardware
• Processor
• Coding is accessible & transferrable → (C++, Processing, java)
Arduino…
• is the go-to gear for artists, hobbyists,
students, and anyone with a gadgetry
dream.

• rose out of another formidable challenge:


how to teach students to create
electronics, fast.

http://spectrum.ieee.org/geek-life/hands-on/the-making-of-arduino
The Arduino Microcontroller: Atmel
ARV Atmega 328

Specification
Making-robots-with-arduino.pdf
What is the Arduino

todbot.com/blog/bionicarduino
Different Varieties of Arduino
Digital Input / Digital output
(PWM on pins 3, 5, 6, 9, 10, 11)

USB Arduino
connection Uno
Revision
7-12 volt 3
input power
(9v is
common) Power Analog input /
pins Digital input or
output
Topic 1: Meet Arduino Uno
Getting Started
• Check out: http://arduino.cc/en/Guide/HomePage
1. Download & install the Arduino environment (IDE)
2. Connect the board to your computer via the UBS
cable
3. If needed, install the drivers (not needed in lab)
4. Launch the Arduino IDE
5. Select your board
6. Select your serial port
7. Open the blink example
8. Upload the program
Try It: Connect the USB Cable

todbot.com/blog/bionicarduino
Arduino IDE

See: http://arduino.cc/en/Guide/Environment for more information


Terminology
Select Serial Port and Board
Status Messages

todbot.com/blog/bionicarduino
todbot.com/blog/bionicarduino
Add an External LED to pin 13

• File > Examples > Digital > Blink


• LED’s have polarity
– Negative indicated by flat side of the housing
and a short leg

www.instructables.com
Our First Program
A Little Bit About Programming
• Code is case
sensitive
• Statements are
commands and
must end with a
semi-colon
• Comments follow a
// or begin with /*
and end with */
• loop and setup
Input/Output

Image from Theory and Practice of Tangible User Interfaces at UC Berkley


Digital Input/Output

1
• Digital IO is binary
valued—it’s either on 0
or off, 1 or 0
• Internally, all
microprocessors are
digital, why?
Analog to Digital Coversion
• What is analog ?
• It is continuous range of voltage values
(not just 0 or 5V)

• Why convert to digital ?


• Because our microcontroller only
understands digital.
ADC in Arduino Uno
Converting Analog Value to Digital
Quantanization the signal
ADC in Arduino
• The Arduino Uno board contains 6 pins for
ADC

• 10-bit analog to digital converter

• This means that it will map input voltages


between 0 and 5 volts into integer values
between 0 and 1023
Getting started with Programming
Bare minimum code
void setup() {
// put your setup code here, to run once:
}

void loop() {
// put your main code here, to run
repeatedly:
}
Bare minimum code
• setup : It is called only when the Arduino is
powered on or reset. It is used to initialize
variables and pin modes

• loop : The loop functions runs continuously


till the device is powered off. The main
logic of the code goes here. Similar to
while (1) for micro-controller programming.
PinMode
• A pin on arduino can be set as input or
output by using pinMode function.

• pinMode(13, OUTPUT); // sets pin 13 as


output pin

• pinMode(13, INPUT); // sets pin 13 as


input pin
Reading/writing digital values
• digitalWrite(13, LOW); // Makes the output
voltage on pin 13 , 0V

• digitalWrite(13, HIGH); // Makes the output


voltage on pin 13 , 5V

• int buttonState = digitalRead(2); // reads


the value of pin 2 in buttonState
Reading/Writing Analog Values
• analogRead(A0); // used to read the
analog value from the pin A0

• analogWrite(2,128);
Light Emitting Diode: LED
What is an LED?
• Light-emitting diode
• Semiconductor
• Has polarity
LED: How It Works
• When current flows
across a diode

• Negative electrons move one way


and positive holes move the other
way
LED: How It Works
• The wholes exist at a
lower energy level
than the free
electrons

• Therefore when a free electrons


falls it losses energy
LED: How It Works
• This energy is
emitted in a form of a
photon, which
causes light

• The color of the light is determined


by the fall of the electron and hence
energy level of the photon
Inside a Light Emitting Diode

1. Transparent
Plastic Case
2. Terminal Pins
3. Diode
Kinds of LEDs
What is the differece between
LEDs?
LED Series Resistor Circuit
How to Connect a LED:
• Requires 1.5~2.5V and 10 mA
• To prevent overloading, use resistor 470
Ω
How to Connect a LED:
Connect LED to BS2
• LED is on when P0
is high

• LED is on when P1
is low
Case Study: Blinking LED
• Pbasic program to make an LED blink
output 0

Main:
low 0
pause 1000
high 0
pause 1000
goto Main
int pin = 13;

void setup()
{
pinMode(pin, OUTPUT);
}
void loop()
{
digitalWrite(pin, HIGH);//set the LED
delay(1000);
digitalWrite(pin, LOW);//set the LED
delay(1000);

}
ATmega328 Internal Architecture

http://www.adafruit.com/index.php?main_page=popup_image&pID=50
ATmega328 Microcontroller
Pin number
Pin name

Special
function

Note the
limitations!
p. 316
Absolute Maximums

ATmega328 data sheet p. 316


Single/Double/Tri Color LED Matrix
7 segment LED Digital Display
LED Strips
RGB LEDs

Sparkfun.com
http://www.jameco.com/
www.ledsupply.com/
http://www.oznium.com/led-strip-flat-head
What's a switch?
Measure Open and Closed
Circuits
Push Button Switches
• Pushing the button changes state
• State is reversed (return to biased positon) when button
is released

• Two types
✓ NO: normally open
✓ NC: normally closed
Continuous monitor of button
state

This program does not control the LED


Limit Switch
Limit switches perform the same function as push button
switches.
Advantages
• High Current Capability
•Low Cost
•Familiar “Low- Tech" Sensing
Disadvantages
• Requires Physical
• Contact with Target
• Very Slow Response
Logic circuit
• In digital input pin, for any program looks
for HIGH and LOW values as conditions to
perform certain actions.
Floating Voltages
• However, sometimes a digital pin will
register a ‘floating voltage’ and the value
read on the pin will not be perfectly stable.
Pull-up Resistors
• Pull-up resistors are
resistors which are used to
ensure that a wire is pulled
to a high logical level in the
absence of an input signal.
Pull-down Resistors
• Pull-down resistors work in
the same manner as pull-up
resistors, except that they
pull the pin to a logical low
value

Read more http://www.resistorguide.com/pull-up-


resistor_pull-down-resistor/
Pull up resistor / Pull down
resistor

Pull Down Resistor


Pull-up Resistor
Floating Pins, Pull-Up
Resistors and Arduino
Electromagnetic Relay
Arduino-
Digital Output – Controling any Electrical
Device with any power needs using a relay
Externally Powered Device

3v-220v
External Power
Externally Powered Device

// Connect to Pin 13 and Ground


void setup(){
pinMode(13, OUTPUT); // Specify Arduino Pin number and
output/input mode
}
void loop(){
digitalWrite(13, HIGH); // Turn on Pin 13 sending a HIGH Signal
delay(1000); // Wait for one second
digitalWrite(13, LOW); // Turn off Pin 13 sending a LOW Signal
delay(3000); // Wait for Three second
}

GRD Control Pin 81


Pin 2 -> COL 7 Pin 8 -> ROW 1
Pin 3 -> COL 6 Pin 7 -> ROW 2
Pin 4 -> COL 5 Pin 6 -> ROW 3
Pin 5 -> ROW 4
#include "Keypad.h"

const byte ROWS = 4; //four rows


const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup()
{
Serial.begin(9600);
}

void loop()
{
char key = keypad.getKey();

if (key != NO_KEY){
Serial.println(key);
}
}
Raspberry
Pi
Raspberry Pi
• A Raspberry Pi is a credit
card-sized computer originally
designed for education,
inspired by the 1981 BBC
Micro.
• Creator Eben Upton's goal
was to create a low-cost
device that would improve
programming skills and
hardware understanding at the
pre-university level.
What is Raspberry Pi ?
• Arguably the most popular single board
computer (SBC)
• Easy to get started with because basically
every problem is documented
• Add a computer with a OS to practically
anything • Support for a vast array of
peripherals (thanks to the Linux kernel) USB
devices, networking, displays, cameras, audio
etc.

NOTE: Do not expect it to


perform as well as your laptop
Raspberry Pis in Primary Ed.

http://www.youtube.com/watch?v=KdTwQXre1D
U
What can you do with a Pi? (not
so cool)

http://mymediaexperience.com/raspberry-pi-xbmc-with-raspbmc/

https://www.raspberrypi.org/magpi/magic-mirror/

https://github.com/foosel/OctoPrint
https://vadelmapii.com/blogi/yllapida-omaa-dropbox-kloonia-raspberry-pilla-kayttaen-owncloudia
What can you do with a Pi? (cool)

https://hackaday.io/project/1279-ramanpi-raman-spectrometer https://www.raspberrypi.org/blog/real-time-depth-perception-with-the-compute-module/

http://www.zdnet.com/article/build-your-own-supercomputer-out-of-raspberry-pi-boards/
Variations of Raspberry Pi
• Hardware platform
– Raspberry Pi Zero ($5)
– Raspberry Pi
– Raspberry Pi 2
– Raspberry Pi 3 (with Wifi + Bluetooth)
• Software platform
– Noobs
– Raspbian
– 3rd OS
– https://www.raspberrypi.org/downloads/
Raspberry Pi models

25.12.2019 96
Raspberry Pi advantages and
disadvantages

• Cheap (price per performance) • Scary linux (learning required)


• Well documented • Not real time*
• Availability • No ADC (easy to add though)
• Also in terms of add-ons (HATs) • PWM possible but limited frequency
• Multipurpose
• Compact (especially Zero)

* It is possible to install a RTOS on the Pi


Getting started
1. Install OS
2. Configure OS
3. Connect peripherals
4. Write software
5. Profit (?)
>Power Cable
>SD card

>Video cable
>Keyboard

>Wireless Adapter
>Speakers
>Pi Display
>Pi Camera
>Pi Case
Connections

GPIO
MicroSD-slot
(underneath)
4x USB 2.0

Display connector

Micro USB for Ethernet


power (min. 5V/1A)

3.5mm Audio/Video Jack


HDMI
On first boot…
• NOOBS installer
has GUI
(Raspbian
recommended)
• Boots into raspi-
config (you can
run it with “sudo
raspi-config”)
• Expand file
system, change
password and
change keyboard
layout, enable
ssh etc.
Terminal or Pixel
• There are two options when booting: shell
or Pixel desktop (graphical session)
CLI / Shell commands
Command Description

ls List contents of current directory (folder)

cd Change directory

mkdir Creates a new directory (make directory)

sudo Execute as super user (“admin” / root privileges)

cp Copy (syntax is cp src dest)

mv Move (syntax is mv src dest)

rm Remove

./ Dot-slash means execute

nano Launch nano text editor

apt-get update Update repository list (update list of links to software downloads)

apt-get install Install a package

reboot Reboots the system (run with sudo)

poweroff Turns the Raspberry Pi off (run with sudo)


Programming language options

• Almost everything
• C, C++, Python2/3, Javascript (node), Ruby, Lisp, Rust…

• Most projects are either C or Python


Tips

• If you need e.g. read analog voltages and


control motors → consider combining an
Arduino with a Raspberry Pi
• (Raspberry Pi commands Arduino board
via serial (USB))
Links
• Help videos (getting started)
• Embedded Linux Wiki
• Raspberry Pi Forums
• Hackaday.io Raspberry Pi projects
• Adafruit learning guides
• Raspberry Pi subreddit
Raspberry Pi Simulator

• Raspberry Pi Azure IoT Online Simulator


• https://azure-samples.github.io/raspberry-
pi-web-simulator/

• Raspbian x86 on VirtualBox on a


Windows PC
• http://www.aoakley.com/articles/2017-07-
04-raspbian-x86-virtualbox.php
END
Temperature Sensors
Brief Overview
➢Types of Sensors and how they work
➢Sensor Applications
➢Advantages and Disadvantages
➢Sensors that will work with our project
Types of Temperature Sensors
➢ Thermocouples
➢ Resistance
Temperature
Detectors (RTDs)
➢ Thermistors
➢ Infrared Sensors
➢ Semiconductors
Thermocouples
➢ A thermocouple is an electrical device
consisting of two dissimilar electrical
conductors forming electrical junctions
at differing temperatures. A
thermocouple produces a temperature-
dependent voltage as a result of the
thermoelectric effect, and this voltage
can be interpreted to measure
temperature. Thermocouples are a
widely used type of temperature
sensor.
➢ Two wires of different metal alloys.
➢ Converts thermal energy into electrical
energy.
➢ Requires a temperature difference
between measuring junction and
Thermocouple Applications
➢ Plastic injection molding
machinery
➢ Food processing
equipment
➢ Deicing
➢ Semiconductor processing
➢ Heat treating
➢ Medical equipment
➢ Industrial heat treating
➢ Packaging equipment
Thermocouples
Advantages Disadvantages

➢ Simple- ➢ Least stable, least


➢ High temperature repeatable
operation ➢ Low sensitivity to small
➢ Low cost temperature changes
➢ No resistance lead wire ➢ Extension wire must be of
problems the same thermocouple
➢ Fastest response to type
temperature changes ➢ Wire may pick up
radiated electrical noise if
not shielded
➢ Lowest accuracy
Resistance Temperature Detectors
(RTDs)
➢ Wire wound and thin
film devices.
➢ Nearly linear over a
wide range of
temperatures.
➢ Can be made small
enough to have
response times of a
fraction of a second.
➢ Require an electrical
current to produce a
voltage drop across the
sensor
RTD Applications
➢ Air conditioning and
refrigeration servicing
➢ Furnace servicing
➢ Foodservice
processing
➢ Medical research
➢ Textile production
RTDs
Advantages Disadvantages

• Most stable over time • High cost


• Most accurate • Slowest response time
• Most repeatable • Low sensitivity to small
temperature temperature changes
measurement • Sensitive to vibration
• Very resistant to (strains the platinum
contamination/ corrosion element wire)
of the RTD element • Somewhat fragile
Thermistors
• A semiconductor used as a temperature sensor.
• Mixture of metal oxides pressed into a bead, wafer or other
shape.
• Beads can be very small, less than 1 mm in some cases.
• The resistance decreases as temperature increases,
negative temperature coefficient (NTC) thermistor.
What are PTC thermistors
• PTC stands for “Positive Temperature
Coefficient”. PTC thermistors are resistors
with a positive temperature coefficient,
which means that the resistance increases
with increasing temperature.
Thermistors
• Most are seen in
medical equipment
markets.
• Thermistors are also
used are for engine
coolant, oil, and air
temperature
measurement in the
transportation
industry.
Thermistors
Advantages Disadvantages
• High sensitivity to • Limited temperature
small temperature range
changes • Fragile
• Temperature • Some initial accuracy
measurements “drift”
become more stable
with use
• Copper or nickel
extension wires can
be used
Infrared Sensors
• Infrared temperature sensors sense
electromagnetic waves in the 700 nm to
14,000 nm range.
• These sensors work by focusing the
infrared energy emitted by an object onto
one or more photodetectors.
Infrared Applications
• Manufacturing process like metals,
glass, cement, ceramics,
semiconductors, plastics, paper,
textiles, coatings.

• Automation and feedback control

• Improve safety in fire-fighting,


rescues and detection of criminal
activities.

• Used to monitor and measure


human body temperatures with one
second time response.
Infrared Sensors
Advantages Disadvantages
• No contact with the • High initial cost
product required • More complex - support
• Response times as fast electronics required
or faster than • Measuring accuracy
thermocouples affected by dust, smoke,
• No corrosion or oxidation background radiation, etc.
to affect sensor accuracy
• Good stability over time
• High repeatability
Semiconductors
• Are small and result from the fact that
semiconductor diodes have voltage-
current characteristics that are
temperature sensitive.
• Temperature measurement ranges that
are small compared to thermocouples and
RTDs, but can be quite accurate and
inexpensive.
Semiconductor Applications
• Hard Disk Drives
• Personal Computers
• Electronic Test Equipment
• Office Equipment
• Domestic Appliances
• Process Control
• Cellular Phones
Determining Factors
➢ Low Power Extras
➢ Serial Interface ➢ I2C Interface
➢ Small ➢ Temperature Alarms
➢ Accurate
➢ Wide temperature
range
Texas Instrument Specs
TMP 100/101
➢ I2C Interface
➢ -55º to 125ºC range
➢ ±1º accuracy (±3º max)
➢ ±0.0625ºC resolution
➢ 2.7 to 5.5 operating voltage
➢ 45 to 75 µA operating current,
0.1 to 1µA shutdown current
➢ 40ms/320ms conversion
rate(9/12 bit)
➢ 25/3 conversions per second
(9/12 bit)
➢ Online sample request
➢ 6 pin SO23 package
➢ Needs 400kHz clock for I2C
Interface
Maxim
MAX6625/MAX6626
➢ I2C Interface
➢ -55º to 125ºC range
➢ ±1º accuracy (±2º max)
➢ ±5/0.0625ºC
resolution(625/626)
➢ 3.0 to 5.5 operating voltage
➢ 250µA to 1mA operating
current, 1µA shutdown current
➢ 133ms conversion rate
➢ Online sample request
➢ 6 pin SO23 package
National Semiconductor
LM75/LM76
➢ I2C Interface
➢ -55º to 125ºC range
➢ ±2/ ±1º accuracy
➢ 9 bits/ 12 bits or ±0.0625ºC
resolution
➢ 3/3.3 to 5.5 operating voltage
➢ 0.25 to 0.5 µA operating current,
4/5µA shutdown current
➢ 100ms/400ms conversion
rate(9/12 bit)
➢ Online sample request
➢ 8 pin SOP package
➢ Needs 400kHz clock for I2C
Interface
Personal Recommendation
• Texas Instrument TMP100/101
– Small package
– Can operate on lower voltage
– Low power consumption
– Accurate
Sensor and Actuator
DHTxx Sensors
• Temperature-humidity sensor
• Small size
• Low consumption
• DHT11 or DHT22 is a good entry-level choice
• Library can be downloaded and incorporated to give
easy access to features of the sensor
Kinds of Temp/ Humidity Sensor
Kinds of Temp/ Humidity Sensor
DHT11 vs DHT22
DHT11
• Ultra low cost
• 3 to 5V power and I/O
• 2.5mA max current use during conversion (while
requesting data)
• Good for 20-80% humidity readings with 5% accuracy
• Good for 0-50°C temperature readings ±2°C accuracy
• No more than 1 Hz sampling rate (once every second)
• Body size 15.5mm x 12mm x 5.5mm
• 4 pins with 0.1" spacing
DHT11 vs DHT22
DHT22
• Low cost
• 3 to 5V power and I/O
• 2.5mA max current use during conversion (while
requesting data)
• Good for 0-100% humidity readings with 2-5% accuracy
• Good for -40 to 125°C temperature readings ±0.5°C
accuracy
• No more than 0.5 Hz sampling rate (once every 2
seconds)
• Body size 15.1mm x 25mm x 7.7mm
• 4 pins with 0.1" spacing
What is the best
• The DHT22 measures:
– Relative Humidity from 0% to 100% with ±2%
accuracy
– Temperatures from -45°C to 125°C with ±0.2°C
accuracy Wiring it up is very easy!

• As you can see, the DHT22 is a little more


accurate and good over a slightly larger range.
• Both use a single digital pin.
• Code written for the DHT11 is compatible with
the DHT22
Wiring it up is very easy!
• Both are wired the
same:
• V+ is wired to +
• GND is wired to gnd
• Data goes to pin
number X (Digital
pin) on the Arduino
The resister should go
between VCC and SIG
Wiring it up is very easy!
Writing program
• Install this https://github.com/ringerc/Arduino-DHT22
#include <dht.h>
dht DHT;

#define DHT11_PIN 7

void setup(){
Serial.begin(9600);
}

void loop()
{
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
delay(1000);
}
DHT 11 Sensor
1. Connect the sensor with Arduino board like picture below.
2. Download DHT11 Sensor library from
http://www.hardcopyworld.com/ngine/aduino/?wpdmdl=2388
3. Add library to Arduino IDE
DHT 11 Sensor
1. Configure serial port
2. Open Serial monitor tool
3. Copy the source from
http://www.hardcopyworld.com/ngine/aduino/index.php/archives/190
4. Compile and Upload
Temperature Sensor - TMP36
• low power
temperature
sensor outputs an
analog voltage that
is proportional to
the ambient
temperature.
(TMP35/TMP36/TMP37)
Wiring it up is very easy!
To use, connect:
• pin 1 (left) to
power (between
2.7 and 5.5V).
• pin 3 (right) to
ground.
• pin 2 to analog in
on your
microcontroller.
Temperature Sensor Circuit
Schematic
• This will be the raw value (between 0 and 1023)
divided by 205. It is divided by 205 because a
span of 1024 values occupies 5V, or 1024/5=
205 per volt.
• Once this the analog voltage is calculated, we
can find the degrees in celsius by the equation:
celiustemp= 100.0 * volts -50
• We then can find the temperature in fahrenheit
by the equation: fahrenheittemp= celiustemp *
9.0/5.0 + 32.0
Code for Temperature Sensor
Circuit
• //initializes/defines the output pin of the TMP36 temperature sensor
int outputpin= 0;
//this sets the ground pin to LOW and the input voltage pin to high
void setup()
{
Serial.begin(9600);
}

//main loop
void loop()
{
int rawvoltage= analogRead(outputpin);
float volts= rawvoltage/205.0;
float celsiustemp= 100.0 * volts - 50;
float fahrenheittemp= celsiustemp * 9.0/5.0 + 32.0;
Serial.print(celsiustemp);
Serial.println(" Celsius");
Serial.print(fahrenheittemp);
Serial.println(" Fahrenheit");
delay(300000);
}
Arduino and monochrome
LCDs
• Fixed-character LCD modules
• Graphic LCD modules
Fixed-character LCD modules
• Their size is normally measured by the number
of columns and rows of characters in the display.
• For example, the three LCDs below are 8×2,
16×2 and 20×4 characters in size:
Fixed-character LCD modules
• Most LCDs should
have a backlight of
some sort, however
you may come
across some
heavily-discounted
models on (for
example) eBay that
are not.
Interfacing these screens with
our Arduino boards
• very easy, and there are several ways to
do so. These interface types can include
• four- and eight-bit parallel.
• Three-wire, serial, I2C and SPI interfaces;
• The LCD price is usually inversely
proportional to the ease of interface
Four-bit parallel interface
There are sixteen pins on the LCD. These are usually in one row:

… or two rows of eight:


Four-bit parallel interface
The pin labels for our example are the following:
1. GND
2. 5V (careful! Some LCDs use 3.3 volts – adjust according to LCD data sheet from
supplier)
3. Contrast
4.RS
5.RW
6.Enable
7.DB0 (pins DB0~DB7 are the data lines)
8.DB1
9.DB2
10.DB3
11.DB4
12.DB5
13.DB6
14.DB7
15.backlight + (unused on non-backlit LCDs) – again, check your LCD data sheet as
backlight voltages can vary.
16.backlight GND (unused on non-backlit LCDs)
As always, check your LCD’s data sheet before wiring it up.
Some LCDs may also have the pinout details on their PCB if you are lucky, however
it can be hard to decipher:
Circuit layout created using
Fritzing
Writing program
• From a software perspective, we need to use the
LiquidCrystal() library. This library should be pre-
installed with the Arduino IDE.
• Add the following line:
#include "LiquidCrystal.h"
• Create a variable for our LCD module, and tell the sketch
which pins are connected to which digital output pins
LiquidCrystal lcd(4,5,6,7,8,9);
• The parameters in the brackets define which digital
output pins connect to (in order) LCD pins: RS, enable,
D4, D5, D6, and D7.
In your void setup(), add the line:
lcd.begin(16,2);

void loop(){

lcd.setCursor( 5 , 1);

lcd.print(“MAMA”);

lcd.cursor();

}// close loop


#include "LiquidCrystal.h"
LiquidCrystal lcd(4,5,6,7,8,9);

void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}

void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting
begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis() / 1000);
}
Three-wire LCD interface
• If you cannot spare many
digital output pins on your
Arduino, only need basic
text display and don’t
want to pay for a serial or
I2C LCD, this could be an
option for you. A 4094
shift register IC allows
use of the example
HD44780 LCD with only
three digital output pins
from your Arduino. The
hardware is connected as
such:
• use the ShiftLCD library, which you can
download from here:
• www.miselph.co.uk/arduino/ShiftLCD.zip
• Then, in the start of your sketch, add the
following line:
#include<ShiftLCD.h>
• tell the sketch which of the 4094’s pins are
conected to which digital output pins:
ShiftLCD lcd(2,3,4);
#include<ShiftLCD.h>
ShiftLCD lcd(2,3,4);
int data;
void setup()
{
lcd.begin(16,2);
lcd.print("Hello Word");
delay(3000);
}

void loop()
{
lcd.clear();
lcd.print(millis()/1000);
lcd.setCursor(1,1);
lcd.print("Miarana");
}
Graphic LCD modules
• Fortunately there are many graphic LCD
modules on the market.
• A parallel data interface and one and a
serial data interface.
Parallel interface
• Our example in this case is a 128 by 64
pixel unit with a KS0108B parallel
interface:
• By now you should be able to install a
library, so download this KS0108 library
and install it as usual
http://www.arduino.cc/playground/uploads/C
ode/ks0108GLCD.zip
Arduino Uno/Duemilanove sockets:
1. 5V
2.GND
3.centre pin of 10k ohm potentiometer
4.D8
5.D9
6.D10
7.D11
8.D4
9.D5
10.D6
11.D7
12.A0
13.A1
14.RST
15.A2
16.A3
17.A4
18.outer leg of potentiometer; connect
other leg to GND
19.5V
20.GND
• there are several functions that need to be
called in order to activate our LCD. The
first of these being:
GLCD.Init(NON_INVERTED);
#include <ks0108.h> // library header GLCD.ClearScreen(); // clear the LCD
int xc, yc = 0; for (int a=0; a<64; a++)
int d=1000; // for delay use {
GLCD.DrawHoriLine(0, a, 127, BLACK);
void setup()
{ // draws a horizontal line from xy position 0, a of length 127
GLCD.Init(NON_INVERTED); // initialise the library with pixel default as off delay(d-950);
GLCD.ClearScreen(); // clear the LCD }
randomSeed(analogRead(5)); for (int a=0; a<64; a++)
}
{
void loop() GLCD.DrawHoriLine(0, a, 127, WHITE);
{ delay(d-950);
GLCD.DrawRect(0, 0, 127, 63, BLACK); }
// draw an open rectangle that spans the extremties of the LCD GLCD.ClearScreen(); // clear the LCD
GLCD.DrawRect(10, 10, 117, 53, BLACK);
GLCD.DrawRoundRect(30, 30, 20,20, 5,BLACK);
GLCD.DrawRect(20, 20, 107, 43, BLACK);
GLCD.DrawRect(30, 30, 97, 33, BLACK); // draw a rectangle with rounded edges: x, y, width, height,
delay(d); radius of rounded edge, colour
GLCD.ClearScreen(); // clear the LCD GLCD.DrawRoundRect(60, 30, 20,20, 5,BLACK);
for (int a=1; a<20; a++) delay(d);
{
GLCD.ClearScreen(); // clear the LCD
GLCD.DrawCircle(63,31,a,BLACK);
// draws a circle with centre at 61,31; radius of a, with black pixels delay(d);
delay(d-800); GLCD.FillRect(30, 30, 30, 10, BLACK);
GLCD.DrawCircle(63,31,a,WHITE); // draws the same circle with the pixels // draws a filled rectangle: x, y, width, height, colour
off delay(d);
}
GLCD.ClearScreen(); // clear the LCD
delay(d);
GLCD.ClearScreen(); // clear the LCD for (int a=0; a<1000; a++)
for (int a=0; a<128; a++) {
{ xc=random(0,127);
GLCD.DrawVertLine(a, 0, 63, BLACK); yc=random(0, 63);
// draws a vertical line from xy position a, 0 of length 63
GLCD.SetDot(xc, yc, BLACK);
delay(d-950);
} // turn on a pixel at xc, yc);
delay(d-800); delay(2);
for (int a=0; a<128; a++) }
{ GLCD.ClearScreen();
GLCD.DrawVertLine(a, 0, 63, WHITE);
// clear the LCD
delay(d-950);
} }
• Sensor
• Pressure Sensor
• Pressure Sensor Types
• Force Sensor
• Force sensor applications
• Force sensor characteristics
• How does it work
• Sensor Testing
• Connection with Arduino
• Voltage Divider
• How to connect
• Arduino Code
• Sensor Operating
• Connection with Raspberry Pi 3
Sensor:
• A sensor is a device, whose purpose is to
detect events or changes in its
environment and send the information to
other electronics. A sensor is always used
with other electronics.
Pressure Sensor:
• A pressure sensor is a
device for pressure
measurement.
• Pressure is usually stated in
terms of force per unit area.
• A pressure sensor usually
acts as a transducer.
• It generates a signal as a
function of the pressure
imposed.
Types of Pressure Sensors
• Based on the type of applications they are
used in, pressure sensors can be
categorized into many types
Types of Pressure Sensors
• 1- Strain Gauge Type: made from different
material Copper-Nickel, Chrome-Nickel and
Nickel-Iron
• When force applied on metal length and
diameter will change but remove this force
its take his original position. It has four arms
which connect like wheat stone bridge.
• Wheatstone bridge condition
P/Q = R/S where p q r s is resistance
Voltage E = 0 ( in balance condition)
when force applied on diaphragm BF350-3AA Strain Gauge Modul
unbalance create and resistance change so
out put terminal get o/p volatile . which is
strain force, ( this voltage is directly
proportional to applied force ) . so voltmeter
shows reading of applied force
Types of Pressure Sensors
• Capacitive Pressure Sensor: A capacitor has
two metal plates and a dielectric sandwiched
between them. In capacitive pressure sensor,
one of these metal plates is permitted to move
in and out so that the capacitance between
them changes due to varying distance between
the plates. The movable plate is connected to a
diaphragm which senses the pressure and then
expands or compresses accordingly. The
movement of the diaphragm would affect the
attached metal plate’s position and capacitance
would vary.
• These sensors, though much ineffective at high
temperatures, are widely used at ambient
temperature range due to their linear output.
Types of Pressure Sensors
• Piezoelectric Pressure Sensor:
Piezoelectric crystals develop a potential
difference (i.e. voltage is induced across the
surfaces) whenever they are subjected to
any mechanical pressure. These sensors
have the crystal mounted on a dielectric Analog Piezoelectric
base so that there is no current leakage. Ceramic Vibration Sensors
Attached to the crystal is a horizontal shaft for Arduino,
to which a diaphragm is
connected. Whenever the diaphragm
senses pressure, it pushes the shaft down
which pressurizes the crystal and voltage is
produced.
Pressure Sensor Examples
• A Barometer is used in meteorology to
measure atmospheric pressure and
forecast short term changes in the
weather. Because atmospheric pressure
also varies with elevation,
a barometer can also be used as a basic
altimeter.
Pressure Sensor Examples
• Tire Pressure Monitoring Sensor is to
warn you that at least one or more tires
are significantly under-inflated, possibly
creating unsafe driving conditions.
Pressure Sensor Examples
• Water flow sensor consists of a plastic
valve body, a water rotor, and a hall-
effect sensor. When water flows through
the rotor, rotor rolls. Its speed changes
with different rate of flow. The hall-
effect sensor outputs the corresponding
pulse Signal.
Pressure Sensor Examples
• Force Sensor: A force-sensing resistor
is a material whose resistance changes
when a force, pressure or mechanical
stress is applied. They are also known as
"force-sensitive resistor" and are
sometimes referred to by the initialism
"FSR".
Force Sensor:
• Force Sensing Resistors, or FSRs, are robust
polymer thick film (PTF) devices that exhibit a
decrease in resistance with increase in force
applied to the surface of the sensor. This force
sensitivity is optimized for use in human touch
control of electronic devices such as automotive
electronics, medical systems, and in industrial and
robotics applications.
• The standard 402 sensor is a round sensor 18.28
mm in diameter. Custom sensors can be
manufactured in sizes ranging from 5mm to over
600mm.
Force sensor applications:
• Electronic Scale a balance that
generates a current proportional to the
displacement of the pan. Type
of: balance. A scale for weighing;
depends on pull of gravity.
Force sensor applications:
• An Elevator or Lift is a type of vertical
transportation that moves people or goods
between floors (levels, decks) of a
building, vessel, or other structure.
Force sensor characteristics:
• Model: FSR model 402
• Size: Diameter of 12.5mm and buffer area
of 0.02mm
• sensitivity: Infinite (Superior)
• Electricity: Less than 1mA of electrical
current.
How does it work ?
• The force sensors are majorly electronic
equipment whose underlying material can
be a force-sensing resistor. Generally,
the working principle of force sensors is
that they respond to the applied load and
weight and then transforms them into a
quantifiable output.
Sensor Testing:
• The easiest way to test the sensor is to
measure it’s resistance using ohmmeter.
• Connect the ohmmeter on the edge of the
sensor and press the sensor to see how
the pressure changes the resistance value
on the ohmmeter.
Sensor Testing:
Connection with Arduino:
• Connection Elements

Arduino
Wires FSR 402
sensor

Resistor Breadboard
Before we start:
• The force sensor is a variable resistance. The
value of this resistance varies depending on the
degree of pressure on it. It is an analogue sensor
analog which enables us to know the amount of
pressure generated on an area unit.
• So that we can read the values of this change
through the analogue outlets must be the change
inside the analogue outlets is a variable volt and
not resistance, and so we can read this type of
sensors must use a technique called voltage
divider.
Voltage Divider:
• A voltage divider is a simple circuit that
converts the high voltage to a lower
voltage.
• If we assumed that we had a Vcc voltage
source and we had two resistors R1, R2
the two resistors were connected
respectively as in the following picture:
Voltage Divider:
Voltage Divider:
• The amount of voltage on R2 resistance is
given by law:

• The voltage on R1 is equal to:


How to connect ?
How to connect ?
• The 5v and A0 are connected directly to
the sensor each and GND and A0 are
connected with the impedance between
them as shown in the picture.
• 5v, A0: are connected with the sensor.
• GND: Is connected to A0 with a resister
connected between them.
Arduino Code:
Connection with Raspberry Pi 3:
• Connection Elements

Wires Raspberry Pi 3
FSR 402
sensor

MCP 3008 Resistor Breadboard


How to connect ?
How to connect ?
• a Pi Cobbler that will let you attach the Pi to a breadboard
with a ribbon cable
• a breadboard so you can plug everything in
• a force sensitive resistor
• a MCP3008 analog to digital converter to convert the
analog signals from the FSR to digital signals that the
Raspberry Pi can read, You can get a different ADC, but
then these instructions will need some interpretation.
• some wires to make connections on the breadboard
• a 10k Ohm resistor
• Code here : https://learn.adafruit.com/reading-a-analog-
in-and-controlling-audio-volume-with-the-raspberry-
pi/script
Optical Sensors and Optical
Fibers

Jaber Al Yamani
Optical Sensors and Optical
Fibers
• An optical sensor is a device that converts
light rays into electronic signals. Similar to a
photo resistor, it measures the physical
quantity of light and translates it into a form
read by the instrument.
• One of the features of an optical sensor is its
ability to measure the changes from one or
more light beams. This change is most often
based around alterations to the intensity of
the light.
Optical Sensors and Optical
Fibers
• The fiber optic sensors also called as
optical fiber sensors use optical fiber or
sensing element.
• These sensors are used to sense some
quantities like temperature, pressure,
vibrations, displacements, rotations or
concentration of chemical species.
• Fibers have so many uses in the field of
remote sensing because they require no
electrical power at the remote location and
Optical Fibers Basics

• An optical fiber is
composed of three
parts; the core, the
cladding, and the
coating or buffer.
• Optical fibers are
divided into two
groups called single
mode and multimode
Single mode Optical Fiber
• This type of optical
fiber transmits only
one mode of light.
• Single mode type of
optical fibers is much
better than multimode
optical fibers as they
have more
bandwidth and
experience fewer
losses.
• Used in applications
requiring longer
distance connections.

Multimode Optical Fibers
These types of
optical fibers allow
multiple modes of
light to travel along
their axis with thicker
core diameter.
• The reflection of the
waves inside the
multimode fiber
occurs at different
angles for every
mode.
• There are two types
of multimode optical
fibers: stepped index
and graded index.
Fiber Optic Sensor Principles

• The general structure


of an optical fiber
sensor system is
shown in Figure .
• It consists of an optical
source (Laser, LED,
Laser diode etc),
optical fiber, sensing
or modulator element
Fiber Optic Sensor Principles
• Intensity-based fiber optic sensors rely on signal
undergoing some loss
• The intensity-based sensor requires more light and
therefore usually uses multimode large core fibers
• The advantages of these sensors are: Simplicity of
implementation, low cost, possibility of being
multiplexed, and ability to perform as real distributed
sensors.
• The drawbacks are: Relative measurements and
variations in the intensity of the light source may lead
to false readings, unless a referencing system is used
Fiber Optic Sensor
Classification
• Fiber optic sensors can be classified under
three categories: The sensing location, the
operating principle, and the application.
• Based on the sensing location, a fiber optic
sensor can be classified as extrinsic or
intrinsic.
• In an extrinsic fiber optic sensor (see Figure
), the fiber is simply used to carry light to and
from an external optical device where the
sensing takes place. In this cases, the fiber
just acts as a means of getting the light to
the sensing location.
Fiber Optic Sensor classification
• Based on the application, a fiber optic
sensor can be classified as follows:
1- Physical sensors: Used to measure
physical properties like temperature, stress,
etc.
2- Chemical sensors: Used for pH
measurement, gas analysis, spectroscopic
studies, etc.
3- Bio-medical sensors: Used in bio-medical
applications like measurement of blood flow,
Fiber Optic Sensor classification
• Based on the operating principle or
modulation and demodulation process, a
fiber optic sensor can be classified as an
intensity, a phase, a frequency, or a
polarization sensor. All these parameters
may be subject to change due to external
perturbations. Thus, by detecting these
parameters and their changes, the
external perturbations can be sensed.
Types of Optical
Sensors
There are different kinds of
optical sensors, the most
common types which we have
been using in our real world
applications as given below:
• Photoconductive devices
used to measure the
resistance by converting a
change of incident light into
a change of resistance.
• The Photodiodes convert an Photoconductive
amount of incident light into
an output current
Types of Optical Sensors
• The photovoltaic cell (solar cell) converts
an amount of incident light into an output
voltage.
List of Optical
sensors
• Avoid (KY-032)
• Flame (FLAME1)
• Tracking (KY-033)
• Photoresistor
• This Infrared Obstacle • Working voltage: DC
KY-032 Avoidance Sensor returns
a signal when it detects •
3.3V-5V
Working current: ≥
an object in range
(Obstacle • The range of the sensor •
20mA
Operating temperature:
is around 2-40 cm is -10 ℃ - +50 ℃
Avoidance •
distance
It operates at 3.5 to 5
• detection distance :2-
40cm
volts at around 20
sensor) milliamps.
• Infrared obstacle
avoidance sensor is
designed to detect
obstacles or the
difference in reflective
services.
This Flame Sensor can be used to detect
fire source or other light sources of the
wave length in the range of 760nm - 1100
nm. It is based on the YG1006 sensor
Infrared which is a high speed and high sensitive
NPN silicon phototransistor. Due to its
Flame • black epoxy,
High Photo the sensor is sensitive to
Sensitivity
• Fast Response Time In fire fighting robot
Sensor •
infrared radiation.
Sensitivity
game, theadjustable
sensor plays a very important
Module • Can detect flame
role, it can be used or wavelength of eyes to find
as a robot
light source within 760nm~1100nm

the fire source.
Lighter flame detect distance 80cm
• Greater the flame, farther the test
distance
• Detect angle: 60 degree, very
sensitive with flame spectrum
• The sensitivity is adjustable (the
blue digital potentiometer)
• The sensor detects if a • Working voltage: DC
KY-033 light reflecting or 3.3V-5V
absorbing area is in • Working current: ≥
(Tracking front of it. 20mA
• It shows which of the 2
Sensor) areas it is via digital
• Operating
temperature: -
output 10℃~+50℃
• The Sensitivity
(minimum range) of the • Detection distance: 2-
sensor can be 40cm
adjusted by the
controller.
Photoconductive devices

What is the sensor LDR ?


• LDR is a light-sensitive electrical resistor
that is less resistant to light intensity.
Because of this property benefit
technicians and electric circuit dwellers
use this property to perform many works,
taking advantage of theResistanc
impact of
e code
resistance to light, there are light alarms
and also a dark warning.
The internal structure of the
sensor
Size: Round, 5mm (0.2") diameter.
(Other photocells can get up to
12mm/0.4" diameter!)
Sensitivity range: CdS cells respond to
light between 400nm (violet) and
600nm (orange) wavelengths, peaking at
about 520nm (green).
Power supply: pretty much anything up
to 100V, uses less than 1mA of current
on average (depends on power supply
voltage)
The internal structure of the
sensor
• Photovoltaic resistors consist of a layer of
CdS or cadmium CdSe, which are
characterized by their sensitivity to light in
the same spectrum of human vision or
film.
• The highest sensitivity of cadmium sulfide
at 520 nm wavelength and for cadmium
selenide has the highest light sensitivity at
730 nm.
• Materials such as lead sulfhide are used to
How the sensor works

• The resistance is high and thus prevents


the flow from passing through it. When the
light falls on it, its resistance decreases to
nothing in the flow to the other side.
Examples of applications

1.Street lamps used for


automatic operation and
extinguishing
2. light switches, ie when the
light is present, the switch is
closed and when the light is
not closed
3.light sensing circuits (light
intensity measurement)
Connect to raspberry pi
Reading Analogue Sensors
using RC charging circuit

• In this circuit you place a


Resistor in series with a
Capacitor.
• When a voltage is applied
across these components
the voltage across the
capacitor rises.
(farads) The time it
t = RC where t is time, R is resistance (ohms) and C is
capacitance

takes for the voltage to


reach 63% of the
Reading Analogue Sensors
using RC charging circuit
• The time it takes the circuit to change a
GPIO input from Low to High is equal to ‘t’.
• With a 10Kohm resistor and a 1uF
capacitor t is equal to 10 milliseconds. In
the dark our LDR may have a resistance
of 1Mohm which would give a time of 1
second.
• In order to guarantee there is always
some resistance between 3.3V and the
GPIO pin I inserted a 2.2Kohm resistor in
Theory

• Here is the sequence of events :


• Set the GPIO pin as an output and set it Low. This
discharges any charge in the capacitor and ensures
that both sides of the capacitor are 0V.
• Set the GPIO pin as an input. This starts a flow of
current through the resistors and through the
capacitor to ground. The voltage across the
capacitor starts to rise. The time it takes is
proportional to the resistance of the LDR.
• Monitor the GPIO pin and read its value. Increment a
counter while we wait.
• At some point the capacitor voltage will increase
enough to be considered as a High by the GPIO pin
(approx 2v). The time taken is proportional to the
light level seen by the LDR.
• Set the GPIO pin as an output and repeat the
process as required.
Disadvantage of Reading Analogue
Sensors using RC charging circuit
• Sensors usually need an analog input port to read their value
This method is not as accurate as the ADC but it is good
enough to give 2 distinct status sensor turned on or off
Circuit Diagram
Programing
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
delayt = .2
value = 0 # this variable will be used to store the ldr value
ldr = 7 #ldr is connected with pin number 7
led = 11 #led is connected with pin number 11
GPIO.setup(led,GPIO.OUT)
GPIO.output(led, False) # keep led off by default
def rc_time (ldr):
count = 0
Programing
#Output on the pin for
GPIO.setup(ldr, GPIO.OUT)
GPIO.output(ldr, False)
time.sleep(delayt)
#Change the pin back to input
GPIO.setup(ldr, GPIO.IN)

#Count until the pin goes high


while (GPIO.input(ldr) == 0):
count += 1
return count
Programing
#Catch when script is interrupted, cleanup correctly
try:
# Main loop
while True:
print("Ldr Value:")
value = rc_time(ldr)
print(value)
if ( value >= 2000 ):
print("Lights are ON")
GPIO.output(led, True)
if (value < 2000):
print("Lights are OFF")
Programing
GPIO.output(led, False)
except KeyboardInterrupt:
pass
finally:
GPIO.cleanup()
LDR On Arduino Uno R3
• LDR
Requirements
• LED
• Resistor2400 Ohm
• Resistor 330 Ohm
• Some of Wire
Circuit Diagram
Programing
void setup() {
Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(6, OUTPUT);
}
void loop() {
Serial.println(analogRead(A0));
delay(100);
if(analogRead(A0) < 700){
digitalWrite(6, LOW);
}Else{
digitalWrite(6, HIGH);
}

You might also like