You are on page 1of 50

INDEX

S.NO NAME OF THE EXPERIMENT DATE Page Viva SIGN


NO Marks
1 Installation of Arduino software and Arduino
24-4-21
UNO board description.

2 To write an Arduino program for blinking an


1-5-21
LED.

3 To write an Arduino program for blinking an


8-5-21
LED using a switch.

4 To write an Arduino program for implementing a


15-5-21
traffic light system.

5 Detecting the object distance by using ultrasonic


22-5-21
sensor

6 Detecting the object using PIR sensor 29-5-21

7 Temperature Sensor using Arduino uno 5-6-21

8 To Write an arduino program for LDR sensor to


12-6-21
detect the light sensing.

9 To write an arduino program to detect the smoke


19-6-21
presence with the help of MQ-2 sensor.

10 To write an arduino program to implement a relay


26-6-21
module along with the buzzer.

11 Write an arduino program for sensing the room


temperature and humidity through humidity 3-7-21
sensing device and displaying on the LCD Screen.

12 Introduction to Raspberry pi 10-7-21

13 To write a Raspberry pi program to implement


17-7-21
blinking of an LED.

14 To write a raspberry pi program for detecting the


24-7-21
object distance by using ultrasonic sensor.

15 To implement the PIR sensor with Raspberry pi 26-7-21

16 To implement the LDR sensor with Raspberry pi. 28-7-21

17 Case Study 31-7-21


WEEK-1
AIM: Installation of Arduino software and Arduino UNO board description.

INSTALLATION OF ARDUINO IDE:

Get the latest version from the download page. You can choose between the Installer
(.exe) and the Zip packages. We suggest you use the first one that installs directly everything
you need to use the Arduino Software (IDE), including the drivers. With the Zip package you
need to install the drivers manually. The Zip file is also useful if you want to create
importable installation.
When the download finishes, proceed with the installation and please allow the driver
installation process when you get a warning from the operating system.

Choose the components to install


Choose the installation directory (we suggest to keep the default one)

The process will extract and install all the required files to execute properly the Arduino
Software (IDE) Proceed with board specific instructions. When the Arduino Software (IDE)
is properly installed you can go back to the Getting Started Home and choose your board
from the list on the right of the page.

ARDUINO UNO BOARD:


The Arduino Uno board is a microcontroller based on the ATmega328. It has 14
digital input/output pins in which 6 can be used as PWM outputs, a 16 MHz ceramic
resonator, an ICSP header, a USB connection, 6 analog inputs, a power jack and a reset
button.
Power USB
1. Arduino board can be powered by using the USB cable from your computer.
All you need to do is connect the USB cable to the USB connection (1).

Power (Barrel Jack)


2. Arduino boards can be powered directly from the AC mains power supply by
connecting it to the Barrel Jack (2).

Voltage Regulator
The function of the voltage regulator is to control the voltage given to the
3.
Arduino board and stabilize the DC voltages used by the processor and other
elements.

Crystal Oscillator
The crystal oscillator helps Arduino in dealing with time issues. How does
4. Arduino calculate time? The answer is, by using the crystal oscillator. The
number printed on top of the Arduino crystal is 16.000H9H. It tells us that the
frequency is 16,000,000 Hertz or 16 MHz.

Arduino Reset
You can reset your Arduino board, i.e., starts your program from the
5,17 beginning. You can reset the UNO board in two ways. First, by using the reset
button (17) on the board. Second, you can connect an external reset button to
the Arduino pin labeled RESET (5).

Pins (3.3, 5, GND, Vin)


● 3.3V (6) − Supply 3.3 output volt
● 5V (7) − Supply 5 output volt
● Most of the components used with Arduino board works fine with 3.3
6,7,8,9 volt and 5 volt.
● GND (8)(Ground) − There are several GND pins on the
Arduino, any of which can be used to ground your
circuit.
● Vin (9) − This pin also can be used to power the
Arduino board from an external power source, like
AC mains power supply.

Analog pins
The Arduino UNO board has five analog input pins A0 through A5. These
10. pins can read the signal from an analog sensor like the humidity sensor or
temperature sensor and convert it into a digital value that can be read by the
microprocessor.

Main microcontroller
Each Arduino board has its own microcontroller (11). You can assume it as
the brain of your board. The main IC (integrated circuit) on the Arduino is
slightly different from board to board. The microcontrollers are usually of the
11.
ATMEL Company. You must know what IC your board has before loading up
a new program from the Arduino IDE. This information is available on the top
of the IC. For more details about the IC construction and functions, you can
refer to the data sheet.

ICSP pin
Mostly, ICSP (12) is an AVR, a tiny programming header for the Arduino
consisting of MOSI, MISO, SCK, RESET, VCC, and GND. It is often referred
12.
to as an SPI (Serial Peripheral Interface), which could be considered as an
"expansion" of the output. Actually, you are slaving the output device to the
master of the SPI bus.

Power LED indicator


This LED should light up when you plug your Arduino into a power source to
13.
indicate that your board is powered up correctly. If this light does not turn on,
then there is something wrong with the connection.

TX and RX LEDs
On your board, you will find two labels: TX (transmit) and RX (receive).
14.
They appear in two places on the Arduino UNO board. First, at the digital pins
0 and 1, to indicate the pins responsible for serial communication. Second, the
TX and RX led (13). The TX led flashes with different speed while sending
the serial data. The speed of flashing depends on the baud rate used by the
board. RX flashes during the receiving process.

Digital I/O
The Arduino UNO board has 14 digital I/O pins (15) (of which 6 provide
PWM (Pulse Width Modulation) output. These pins can be configured to work
15.
as input digital pins to read logic values (0 or 1) or as digital output pins to
drive different modules like LEDs, relays, etc. The pins labeled “~” can be
used to generate PWM.

AREF
AREF stands for Analog Reference. It is sometimes, used to set an external
16.
reference voltage (between 0 and 5 Volts) as the upper limit for the analog
input pins.
WEEK-2

AIM: To write an Arduino program for blinking an LED.

Hardware components used: Arduino, Breadboard, LED, Resistor

Arduino: Arduino/Genuino Uno is a microcontroller board based on the ATmega328P


(datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6
analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and
a reset button.

Breadboard: A breadboard, or protoboard, is a construction base for prototyping of


electronics.

LED:A light-emitting diode is a semiconductor light source that emits light when current
flows through it. Electrons in the semiconductor recombine with electron holes, releasing
energy in the form of photons.

Resistor: A resistor is a passive two-terminal electrical component that implements electrical


resistance as a circuit element. In electronic circuits, resistors are used to reduce current flow,
adjust signal levels, to divide voltages, bias active elements, and terminate transmission lines,
among other uses.

Circuit:

Code:
void setup()
{
pinMode(13, OUTPUT);
}

void loop()
{
digitalWrite(13, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(13, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}

Output:
WEEK-3

AIM: To write an Arduino program for blinking an LED using a switch.

Hardware components used: Arduino, Breadboard, LED, Resistor, Pushbutton.

Arduino: Arduino/Genuino Uno is a microcontroller board based on the ATmega328P


(datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6
analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and
a reset button.

Breadboard: A breadboard, or protoboard, is a construction base for prototyping of


electronics.

LED:A light-emitting diode is a semiconductor light source that emits light when current
flows through it. Electrons in the semiconductor recombine with electron holes, releasing
energy in the form of photons.

Resistor: A resistor is a passive two-terminal electrical component that implements electrical


resistance as a circuit element. In electronic circuits, resistors are used to reduce current flow,
adjust signal levels, to divide voltages, bias active elements, and terminate transmission lines,
among other uses.

Push buttons can be explained as simple power controlling switches of a machine or


appliance. These are generally metal or thermoplastic switches that are intended to grant easy
access to the user.

Circuit:
Code:

void setup()
{
pinMode(2, INPUT);
pinMode(13, OUTPUT);
}

void loop()
{
if (digitalRead(2) == HIGH) {
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}

OUTPUT:
WEEK-4

AIM: To write an Arduino program for blinking Traffic LED.

Hardware components used:Arduino, Breadboard, LED, Resistor

Arduino: Arduino/Genuino Uno is a microcontroller board based on the ATmega328P


(datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6
analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and
a reset button.

Breadboard: A breadboard, or protoboard, is a construction base for prototyping of


electronics.

LED:A light-emitting diode is a semiconductor light source that emits light when current
flows through it. Electrons in the semiconductor recombine with electron holes, releasing
energy in the form of photons.

Resistor: A resistor is a passive two-terminal electrical component that implements electrical


resistance as a circuit element. In electronic circuits, resistors are used to reduce current flow,
adjust signal levels, to divide voltages, bias active elements, and terminate transmission lines,
among other uses.

Circuit:

Code:
void setup()
{
pinMode(4, OUTPUT); //green led
pinMode(3, OUTPUT); //orange led
pinMode(2, OUTPUT); //red led

void loop()
{
digitalWrite(4, HIGH); //turn on green led
delay(3000); // Wait for 3000 millisecond(s)
digitalWrite(4, LOW); //turn of green led

digitalWrite(3, HIGH); //turn on orange led


delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(3, LOW); //turn of orange led

digitalWrite(2, HIGH); //turn on red led


delay(3000); // Wait for 3000 millisecond(s)
digitalWrite(2, LOW); //turn of red led

OUTPUT:
WEEK-5
AIM: Detecting the object distance by using ultrasonic sensor

Hardware components used:Arduino, Breadboard, Ultrasonic distance sensor

Arduino: Arduino/Genuino Uno is a microcontroller board based on the ATmega328P


(datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6
analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and
a reset button.

Breadboard: A breadboard, or protoboard, is a construction base for prototyping of


electronics.

Ultrasonic sensors: can measure the distance to a wide range of objects regardless of shape,
color or surface texture. They are also able to measure an approaching or receding object.

Circuit:

Code:
const int trigPin = 9;
const int echoPin = 10;

float duration, distance;

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);


distance = (duration*.0343)/2;
Serial.print("Distance: ");
Serial.println(distance);
delay(100);
}

Output:
WEEK-6

AIM: Detecting the object using PIR sensor

Hardware components used: Arduino, LED, PIR Sensor

PIR Sensor:PIR sensors allow you to sense motion, almost always used to detect whether a
human has moved in or out of the sensor's range.

LED:A light-emitting diode is a semiconductor light source that emits light when current
flows through it. Electrons in the semiconductor recombine with electron holes, releasing
energy in the form of photons.

Arduino: Arduino/Genuino Uno is a microcontroller board based on the ATmega328P


(datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6
analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and
a reset button.

Circuit:
Code:
int sensorState = 0;

void setup()
{
pinMode(2, INPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);

}
void loop()
{
// read the state of the sensor/digital input
sensorState = digitalRead(2);
// check if sensor pin is HIGH. if it is, set the
// LED on.
if (sensorState == HIGH) {
digitalWrite(13, HIGH);
Serial.println("Sensor activated!");
} else {
digitalWrite(13, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}

Output:
WEEK-7

AIM: Temperature Sensor using Arduino uno

Hardware components used: Arduino, Temperature Sensor.

Temperature Sensor: A temperature sensor is an electronic device that measures the


temperature of its environment and converts the input data into electronic data to record,
monitor, or signal temperature changes.

Arduino: Arduino/Genuino Uno is a microcontroller board based on the ATmega328P


(datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6
analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and
a reset button.

Circuit:

Code:

void setup()
{
Serial.begin(9600);
pinMode(A0, OUTPUT);
}

void loop()
{
int temp=analogRead(A0);
temp=temp*0.48828125;
Serial.println("Temparature is: "+temp);
delay(1000);
}
WEEK-8
AIM: To Write an arduino program for LDR sensor to detect the light sensing.

Hardware components used:Arduino, Breadboard, Resistor, LDR sensor

Arduino: Arduino/Genuino Uno is a microcontroller board based on the ATmega328P


(datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6
analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and
a reset button.

Breadboard: A breadboard, or protoboard, is a construction base for prototyping of


electronics.

Resistor: A resistor is a passive two-terminal electrical component that implements electrical


resistance as a circuit element. In electronic circuits, resistors are used to reduce current flow,
adjust signal levels, to divide voltages, bias active elements, and terminate transmission lines,
among other uses.

LDR sensor: Photoresistors, also known as light dependent resistors (LDR), are light
sensitive devices most often used to indicate the presence or absence of light, or to measure
the light intensity.

Circuit:

Code:
int light;
void setup()
{
Serial.begin(9600);
}
void loop()
{
light=analogRead(A0);
Serial.println(light);
delay(1000);
}

Output:
WEEK-9
AIM: To write an arduino program to detect the smoke presence with the help of MQ-2
sensor.

Hardware components :Arduino, Resistor, LDR sensor

Arduino: Arduino/Genuino Uno is a microcontroller board based on the ATmega328P


(datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6
analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and
a reset button.

Resistor: A resistor is a passive two-terminal electrical component that implements electrical


resistance as a circuit element. In electronic circuits, resistors are used to reduce current flow,
adjust signal levels, to divide voltages, bias active elements, and terminate transmission lines,
among other uses.

Gas Sensor: MQ2 Gas sensor works on 5V DC and draws around 800mW. It can detect
LPG, Smoke, Alcohol, Propane, Hydrogen, Methane and Carbon Monoxide concentrations
anywhere from 200 to 10000ppm.

Circuit:
Code:
void setup()
{
Serial.begin(9600);
}

void loop()
{
int a=analogRead(A0);
int b=map(a,0,1025,0,255);
Serial.println(b);
if(b>80)
{
Serial.println("Smoke Detected");
}
else
{
Serial.println("Smoke Not Detected");
}
}

Output:
WEEK-10
AIM: To write an arduino program to implement a relay module along with the buzzer.

Hardware components used:Arduino, Breadboard, Resistor,

Arduino: Arduino/Genuino Uno is a microcontroller board based on the ATmega328P


(datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6
analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and
a reset button.

Breadboard: A breadboard, or protoboard, is a construction base for prototyping of


electronics.

Resistor: A resistor is a passive two-terminal electrical component that implements electrical


resistance as a circuit element. In electronic circuits, resistors are used to reduce current flow,
adjust signal levels, to divide voltages, bias active elements, and terminate transmission lines,
among other uses.

Buzzer: The buzzer consists of an outside case with two pins to attach it to power and
ground. ... When current is applied to the buzzer it causes the ceramic disk to contract or
expand. Changing the This then causes the surrounding disc to vibrate. That's the sound that
you hear.

Circuit:

Code:
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
tone(13, 200, 100);
delay(200);

Output:
WEEK-11
AIM: Write an arduino program for sensing the room temperature and humidity through
humidity sensing device and displaying on the LCD Screen.

Hardware components used:Arduino, Breadboard, Resistor, Temperature sensor,


Potentiometer

Arduino: Arduino/Genuino Uno is a microcontroller board based on the ATmega328P


(datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6
analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and
a reset button.

Breadboard: A breadboard, or protoboard, is a construction base for prototyping of


electronics.

Resistor: A resistor is a passive two-terminal electrical component that implements electrical


resistance as a circuit element. In electronic circuits, resistors are used to reduce current flow,
adjust signal levels, to divide voltages, bias active elements, and terminate transmission lines,
among other uses.

Temperature Sensor: A temperature sensor is an electronic device that measures the


temperature of its environment and converts the input data into electronic data to record,
monitor, or signal temperature changes.

Potentiometer: A potentiometer is a three-terminal resistor with a sliding or rotating contact


that forms an adjustable voltage divider. If only two terminals are used, one end and the
wiper, it acts as a variable resistor or rheostat.

Circuit:
Code:
#include<LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#define pinTemp A0
void setup(){
Serial.begin( 9600 );
pinMode( pinTemp,INPUT );

lcd.begin(16, 2);
lcd.print("Temperature:");
}

void loop() {
float temp = ((analogRead(pinTemp) * (5.0/1024))-0.5 )/0.01;
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print( temp );

Serial.println( temp );
delay( 1000 );
}
Output:
WEEK-12
AIM: Introduction to Raspberry pi.

DESCRIPTION:

Raspberry Pi is a small single board computer. By connecting peripherals like Keyboard,


mouse, display to the Raspberry Pi, it will act as a mini personal computer.
Raspberry Pi is popularly used for real time Image/Video processing, IoT based applications
and Robotics applications.
Raspberry Pi is slower than laptop or desktop but is still a computer which can provide all the
expected features or abilities, at a low power consumption.
Raspberry Pi Foundation officially provides Debian based Raspbian OS. Also, they provide
NOOBS OS for Raspberry Pi. We can install several Third-Party versions of OS like Ubuntu,
Archlinux, RISC OS, Windows 10 IOT Core, etc.
Raspbian OS is official Operating System available for free to use. This OS is efficiently
optimized to use with Raspberry Pi. Raspbian have GUI which includes tools for Browsing,
Python programming, office, games, etc.
We should use SD card (minimum 8 GB recommended) to store the OS (operating System).
Raspberry Pi is more than computer as it provides access to the on-chip hardware i.e. GPIOs
for developing an application. By accessing GPIO, we can connect devices like LED, motors,
sensors, etc and can control them too.
It has ARM based Broadcom Processor SoC along with on-chip GPU (Graphics Processing
Unit).
The CPU speed of Raspberry Pi varies from 700 MHz to 1.2 GHz. Also, it has on-board
SDRAM that ranges from 256 MB to 1 GB.
Raspberry Pi also provides on-chip SPI, I2C, I2S and UART modules.
There are different versions of raspberry pi available as listed below:

1. Raspberry Pi 1 Model A
2. Raspberry Pi 1 Model A+
3. Raspberry Pi 1 Model B
4. Raspberry Pi 1 Model B+
5. Raspberry Pi 2 Model B
6. Raspberry Pi 3 Model B
7. Raspberry Pi Zero

The On-chip hardware of Raspberry Pi 3 (here) is as shown in below figure,


Raspberry Pi 3 Model B Hardware
Some Hardware Components shown above are mention below:

1. HDMI (High-Definition Multimedia Interface): It is used for transmitting


uncompressed video or digital audio data to the Computer Monitor, Digital TV, etc.
Generally, this HDMI port helps to connect Raspberry Pi to the Digital television.
2. CSI Camera Interface: CSI (Camera Serial Interface) interface provides a
connection in between Broadcom Processor and Pi camera. This interface provides
electrical connections between two devices.
3. DSI Display Interface: DSI (Display Serial Interface) Display Interface is used for
connecting LCD to the Raspberry Pi using 15-pin ribbon cable. DSI provides fast
High-resolution display interface specifically used for sending video data directly
from GPU to the LCD display.
4. Composite Video and Audio Output: The composite Video and Audio output port
carries video along with audio signal to the Audio/Video systems.
5. Power LED: It is a RED colored LED which is used for Power indication. This LED
will turn ON when Power is connected to the Raspberry Pi. It is connected to 5V
directly and will start blinking whenever the supply voltage drops below 4.63V.
6. ACT PWR: ACT PWR is Green LED which shows the SD card activity.
WEEK-13
AIM: To write a raspberry pi program to implement blinking of an led.

DESCRIPTION:

A simple LED circuit consists of a LED and resistor. The resistor is used to limit the current
that is being drawn and is called a current limiting resistor. Without the resistor the LED
would run at too high of a voltage, resulting in too much current being drawn which in turn
would instantly burn the LED, and likely also the GPIO port on the Raspberry Pi.

When hooking up the circuit note the polarity of the LED. You will notice that the LED has
a long and short lead. The long lead is the positive side also called the anode, the short lead is
the negative side called the cathode. The long should be connected to the resistor and the
short lead should be connected to ground via the blue jumper wire and pin 6 on the Raspberry
Pi as shown on the diagram.

CIRCUIT DIAGRAM:
CODE:

Import RPi.GPIO as GPIO

Import time

GPIO.setmode(GPIO.BCM)

GPIO.setwarnings(False)

While True:

GPIO.setmode(18, GPIO.OUT)

print(“LED on”)

GPIO.output(18, GPIO.HIGH)

print(“LED off”)

GPIO.output(18, GPIO.LOW)

time.sleep(5)

OUTPUT:
WEEK-14
AIM: To write a raspberry pi program for detecting the object distance by using ultrasonic
sensor.

DESCRIPTION:

Raspberry Pi: is a credit-card sized single-board computer designed and manufactured by


the Raspberry Pi foundation in the United Kingdom. Raspberry Pi has an ARMv6 700 MHz
single-core processor, a VideoCore IV GPU and 512MB of RAM. it uses an SD card for its
operating system and data storage.

Ultrasonic sensors: can measure the distance to a wide range of objects regardless of shape,
color or surface texture. They are also able to measure an approaching or receding object.

CODE:

import RPi GPIO as GPIO

import time

GPIO.setmode (GPIO.BCM)

GPIO.setwarnings(False)

GPIO_TRIGGER = 18

GPIO_ECHO = 24

GPIO.setup(GPIO_TRIGGER, GPIO.OUT)

GPIO.setup(GPIO_ECHO. GPIO.IN)

def distance():

GPIO.output(GPIO_TRIGGER, True)

time.sleep(0.00005)

GPIO.output(GPIO_TRIGGER, False)

StartTime = time.time()

StopTime = time.time()

while GPIO.input(GPIO_ECHO)==0:
StartTime = time. time()

while GPIO.input(GPIO_ECHO )==1:

StopTime time. time()

TimeElapsed = StopTime - StartTime

distance = (TimeElapsed * 34300)/2

return distance

try:

while True:

dist distance()

print("Measured Distance = %.if cm" % dist)

time. sleep (1)

except KeyboardInterrupt:

print("Measurement Stopped by User")

GPIO.cleanup()
OUTPUT:
WEEK-15
AIM: To implement the PIR sensor with raspberry pi

DESCRIPTION:

PIRs are basically made of a pyroelectric sensor (which you can see below as the round metal
can with a rectangular crystal in the center), which can detect levels of infrared radiation.
Everything emits some low level radiation, and the hotter something is, the more radiation is
emitted. The sensor in a motion detector is actually split in two halves. The reason for that is
that we are looking to detect motion (change) not average IR levels. The two halves are wired
up so that they cancel each other out. If one half sees more or less IR radiation than the other,
the output will swing high or low.

A passive infrared sensor (PIR sensor) is an electronic sensor that measures infrared (IR)
light radiating from objects in its field of view. They are most often used in PIR-
based motion detectors.
When the sensor is idle, both slots detect the same amount of IR, the ambient amount radiated
from the room or walls or outdoors. When a warm body like a human or animal passes by, it
first intercepts one half of the PIR sensor, which causes a positive differential change
between the two halves.

CODE:

import RPi.GPIO as GPIO


import time
sensor = 16
GPIO.setmode (GPIO.BOARD)
GPIO.setup(sensor, GPIO.IN)
print("Ir sensor ready")
try:
while True:
if GPIO. input(sensor):
print("object detected")
while GPIO.input(sensor):
time.sleep(0.2)
else:
print("Object not detected")
except keyboardInterrupt:
GPIO.cleanup()
OUTPUT:
WEEK-16
AIM: To implement the LDR sensor with raspberry pi.

DESCRIPTION:

The light dependent resistor or also known as the LDR sensor is the most important piece of
equipment in our circuit (obviously). Without it, we wouldn’t be able to detect whether it is
dark or light. In the light, this sensor will have a resistance of only a few hundred ohms while
in the dark, it can have a resistance of several megohms
.
The capacitor in our circuit is there, so we’re able to measure the resistance of the LDR
sensor. A capacitor essentially acts like a battery charging up while receiving power and then
discharging when no longer receiving power. Using this in series with the LDR, we can work
out how much resistance the LDR is giving out thus whether it is light or dark.
To get the light sensor circuit built correctly follow the steps below or check out the circuit
diagram right underneath the steps. In the following steps, I am referring to the physical
numbers of the pins (Logical order).

CODE:

import RPi.GPIO as GPIO


import time

GPIO.setmode (GPIO.BOARD)

pc = 7
try:
while True:
count = 0
GPIO.setup(pc, GPIO.OUT)
GPIO.output(pc, GPIO.LOW)
time.sleep(0.1)
GPIO.setup(pc, GPIO.IN)
while (GPIO. input(pc)==GPIO.LOW):
count+=1
print(count)
except keyboardInterrupt:
GPIO.cleanup()
OUTPUT:
CASE STUDY
AIM: - Interface Raspberry Pi board with IR sensor to measure the presence of an object.

Description:-In this project, we will learn about Infrared Sensors, simply known as IR
Sensor and how to interface an IR Sensor with Raspberry Pi. By interfacing this IR Sensor
with Raspberry Pi, you can implement a Proximity Sensor Application (Obstacle Detection).

Overview

Infrared Sensors or IR Sensors are one of the frequently used sensor modules by electronics
hobbyists and makers. They are often used as Obstacle Detecting Sensors or Proximity
Sensors.

Brief Note on IR Sensor (IR Proximity Sensor)

IR Sensors emit and receive Infrared radiation. They are often used as Proximity Sensors i.e.
detect and alarm if an object is close to the sensor.

Let me help you understand better about IR Sensors by giving two real life applications of IR
Sensors. The first one is Mobile Phones.

Almost all mobile phones nowadays have IR Sensors in them. Usually, they will be placed
near the earpiece on the phone.

When the user make or receives a phone call, the IR Sensor detects how far the phone is from
the user’s ear. If it is close to the ear, the phone’s display will be turned off so that you do not
touch anything on the screen accidently.

Another important application is in automobiles. All modern cars are equipped with reverse
parking sensor that sense how far you can reverse your car without hitting anything. These
reverse sensors are implemented using IR Sensors.
Fig.1.1

An IR Sensor Module basically consists of three parts: an IR Transmitter, an IR Detector and


a control circuit.

Usually, an IR LED is used as an IR Transmitter and a Photo Diode or a Photo Transistor


(less often) is used as an IR Detector. The control circuit consists of a Comparator IC with
necessary components.

Based on the application and requirement, IR Sensors can be implemented in two ways. In
the first method, both the IR Transmitter and the IR Detector are placed side-by-side. In the
second setup, the IR Transmitter and the IR Detector are placed facing each other.

The first way of implementation is known as Reflective Type IR Sensor. In this setup, the IR
Transmitter continuously emits infrared light and if there is any obstacle/object in front of the
sensor, the infrared light hits the object and bounces back. The reflected signal is captured by
the IR Detector and the control circuit will reflect a Logic HIGH on its output.

The second way of implementation, where the IR Transmitter and Detector are positioned
face-t-face, is known as Transmissive Type IR Sensor. Here, the infrared light from the IR
Transmitter always falls on the Detector.

If there is an object in between the Transmitter and Detector, then there will be an obstruction
to the infrared light and the control circuit will detect this and produces appropriate output.
The IR Sensor used in this project is a Reflective Type IR Sensor. You can easily build this
type of IR Sensor as a DIY Project as the circuit is very simple.

Schematic of IR Sensor Module

The following image shows the circuit diagram of the IR Sensor Module. It consists of the
following components.

● IR LED
● Photo Diode
● 150Ω Resistor
● 10 KΩ Resistor
● 10 KΩ Potentiometer
● LM358
● LED
● 1 KΩ Resistor

Raspberry Pi IR Sensor Interface

Now that we have seen a little bit about the IR Sensor Module and its connections, we will
proceed with interfacing IR Sensor with Raspberry Pi.

The Raspberry Pi IR Sensor Interface can be converted into a Proximity Detector, where the
application will detect if the object is too close to the sensor.
Components Required

● Raspberry Pi 3 Model B
● IR Sensor
● 5V Buzzer
● Mini Breadboard
● Connecting Wires
● Power Supply
● Computer

Circuit Design

The IR Sensor Module has only three Pins: VCC, GND and Data. Connect the VCC and
GND pins of the IR Sensor to +5V and GND pins of the Raspberry Pi.

Then connect the Data pin of the IR Sensor to GPIO23 i.e. Physical Pin 16 of the Raspberry
Pi.

In order to indicate the alarm, I have used a simple 5V Buzzer. Connect one terminal of the
buzzer to GND of Raspberry Pi and the other terminal (usually marked +) to GPIO24 i.e.
Physical Pin 18 of Raspberry Pi.
Working
We have learned how to interface an IR Sensor with Raspberry Pi. I’ll now explain the
working of the project.
All the magic happens in the IR Sensor Module. As it is a Reflective type IR Sensor,
whenever an object is placed in front of the sensor, the Infrared light from the IR LED gets
reflected back after hitting the object and falls on the Photo Diode.

The photo diode then starts conducting. As a result, the voltage at the non-inverting input of
the LM358 will be greater than that at the inverting input.

Since the LM358 is acting as a Comparator, its output will become HIGH and the on-board
LED glows. The HIGH on the Data Pin is detected by the Raspberry Pi and it activates the
buzzer.

Using the 10 KΩ Potentiometer, you can adjust how far the object can be placed in front of
the sensor in order to detect.

Applications

As mentioned in the earlier sections, Proximity Sensor or Obstacle Detection is the main
application of interfacing IR Sensor with Raspberry Pi. Some of the common applications
include:

● Contactless Tachometer
● Line Follower Robot
● Obstacle Avoiding Robot
● Car Reverse Sensor

DESCRIPTION OF THINGSPEAK:-

Definition:-

ThingSpeak. According to its developers, "ThingSpeak is an open-source Internet of Things


(IoT) application and API to store and retrieve data from things using the HTTP protocol
over the Internet or via a Local Area Network.

Why do we need it and What is the use of ThingSpeak?

ThingSpeak is an open data platform for the Internet of Things. Your device or application
can communicate with ThingSpeak using a RESTful API, and you can either keep your data
private, or make it public. In addition, use ThingSpeak to analyze and act on your data.
ThingSpeak provides an online text editor to perform data analysis and visualization using
MATLAB. You can also perform actions such as running regularly scheduled MATLAB
code or sending a tweet when your data passes a defined threshold.

ThingSpeak is used for diverse applications ranging from weather data collection and
analysis, to synchronizing the color of lights across the world.

At the heart of ThingSpeak is a time-series database. ThingSpeak provides users with free
time-series data storage in channels. Each channel can include up to eight data fields.

Sensors, or things, sense data and typically act locally. ThingSpeak enables sensors,
instruments, and websites to send data to the cloud where it is stored in either a private or a
public channel.

ThingSpeak stores data in private channels by default, but public channels can be used to
share data with others. Once data is in a ThingSpeak channel, you can analyze and visualize
it, calculate new data, or interact with social media, web services, and other
devices. ThingSpeak allows you to aggregate, visualize and analyze live data streams in the
cloud. Some of the key capabilities of ThingSpeak include the ability to: Easily configure
devices to send data to ThingSpeak using popular IoT protocols. Visualize your sensor data
in real-time
CODE:-
import RPi.GPIO as GPIO
import time
sleep=1
key = &#39;4AQOQCI2SI3VUP3G&#39; # Write API key
def dist():
while True:
headers = {&quot;Content-typZZe&quot;: &quot;application/x-www-form-
urlencoded&quot;,&quot;Accept&quot;: &quot;text/plain&quot;}
conn = http.client.HTTPConnection(&quot;api.thingspeak.com:80&quot;)
sensor = 16
buzzer = 18
GPIO.setmode(GPIO.BOARD)
GPIO.setup(sensor,GPIO.IN)
GPIO.setup(buzzer,GPIO.OUT)
GPIO.output(buzzer,False)
print &quot;IR Sensor Ready.....&quot;
print &quot; &quot;
try:
while True:
if GPIO.input(sensor):
GPIO.output(buzzer,True)
print &quot;Object Detected&quot;
while GPIO.input(sensor):
time.sleep(0.2)
params = urllib.parse.urlencode({&#39;field1&#39;: distance,
&#39;key&#39;:key }) # channel name is field1 or field 2
conn.request(&quot;POST&quot;, &quot;/update&quot;, params, headers)
response = conn.getresponse()
else:
GPIO.output(buzzer,False)
except KeyboardInterrupt:
GPIO.cleanup()

THINGSPEAK:
OUTPUT:

You might also like