IOT Record
IOT Record
VIJAYAWADA
¾ B-TECH
SEMESTER -6
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.
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.
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).
GND (8)(Ground) − There are several GND pins on the Arduino, any of
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.
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.
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
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()
pinMode(led,OUTPUT);
digitalWrite(led,LOW);
Void loop
{
State=digitalRead(button);
if(state= =1)
{
digitalWrite(led,LOW);
}
else
{
digitalWrite(led,HIGH);
}}
OUTPUT:
AIM: Write an arduino program for sensing the room temperature and humidity through
humidity sensing device.
DESCRIPTION:
3. By using a Library specifically designed for these sensors that will make our code short
and easy to write.
CIRCUIT DIAGRAM
PROGRAM:
#include <dht.h>
#define dhtpin.A1
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:
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.
2. Now consider ldr negative and resistor one end and connect it to the one of the analog pin
in the arduino board.
CIRCUIT DIAGRAM:
PROGRAM:
void setup() {
Serial.begin(9600);
pinMode(ldrPin, INPUT);
void loop() {
digitalWrite(ledPin, LOW);
Serial.println(ldrStatus);
} else {
digitalWrite(ledPin, HIGH);
Serial.println(ldrStatus);
OUTPUT:
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.
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)
{
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:
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:
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)
5. DHT11 Signal pin to Arduino Analog A0 (this feeds data from DHT11 to Arduino)
8. LCD 3 to breadboard Negative power rail (if you connect this to a potentiometer, this helps
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:
#include <LiquidCrystal.h>
#include <DHT.h>
#include "DHT.h"
void setup()
Serial.begin(9600);
pinMode(DigitalPin, OUTPUT);
dht.begin();
void loop()
float h = dht.readHumidity();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print("'C");
lcd.setCursor(0,1);
lcd.print("Humid: ");
lcd.print("%");
if (t<=22)
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(8, HIGH);
digitalWrite(7, LOW);
digitalWrite(9, LOW);
else if (t>=35)
digitalWrite(9, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
OUTPUT:
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:
void setup() {
void loop(){
if (state == LOW) {
Serial.println("Motion detected!");
if (state == HIGH){
Serial.println("Motion stopped!");
OUTPUT:
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:
AIM: To write an arduino program to implement relay module along with the buzzer.
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 relayPin=8;
Void setup()
Serial.begin(9600);
pinMode(relayPin,OUTPUT);
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:
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.
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.
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
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:
from time import sleep # Import the sleep function from the time module
GPIO.setup(8, GPIO.OUT, initial=GPIO.LOW) # Set pin 8 to be an output pin and set initial
value to low (off)
OUTPUT:
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:
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()
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 :
cd Adafruit_Python_DHT
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 :
CODE:
import Adafruit_DHT
sensor=Adafruit_DHT.DHT11
gpio=17
# the Pi might fail to get a valid reading. So check if readings are valid.
OUTPUT:
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).
CIRCUIT DIAGRAM:
import time
GPIO.setmode(GPIO.BOARD)
pin_to_circuit = 7
count = 0
GPIO.setup(pin_to_circuit, GPIO.OUT)
GPIO.output(pin_to_circuit, GPIO.LOW)
time.sleep(0.1)
GPIO.setup(pin_to_circuit, GPIO.IN)
count += 1
return count
try:
while True:
print(rc_time(pin_to_circuit))
except KeyboardInterrupt:
pass
finally:
GPIO.cleanup()
OUTPUT:
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:
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
while True:
i=GPIO.input(11)
time.sleep(0.1)
time.sleep(0.1)
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.
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.
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.
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.
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
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
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
Definition:-
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
import time
sleep=1
def dist():
while True:
conn = http.client.HTTPConnection("api.thingspeak.com:80")
sensor = 16
buzzer = 18
GPIO.setmode(GPIO.BOARD)
GPIO.setup(sensor,GPIO.IN)
GPIO.setup(buzzer,GPIO.OUT)
GPIO.output(buzzer,False)
try:
while True:
GPIO.output(buzzer,True)
while GPIO.input(sensor):
time.sleep(0.2)
response = conn.getresponse()
else:
GPIO.output(buzzer,False)
except KeyboardInterrupt:
GPIO.cleanup()
THINGSPEAK: