0% found this document useful (0 votes)
22 views54 pages

IOT Record

iot record

Uploaded by

krish191210
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)
22 views54 pages

IOT Record

iot record

Uploaded by

krish191210
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/ 54

VELAGAPUDI RAMAKRISHNA

SIDDHARTHA ENGINEERING COLLEGE


KANURU (AUTONOMUS)

VIJAYAWADA

ACADEMIC YEAR (2020-2021)

¾ B-TECH
SEMESTER -6

LAB-INTERNET OF THINGS (IOT)

Velagapudi Ramakrishna Siddhartha Engineering College


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

Velagapudi Ramakrishna Siddhartha Engineering College


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.

Velagapudi Ramakrishna Siddhartha Engineering College


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


6,7,8,9
 Most of the components used with Arduino board works fine with 3.3
volt and 5 volt.

 GND (8)(Ground) − There are several GND pins on the Arduino, any of

Velagapudi Ramakrishna Siddhartha Engineering College


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 pins
10. 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 ATMEL
11.
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.

14. TX and RX LEDs

Velagapudi Ramakrishna Siddhartha Engineering College


On your board, you will find two labels: TX (transmit) and RX (receive). 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.

Velagapudi Ramakrishna Siddhartha Engineering College


WEEK 2

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

DESCRIPTION:

1. A switch is a device for making and breaking the connection in an electronic circuit.
2. A LED is a 2 led semi conductor light source. It is p-n junction diode that emits light
when activated.
3. Apparatus used are a switch, an LED, jumper wires, an arduino board ,a bread board and
a USB.
4. Switch positive is connected to the pin7 in arduino board.
5. Switch negative is connected and LED negative are connected to ground together.
6. LED positive is connected to pin2 in arduino board.
7. Arduino board is connected to system using USB.

CIRCUIT DIAGRAM:

PROGRAM:

int button=7;

int led=2;

int state;

void setup()

Velagapudi Ramakrishna Siddhartha Engineering College


{
pinMode(button,INPUT_PULLUP);

pinMode(led,OUTPUT);

digitalWrite(led,LOW);

Void loop
{

State=digitalRead(button);

if(state= =1)
{

digitalWrite(led,LOW);

}
else

{
digitalWrite(led,HIGH);

}}

OUTPUT:

Velagapudi Ramakrishna Siddhartha Engineering College


WEEK 3

AIM: Write an arduino program for sensing the room temperature and humidity through
humidity sensing device.

DESCRIPTION:

1. In this we use a DHT (DHT11 version) Temperature and Humidity Sensor.

2. It’s accurate enough to keep track of humidity and temperature readings.

3. By using a Library specifically designed for these sensors that will make our code short
and easy to write.

4. Sensor positive pin is connected to 3.3v pin in the arduino board.

5. Sensor negative pin is connected to the ground.

6. Output pin is connected to one of the Analog pin (A1).

7. Arduino board is connected to system using USB.

CIRCUIT DIAGRAM

PROGRAM:

#include <dht.h>

#define dhtpin.A1

Velagapudi Ramakrishna Siddhartha Engineering College


dht DHT;

void setup(){

Serial.begin(9600);
delay(500);
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(1000);
}

void loop()
{
DHT.read11(dhtpin);
Serial.println("Current humidity = ");
Serial.println(DHT.humidity);
Serial.println("\n");
Serial.println("temperature = ");
Serial.println(DHT.temperature);
Serial.println("\n ");

delay(5000);
}

OUTPUT:

Velagapudi Ramakrishna Siddhartha Engineering College


WEEK 4

AIM: To Write an arduino program for LDR sensor to detect the light sensing.

DESCRIPTION:

As its name implies, the Light Dependent Resistor (LDR) is made from a piece of exposed
semiconductor material such as cadmium sulphide that changes its electrical resistance from
several thousand Ohms in the dark to only a few hundred Ohms when light falls upon it by
creating hole-electron pairs in the material.

1. Connect ldr positive to 3.3v

2. Now consider ldr negative and resistor one end and connect it to the one of the analog pin
in the arduino board.

3. Later the other end of the resistor is connected to the ground.

4. Arduino board is connected to system using USB.

CIRCUIT DIAGRAM:

PROGRAM:

const int ledPin = 13;

const int ldrPin = A0;

void setup() {

Serial.begin(9600);

Velagapudi Ramakrishna Siddhartha Engineering College


pinMode(ledPin, OUTPUT);

pinMode(ldrPin, INPUT);

void loop() {

int ldrStatus = analogRead(ldrPin);

if (ldrStatus <= 100) {

digitalWrite(ledPin, LOW);

Serial.print("Its DARK, Turn on the LED : ");

Serial.println(ldrStatus);

} else {

digitalWrite(ledPin, HIGH);

Serial.print("Its BRIGHT, Turn off the LED : ");

Serial.println(ldrStatus);

OUTPUT:

Velagapudi Ramakrishna Siddhartha Engineering College


WEEK 5

AIM: Detecting the object using IR sensor

DESCRIPTION:

An infrared sensor is an electronic device that emits in order to sense some aspects of the
surroundings. An IR sensor can measure the heat of an object as well as detects the motion

1. Output pin is connected to the one of the digital pin of the arduino board.

2. Ground pin is connected to the ground of the arduino board.

3. Vcc is connected to the 5v of the arduino board.

CIRCUIT DIAGRAM:

PROGRAM:
int LED = 13;
int isObstaclePin = 7;
int isObstacle = HIGH;

void setup() {
pinMode(LED, OUTPUT);
pinMode(isObstaclePin, INPUT);
Serial.begin(9600);

void loop() {
isObstacle = digitalRead(isObstaclePin);
if (isObstacle == LOW)
{

Velagapudi Ramakrishna Siddhartha Engineering College


Serial.println("OBSTACLE!!, OBSTACLE!!");
digitalWrite(LED, HIGH);
}
else
{
Serial.println("clear");
digitalWrite(LED, LOW);
}
delay(200);
}
OUTPUT:

2. AIM: Detecting the object distance by using ultrasonic sensor

DESCRIPTION:
Ultrasonic sensors work by emitting sound waves at a frequency too high for humans to hear. They then
wait for the sound to be reflected back, calculating distance based on the time required. This is similar to
how radar measures the time it takes a radio wave to return after hitting an object
CIRCUIT DIAGRAM:

Velagapudi Ramakrishna Siddhartha Engineering College


PROGRAM:

int trig=7;
int echopin=6;
long duration;
int distance;
void setup() {
pinMode(echopin,INPUT);
pinMode(trig,OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(trig,LOW);
delayMicroseconds(2);
digitalWrite(trig,HIGH);
delayMicroseconds(10);
digitalWrite(trig,LOW);
duration=pulseIn(echopin,HIGH);
distance=(duration*0.034)/2;
Serial.println("Distance is:");
Serial.println(distance);

OUTPUT:

Velagapudi Ramakrishna Siddhartha Engineering College


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

DESCRIPTION:

The DHT11 is a digital sensor that lets you easily get relative humidity and temperature
readings in your projects. Because of their low cost and small size, DHT11 sensors are
perfect for lots of different DIY electronics projects. Some projects where the DHT11 would
be useful include remote weather stations, home environment control systems, and
agricultural/garden monitoring systems.

1. Arduino GND to breadboard Negative power rail (All black wires goes to this rail)

2. Arduino 5V to breadboard Positive power rail (All deep-blue wires goes to this rail)

3. DHT11 Positive pin to breadboard positive power rail

4. DHT11 Negative pin to breadboard negative power rail

5. DHT11 Signal pin to Arduino Analog A0 (this feeds data from DHT11 to Arduino)

6. LCD 1 to breadboard Negative power rail

7. LCD 2 to breadboard Positive power rail

8. LCD 3 to breadboard Negative power rail (if you connect this to a potentiometer, this helps

to change the LCD brightness)

9. LCD 4 to Arduino Digital Pin 12 (LCD character coordinates)

10. LCD 5 to breadboard Negative power rail

11. LCD 6 to Arduino Digital Pin 11 (LCD initiate command)

12. LCD 11 to Arduino Digital Pin 5

13. LCD 12 to Arduino Digital Pin 4

14. LCD 13 to Arduino Digital Pin 3

15. LCD 14 to Arduino Digital Pin 2

16. LCD 15 to breadboard Positive power rail

Velagapudi Ramakrishna Siddhartha Engineering College


17. LCD 16 to breadboard Negative power rail

18. Cold/Green LED Positive Pin to Arduino Digital Pin 7 (negative pin to breadboard negative

rail)

19. Hot/Yellow LED Positive Pin to Arduino Digital Pin 8 (negative pin to breadboard negative

rail)

20. Extreme/Red LED Positive Pin to Arduino Digital Pin 9 (negative pin to breadboard

negative rail)

CIRCUIT DIAGRAM:

Velagapudi Ramakrishna Siddhartha Engineering College


CODE:

#include <LiquidCrystal.h>

#include <DHT.h>

#include "DHT.h"

#define DHTPIN A0 // what pin we're connected to

#define DHTTYPE DHT11 // we are using the DHT11 sensor

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

DHT dht(DHTPIN, DHTTYPE);

void setup()

Serial.begin(9600);

for (int DigitalPin = 7; DigitalPin <= 9; DigitalPin++)

pinMode(DigitalPin, OUTPUT);

lcd.begin(16,2); //16 by 2 character display

dht.begin();

void loop()

Velagapudi Ramakrishna Siddhartha Engineering College


delay(1000);

// Reading temperature or humidity takes about 250 milliseconds!

float h = dht.readHumidity();

float t = dht.readTemperature(); // Read temperature as Celsius (the default)

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Temp: ");

lcd.print(t); //printing temperarture to the LCD display

lcd.print("'C");

lcd.setCursor(0,1);

lcd.print("Humid: ");

lcd.print(h); //printing humidity to the LCD display

lcd.print("%");

//the 3-led setup process

if (t<=22)

digitalWrite(7, HIGH);

digitalWrite(8, LOW);

digitalWrite(9, LOW);

Velagapudi Ramakrishna Siddhartha Engineering College


else if (t>22)

digitalWrite(8, HIGH);

digitalWrite(7, LOW);

digitalWrite(9, LOW);

else if (t>=35)

digitalWrite(9, HIGH);

digitalWrite(7, LOW);

digitalWrite(8, LOW);

OUTPUT:

Velagapudi Ramakrishna Siddhartha Engineering College


WEEK 7

AIM: Write an arduino program to create a simple circuit with an Arduino and PIR motion
sensor that can detect movement. An LED will light up when movement is detected.

DESCRIPTION:

The PIR motion sensor is ideal to detect movement. PIR stand 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 in infrared light in the environment. It is ideal to detect if a human has
moved in or out of the sensor range. the sensor in the figure above has two built-in
potentiometers to adjust the delay time (the potentiometer at the left) and the sensitivity (the
potentiometer at the right

CIRCUIT DAIGRAM:

Velagapudi Ramakrishna Siddhartha Engineering College


CODE:

int led = 13; // the pin that the LED is atteched to

int sensor = 2; // the pin that the sensor is atteched to

int state = LOW; // by default, no motion detected

int val = 0; // variable to store the sensor status (value)

void setup() {

pinMode(led, OUTPUT); // initalize LED as an output

pinMode(sensor, INPUT); // initialize sensor as an input

Serial.begin(9600); // initialize serial

void loop(){

val = digitalRead(sensor); // read sensor value

if (val == HIGH) { // check if the sensor is HIGH

digitalWrite(led, HIGH); // turn LED ON

delay(100); // delay 100 milliseconds

if (state == LOW) {

Serial.println("Motion detected!");

state = HIGH; // update variable state to HIGH

Velagapudi Ramakrishna Siddhartha Engineering College


else {

digitalWrite(led, LOW); // turn LED OFF

delay(200); // delay 200 milliseconds

if (state == HIGH){

Serial.println("Motion stopped!");

state = LOW; // update variable state to LOW

OUTPUT:

Velagapudi Ramakrishna Siddhartha Engineering College


WEEK 8
AIM: To write an arduino program detect the smoke presence with the help MQ-2 sensor.

DESCRIPTION:
The voltage that the sensor outputs changes accordingly to the smoke/gas level that exists in
the atmosphere. The sensor outputs a voltage that is proportional to the concentration of
smoke/gas. In other words, the relationship between voltage and gas concentration is the
following: The greater the gas concentration, the greater the output voltage.The lower the
gas concentration, the lower the output voltage

Working Mechanism

The output can be an analog signal (A0) that can be read with an analog input of the
Arduino or a digital output (D0) that can be read with a digital input of the Arduino.

CIRCUIT DIAGRAM:

Velagapudi Ramakrishna Siddhartha Engineering College


CODE:
int redLed = 12;
int greenLed = 11;
int buzzer = 10;
int smokeA0 = A5;
// Your threshold value
int sensorThres = 400;
void setup() {
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}
void loop() {
int analogSensor = analogRead(smokeA0);
Serial.print("Pin A0: ");
Serial.println(analogSensor);
// Checks if it has reached the threshold value
if (analogSensor > sensorThres)
{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
tone(buzzer, 1000, 200);
}
else
{
digitalWrite(redLed, LOW);

Velagapudi Ramakrishna Siddhartha Engineering College


digitalWrite(greenLed, HIGH);
noTone(buzzer);
}
delay(100);
}
OUTPUT:

Velagapudi Ramakrishna Siddhartha Engineering College


WEEK 9

AIM: To write an arduino program to implement relay module along with the buzzer.

DESCRIPTION: A relay is an electrically operated switch that can be turned on or off,


letting the current go through or not, and can be controlled with low voltages, like the 5V
provided by the Arduino pins.

Controlling a relay module with the Arduino is as simple as controlling any other output as
we'll see later on. In this relay, when a current flows through the coil, it turns it into an
electromagnet.

The magnet pushes a switch to the left, forcing the spring contacts together, and completing
the circuit they're attached to. This is a relay from an electronic, hot-water immersion heater
programmer

CODE:

Int irmotionPin =4;

Int relayPin=8;

Void setup()

Serial.begin(9600);

pinMode(relayPin,OUTPUT);

Velagapudi Ramakrishna Siddhartha Engineering College


digitalWrite(relayPin,LOW);

Void loop()

{
While(digitalRead(irmotion)==HIGH)

digitalWrite(relayPin,HIGH);

Serial.println(“Realy is OFF”);

Delay(1000);

digiatlWrite(relayPin,LOW);

Serial.println(“Relay is ON”);

Delay(1000);

OUTPUT:

Velagapudi Ramakrishna Siddhartha Engineering College


WEEK 10

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

Velagapudi Ramakrishna Siddhartha Engineering College


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.

Velagapudi Ramakrishna Siddhartha Engineering College


Velagapudi Ramakrishna Siddhartha Engineering College
WEEK 11
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:

Velagapudi Ramakrishna Siddhartha Engineering College


CODE:

import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library

from time import sleep # Import the sleep function from the time module

GPIO.setwarnings(False) # Ignore warning for now

GPIO.setmode(GPIO.BOARD) # Use physical pin numbering

GPIO.setup(8, GPIO.OUT, initial=GPIO.LOW) # Set pin 8 to be an output pin and set initial
value to low (off)

while True: # Run forever

GPIO.output(8, GPIO.HIGH) # Turn on

sleep(1) # Sleep for 1 second

GPIO.output(8, GPIO.LOW) # Turn off

sleep(1) # Sleep for 1 second

OUTPUT:

Velagapudi Ramakrishna Siddhartha Engineering College


WEEK 12
AIM: To write a raspberry pi program to implement blinking of an led by using switch

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. Buttons are a common component used to control electronic devices. They are
usually used as switches to connect or disconnect circuits. Although buttons come in a variety of
sizes and shapes, the one used here is a6mmmini-button as shown in the following pictures. Pins
pointed out by the arrows of same color are meant to be connected.

CIRCUIT DIAGRAM:

Velagapudi Ramakrishna Siddhartha Engineering College


CODE:

import RPi.GPIO as GPIO

from time import sleep

GPIO.setmode(GPIO.BOARD)

GPIO.setup(16,GPIO.IN,pull_up_down=GPIO.PUD_UP)

GPIO.setup(18,GPIO.OUT)

try:

while True:

bs=GPIO.input(16)

if bs==False:

GPIO.output(18,1)

print('button pressed')

sleep(1)

else:

GPIO.output(18,0)

except:

GPIO.cleanup()

Velagapudi Ramakrishna Siddhartha Engineering College


OUTPUT:

Velagapudi Ramakrishna Siddhartha Engineering College


WEEK 13

AIM: To implement the DHT11 sensor with raspberry pi to find the temperature and humidity.

DESCRIPTION:

The DHT11 requires a specific protocol to be applied to the data pin. In order to save time trying
to implement this yourself it’s far easier to use the Adafruit DHT library.

The library deals with the data that needs to be exchanged with the sensor but it is sensitive to
timing issues. The Pi’s operating system may get in the way while performing other tasks so to
compensate for this the library requests a number of readings from the device until it gets one
that is valid.

Software Setup

To start with update your package lists and install a few Python libraries :

sudo apt-get update

sudo apt-get install build-essential python-dev

Then clone the Adafruit library from their repository :

git clone https://github.com/adafruit/Adafruit_Python_DHT.git

cd Adafruit_Python_DHT

Then install the library for Python 2 and Python 3 :

sudo python setup.py install

sudo python3 setup.py install

Once the Adafruit library is installed and you’ve got the example script to work you can use
the sensor in your own scripts. Simply import the module, setup a few variables and call the
“read_retry” function :

Velagapudi Ramakrishna Siddhartha Engineering College


CIRCUIT DIAGRAM:

CODE:

import Adafruit_DHT

# Set sensor type : Options are DHT11,DHT22 or AM2302

sensor=Adafruit_DHT.DHT11

# Set GPIO sensor is connected to

gpio=17

# Use read_retry method. This will retry up to 15 times to

# get a sensor reading (waiting 2 seconds between each retry).

humidity, temperature = Adafruit_DHT.read_retry(sensor, gpio)

# Reading the DHT11 is very sensitive to timings and occasionally

# the Pi might fail to get a valid reading. So check if readings are valid.

if humidity is not None and temperature is not None:

print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))

Velagapudi Ramakrishna Siddhartha Engineering College


else:

print('Failed to get reading. Try again!')

OUTPUT:

Velagapudi Ramakrishna Siddhartha Engineering College


WEEK 14

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).

1. First, connect pin #1 (3v3) to the positive rail on the breadboard.


2. Next, connect pin #6 (ground) to the ground rail on the breadboard.
3. Now place the LDR sensor onto the board and have a wire go from one end to the positive rail.
4. On the other side of the LDR sensor place a wire leading back to the Raspberry Pi. Hook this
to pin #7.
5. Finally, place the capacitor from the wire to the negative rail on the breadboard. Make sure
you have the negative pin of the capacitor in the negative rail.

CIRCUIT DIAGRAM:

Velagapudi Ramakrishna Siddhartha Engineering College


CODE:

import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BOARD)

#define the pin that goes to the circuit

pin_to_circuit = 7

def rc_time (pin_to_circuit):

count = 0

#Output on the pin for

GPIO.setup(pin_to_circuit, GPIO.OUT)

GPIO.output(pin_to_circuit, GPIO.LOW)

time.sleep(0.1)

#Change the pin back to input

GPIO.setup(pin_to_circuit, GPIO.IN)

#Count until the pin goes high

while (GPIO.input(pin_to_circuit) == GPIO.LOW):

count += 1

return count

#Catch when script is interrupted, cleanup correctly

try:

Velagapudi Ramakrishna Siddhartha Engineering College


# Main loop

while True:

print(rc_time(pin_to_circuit))

except KeyboardInterrupt:

pass

finally:

GPIO.cleanup()

OUTPUT:

Velagapudi Ramakrishna Siddhartha Engineering College


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 mo re
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 electronicsensor 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.

CIRCUIT DIAGRAM:

Velagapudi Ramakrishna Siddhartha Engineering College


CODE:

import RPi.GPIO as GPIO

import time

GPIO.setwarnings(False)

GPIO.setmode(GPIO.BOARD)

GPIO.setup(11, GPIO.IN) #Read output from PIR motion sensor

GPIO.setup(3, GPIO.OUT) #LED output pin

while True:

i=GPIO.input(11)

if i==0: #When output from motion sensor is LOW

print "No intruders",i

GPIO.output(3, 0) #Turn OFF LED

time.sleep(0.1)

elif i==1: #When output from motion sensor is HIGH

print "Intruder detected",i

GPIO.output(3, 1) #Turn ON LED

time.sleep(0.1)

Velagapudi Ramakrishna Siddhartha Engineering College


OUTPUT:

Velagapudi Ramakrishna Siddhartha Engineering College


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.

Velagapudi Ramakrishna Siddhartha Engineering College


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.

Velagapudi Ramakrishna Siddhartha Engineering College


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

Velagapudi Ramakrishna Siddhartha Engineering College


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

Velagapudi Ramakrishna Siddhartha Engineering College


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

Velagapudi Ramakrishna Siddhartha Engineering College


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.

3.3.2 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

Velagapudi Ramakrishna Siddhartha Engineering College


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:

Velagapudi Ramakrishna Siddhartha Engineering College


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:

Velagapudi Ramakrishna Siddhartha Engineering College


OUTPUT:

Velagapudi Ramakrishna Siddhartha Engineering College

You might also like