KEMBAR78
ESIoT Lab Manual | PDF | Raspberry Pi | Internet Of Things
0% found this document useful (0 votes)
11 views83 pages

ESIoT Lab Manual

Uploaded by

janart302
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)
11 views83 pages

ESIoT Lab Manual

Uploaded by

janart302
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/ 83

1.

EXPERIMENT
OUTPUT:

RESULT:
Thus the assembly language program was performed and got output
successfully
2 EXPERIMENT
OUTPUT:

RESULT: Thus the data transfer between registers and memory experiment
was performed and got output successfully.
3.EXPERIMENT
AIM: To perform Arithmetic and Logical Unit (ALU) operations
(Addition, Subtraction, AND, OR) using the 8051 microcontroller and
verify the results by storing them in registers.
All Arithmetic and logical program

//Addition

MOV A,#25H

MOV B,#12H

ADD A,B

MOV 40H,A //40H IS THE DESTINATION ADDRESS IN RAM

//SUBTRACTION

MOV A,#25H

MOV B,#12H

SUBB A,B

MOV 41H,A

//multiplication

MOV A,#25H

MOV B,#12H

MUL AB

MOV 42H,A

MOV 43H,B

//DIVISION

MOV A,#25H

MOV B,#12H

DIV AB

MOV 44H,A

MOV 45H,B

Logical operation
//AND OPERATION

MOV A,#25H

MOV B,#12H

ANL A,B

MOV 46H,A

//OR OPERATION

MOV A,#25H

MOV B,#12H

ORL A,B

MOV 47H,A

//XRL OPERATION

MOV A,#25H

MOV B,#12H

XRL A,B

MOV 48H,A

//INCREMENT

INC A

MOV 49H,A

//DECREMENT

DEC A

MOV 4AH,A

LCALL 0003

END
OUTPUT:
Arithmetic:

Logical:

RESULT: Thus the ALU operation was performed and got output
successfully.
4 A) EXPERIMENT
OUTPUT:

RESULT: Thus the arithmetic programs using embedded C was


performed and got output successfully.
4B)
Output: pin no 16 to 31 will turn on when switch operated to on position

4C)
RESULT:
Thus the Program for flashing of LED is executed successfully using embedded C
program.

4D)
Square wave generation using C program

#include<REG51xD2.H>

void delay(unsigned int x)

for(;x>0;x--);

main()
{

unsigned char on=0xFF,Off=0x00;

P0=on;

delay(100);

P0=Off;

delay(100);

OUTPUT:

4 E)
Output: SM Micro System , hour=18; min=30; sec=30
4f)
Output: Temperature sensor:
Adc test 28 degree Celsius
Stepper motor:Motor will run in forward direction
Result:
Thus the program for stepper motor and temperature sensor is
executed sucessfully.

5) ARDUINO PROGRAMMING
5 A) BLINKING OF LED
AIM:
To execute blinking of led program using Arduino Uno board
ALGORITHM:
1.Start the program
2.Save the program
3.Compile the code by clicking the tick mark
4.Upload the code
5.Go to Tools--> Board--> Arduino Uno
6.Go to Tools-->port-->check in device manager for port selection

PROGRAM:
int LEDpin = 13;
int delayT = 2000;
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
pinMode(LEDpin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LEDpin, HIGH);
delay(delayT);
digitalWrite(LEDpin, LOW);
delay(delayT);
}
Output:
The led light turns on and off with a delay of 2 seconds.
RESULT:
Thus the program for blinking of LED is executed successfully.

5 B) IR SENSOR
AIM:
To determine whether is object is present or not using IR Sensor.
ALGORITHM:
1.Start the program
2.Save the program
3.Compile the code by clicking the tick mark
4.Upload the code
5.Go to Tools--> Board--> Arduino Uno
6.Go to Tools-->port-->check in device manager for port selection
7.Sketches-->Serial monitor to see the result
PROGRAM:

int IR_Sensor=2;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(IR_Sensor, INPUT);

}
void loop() {
// put your main code here, to run repeatedly:
int SensorValue=digitalRead(IR_Sensor);
if(SensorValue==LOW)
{
Serial.println("No object Detected");
}
else {
Serial.println("object Detected");
}
delay(500);
}

or

int LEDpin = 13;


int obstaclePin = 7;
//int SensorValue = 0; // LOW MEANS NO OBSTACLE
void setup() {
pinMode(LEDpin, OUTPUT);
pinMode(obstaclePin, INPUT);
Serial.begin(9600);
}
void loop()
{
int SensorValue=digitalRead(obstaclePin);
if (SensorValue == LOW)
{
Serial.println("Obbject Detected ");
digitalWrite(LEDpin, HIGH);
}
else
{
Serial.println("No object!!");
digitalWrite(LEDpin, LOW);
}
delay(500);
}

Output:
The object is detected when it is placed near the sensor.
RESULT:
Thus the program for object is present or not using IR Sensor
is executed successfully.

5 C)ULTRASONIC SENSOR
AIM:
To measure the distance of the object using ultrasonic sensor.
ALGORITHM:
1.Start the program
2.Save the program
3.Compile the code by clicking the tick mark
4.Upload the code
5.Go to Tools--> Board--> Arduino Uno
6.Go to Tools-->port-->check in device manager for port selection
7.Sketches-->Serial monitor to see the result
PROGRAM:
const int trigPin=9; // it defines the Triger pin of the sensor to pin 5 of Arduino
const int echoPin=10;
// we have defined the variable
long duration; // variable for the duration of sound wave travel
int distance; // variable for the distance measurement
void setup()
{
// It sets the TRIG pin as INPUT
Serial.begin(9600); // // Serial Communication at the rate of 9600 bps
pinMode(echoPin, INPUT);
Serial.println("Test of the Ultrasonic Sensor HC-SR04"); // It will appear on Serial
Monitor
Serial.println("with the Arduino UNO R3 board");
}
void loop()
{
// It first sets the TRIG pin at LOW for 2 microseconds
digitalWrite(trigPin,HIGH);
delayMicroseconds(2);
digitalWrite(trigPin,LOW);
// It will read the ECHO pin and will return the time
duration = pulseIn(echoPin,HIGH);
// distance formula
distance = duration*(0.034/2); // (speed in microseconds)
// Speed of sound wave (340 m/s)divided by 2 (forward and backward bounce)
// To display the distance on Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm"); //specified unit of distance
delay(1000);
}
OUTPUT:

RESULT:
Thus the program for measuring distance of the object using
ultrasonic sensor is executed successfully.
5 D) WATER SENSOR
AIM:
To Detect the moisture level using Water Sensor.
ALGORITHM:
1.Start the program
2.Save the program
3.Compile the code by clicking the tick mark
4.Upload the code
5.Go to Tools--> Board--> Arduino Uno
6.Go to Tools-->port-->check in device manager for port selection
7.Sketches-->Serial monitor to see the result
PROGRAM:
#define Grove_Water_Sensor 8 // Attach Water sensor to Arduino Digital Pin 8
#define LED 13 // Attach an LED to Digital Pin 9 (or use onboard LED)

void setup() {
pinMode(Grove_Water_Sensor, INPUT); // The Water Sensor is an Input
Serial.begin(9600);
pinMode(LED, OUTPUT); // The LED is an Output
}

void loop() {
/* The water sensor will switch LOW when water is detected.
Get the Arduino to illuminate the LED and activate the buzzer
when water is detected, and switch both off when no water is present */
if( digitalRead(Grove_Water_Sensor) == LOW)
{
digitalWrite(LED,HIGH);
Serial.println("No Moisture");
}
else {
digitalWrite(LED,LOW);
Serial.println("Moisture is Present");
}
delay(500);
}
OUTPUT:

RESULT:
Thus the program to Detect the moisture level using Water Sensor
is executed successfully.

5E) TEMPERATURE SENSOR:


AIM:To measure, monitor the temperature and humidity using temperature
sensor.
ALGORITHM:
1.Start the program
2.Save the program
3.Compile the code by clicking the tick mark
4.Upload the code
5.Go to Tools--> Board--> Arduino Uno
6.Go to Tools-->port-->check in device manager for port selection
7.Sketches-->Serial monitor to see the result
PROGRAM:

OUTPUT:
RESULT:
Thus the program to measure the temperature and humidity using
temperature Sensor is executed successfully.
EXPERIMENT 10: SETUP A CLOUD PLATFORM TO LOG THE DATA
AIM: To setup a cloud platform to log the data using wifi module

APPARATUS REQUIRED:

THOERY:Wifi is a form of local area network for wireless communication.


It is a better option for data transfers as it easily fits into a variety of standards.
It plays an important role in IoT communication and intercommunication with other
cellular networks such as bluetooth.
Wifi supports high bandwidth and low latency.

PROGRAM:
#define BLYNK_TEMPLATE_ID "TMPL3R5MDYF7N"
#define BLYNK_TEMPLATE_NAME "test2"
#define BLYNK_AUTH_TOKEN "ZN2-L6mu_9szoqLmqG8XIKR50wsI8RNc"
#define CLOUDCHECKER V4
#define TIMER V5
#define LIGHT 2
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = BLYNK_AUTH_TOKEN;


char ssid[] = "kabilan s";
char pass[] = "12112003@v";

BlynkTimer timer;

BLYNK_CONNECTED() {
Blynk.setProperty(CLOUDCHECKER, "offImageUrl", "https://static-
image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
Blynk.setProperty(CLOUDCHECKER, "onImageUrl", "https://static-
image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
Blynk.setProperty(CLOUDCHECKER, "url", "https://docs.blynk.io/en/getting-
started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}

void myTimerEvent() {
Blynk.virtualWrite(TIMER, millis() / 1000);
}

BLYNK_WRITE(V0)
{
if (param.asInt() == 1)
{
Serial.println(param.asInt());
Serial.println("Light is ON");
digitalWrite(LIGHT, LOW);
}
else
{
digitalWrite(LIGHT, HIGH);
}
}

void setup() {
Blynk.begin(auth, ssid, pass);
pinMode(LIGHT,OUTPUT);
Serial.begin(9600);
Serial.print("Ready!");
}
void loop() {
Blynk.run();
}

OUTPUT:

RESULT: Thus to setup a cloud platform to log the data exceuted successfully.
EXPLORE DIFFERENT COMMUNICATION METHODS WITH IOT DEVICES (ZIGBEE,
GSM, BLUETOOTH)

EXP NO: 6

DATE :

Zigbee

ZigBee is similar to Bluetooth and is majorly used in industrial settings. It has some significant
advantages in complex systems offering low-power operation, high security, robustness and
high and is well positioned to take advantage of wireless control and sensor networks in IoT
applications.
The latest version of ZigBee is the recently launched 3.0, which is essentially the unification of
the various ZigBee wireless standards into a single standard.

Iot Technology – ZigBee

Bluetooth

An important short-range IoT communications Protocols / Technology. Bluetooth, which has


become very important in computing and many consumer product markets. It is expected to be
key for wearable products in particular, again connecting to the IoT albeit probably via a
smartphone in many cases.
The new Bluetooth Low-Energy (BLE) – or Bluetooth Smart, as it is now branded – is a
significant protocol for IoT applications. Importantly, while it offers a similar range to
Bluetooth it has been designed to offer significantly reduced power consumption.

Page | 28
Iot Technology – Bluetooth

How to Set Up and Test Arduino Bluetooth Connection

This works with android phones and the HC-05 and HC-06 bluetooth modules, as well as pretty
much any arduino or arduino clone.

Pretty straightforward, connect the bluetooth module to the arduino like so

RX-pin2

TX-pin 3

GND-GND

VCC-5v

Step 2: Plug in the Arduino and Upload the Sketch

Download the ino file and upload it to the arduino.

Page | 29
Step 3: Connect to the Bluetooth on Your Phone

Open up the bluetooth settings on your phone and look for the module. Mine is named Sailfish
but yours should be named either hc-05 or hc-06. The password is almost always 1234, if not,
try 0000.

Step 4: Connect to the Bluetooth Module

download a bluetooth terminal app from the appstore, this one works great:
https://play.google.com/store/apps/details?id=Qwerty.BluetoothTerminal&hl=en and open it
up. Open the app, hit connect to a device - insecure and select your bluetooth module from the
list.

Page | 30
Step 5: Ready to Go!

Finally open up the Serial Monitor in the arduino IDE by hitting the magnifying glass in the top
right corner, and you should be good to go. You now have a back and forth extremely simple
connection between your phone and your arduino via bluetooth.

Cellular

Any IoT application that requires operation over longer distances can take advantage of
GSM/3G/4G cellular communication capabilities. While cellular is clearly capable of sending
high quantities of data, especially for 4G, the cost and also power consumption will be too high
for many applications.
But it can be ideal for sensor-based low-bandwidth-data projects that will send very low
amounts of data over the Internet.

Page | 31
IoT Communication Protocols – Cellular

RESULT

Thus the different communication methods with IOT devices (Zigbee, Gsm, Bluetooth)
was studied successfully

Page | 32
INTRODUCTION TO RASPBERRY PI PLATFORM AND PYTHON PROGRAMMING

EXP NO: 7

DATE :

Raspberry Pi - Introduction
Raspberry Pi, developed by Raspberry Pi Foundation in association with Broadcom, is a
series of small single-board computers and perhaps the most inspiring computer available
today.
From the moment you see the shiny green circuit board of Raspberry Pi, it invites you to
tinker with it, play with it, start programming, and create your own software with it. Earlier,
the Raspberry Pi was used to teach basic computer science in schools but later, because of its
low cost and open design, the model became far more popular than anticipated.
It is widely used to make gaming devices, fitness gadgets, weather stations, and much more.
But apart from that, it is used by thousands of people of all ages who want to take their first
step in computer science.
It is one of the best-selling British computers and most of the boards are made in the Sony
factory in Pencoed, Wales.
Generations and Models
In 2012, the company launched the Raspberry Pi and the current generations of regular
Raspberry Pi boards are Zero, 1, 2, 3, and 4.
Generation 1 Raspberry Pi had the following four options −
 Model A
 Model A +
 Model B
 Model B +
Among these models, the Raspberry Pi B models are the original credit-card sized format.
On the other hand, the Raspberry Pi A models have a smaller and more compact footprint and
hence, these models have the reduced connectivity options.
Raspberry Pi Zero models, which come with or without GPIO (general-purpose input output)
headers installed, are the most compact of all the Raspberry Pi boards types.
Speed Specifications

The table below gives the speed specifications of various Raspberry Pi models and
generations focusing on the version‟s release date, form factor and dimensions −

Raspberry Pi Version Release Date Form Factor Dimensions (in mm)

Raspberry Pi 4 Model B 2019-2020 Standard 85.6 x 56.5

Raspberry Pi 3 Model B+ 2018 Standard 85.6 x 56.5

Raspberry Pi 3 Model B 2016 Standard 85.6 x 56.5

Page | 33
Raspberry Pi 3 Model A+ 2018 Compact 65 x 56.5

Raspberry Pi Zero 2017 Mini 65 x 30 x 5


Wireless with Headers

Raspberry Pi Zero 2016 Mini 65 x 30 x 5


Wireless

Raspberry Pi Zero 2015 Mini 65 x 30 x 5

Raspberry Pi 2 Model B 2015 Standard 85.6 x 56.5

Raspberry Pi 1 Model B + 2014 Standard 85.6 x 56.5

Raspberry Pi 1 Model B 2012 Standard 85.6 x 56.5

Raspberry Pi 1 Model A+ 2014 Compact 65 x 56.5

Raspberry Pi 1 Model A 2013 Standard 85.6 x 56.5


The table below gives the speed specifications of various Raspberry Pi models and
generations focusing on the version‟s weight, General Purpose Input/Output (GPIO),
central processing unit (CPU) speed, Cores and Random-access memory (RAM) −

Raspberry Weight (in


GPIO CPU Speed Cores RAM
Pi Version grams)

Raspberry
Pi 4 Model 46 40 Pin 1.5 GHz Quad 1,2,4, or 8 GB
B

Raspberry
Pi 3 Model 50 40 Pin 1.4 GHz Quad 1 GB
B+

Raspberry
Pi 3 Model 40 40 Pin 1.2 GHz Quad 1 GB
B

Raspberry
Pi 3 Model 28 40 Pin 1.4 GHz Quad 512 MB
A+

Raspberry 10 40 Pin 1 GHz Single 512


Pi Zero
Page | 34
Wireless MB
with
Headers

Raspberry
40 Pin 512
Pi Zero 10 1 GHz Single
Unpopulated MB
Wireless

Raspberry 40 Pin 512


8 1 GHz Single
Pi Zero Unpopulated MB

Raspberry
Pi 2 Model 42 40 Pin 1.2 1 GB
Quad
B GHz

Raspberry
700 512
Pi 1 Model 42 40 Pin Single
MHz MB
B+

Raspberry
21 Pin (26 700 512
Pi 1 Model 38 Single
Pin Header) MHz MB
B

Raspberry
700 512
Pi 1 Model 23 40 Pin Single
MHz MB
A+

Raspberry
21 Pin (26 700 256
Pi 1 Model 30 Single
Pin Header) MHz MB
A

Connectivity Specifications
The table below gives the connectivity specifications of various Raspberry Pi boards focusing on
the version‟s full sized USB ports, other USB and charge methods, power and High-Definition
Multimedia Interface (HDMI) ports –

Raspberry Pi Full sized USB Other USB & Power HDMI Ports
Version Ports Charge Methods

Page | 35
Raspberry Pi 2 USB3.0 2 1 USB-C 5.1V at 3A 2 micro-HDMI
4 Model B USB2.0

Raspberry Pi 4 USB2.0 1 MIcroUSB 5.1V at HDMI, Composite (TRRS)


3 Model B+ 2.5A

Raspberry Pi 4 USB2.0 1 MIcroUSB 5.1V at HDMI, Composite (TRRS)


3 Model B 2.5A

Raspberry Pi 1 USB2.0 1 MIcroUSB 5.1V at 3A HDMI, Composite (TRRS)


3 Model A+

Raspberry Pi __ 1 MIcroUSB 5.1V at Mini-HDMI, GPIO Composite


Zero Wireless 1.2A
with Headers

Raspberry Pi __ 1 MIcroUSB 5.1V at Mini-HDMI, GPIO Composite


Zero Wireless 1.2A

Raspberry Pi __ 1 MIcroUSB 5.1V at Mini-HDMI, GPIO Composite


Zero 1.2A

Raspberry Pi 4 USB2.0 1 MIcroUSB 5.1V at HDMI, Composite (TRRS)


2 Model B 1.8A

Raspberry Pi 4 USB2.0 1 MIcroUSB 5.1V at HDMI, Composite (TRRS)


1 Model B + 1.2A

Raspberry Pi 2 USB2.0 1 MIcroUSB 5.1V at 3A PAL and NTSC, HDMI or DSI,


1 Model B RCA

Raspberry Pi 1 USB2.0 1 MicroUSB or 5.1V at HDMI, Composite (TRRS)


1 Model A+ GPIO 700mA

Raspberry Pi 1 1 MicroUSB or 5.1V at PAL and NTSC, HDMI


1 Model A USB2.0 GPIO 700mA or DSI, RCA

Page | 36
The table below gives the connectivity specifications of various Raspberry Pi boards
focusing on the version‟s video out quality, video in, Ethernet, bluetooth, Wi-Fi and
external storage –

Raspberry Video Out Video In Ethernet Bluetooth Wi-Fi External Storage


Pi Version Quality

Raspberry 4kp60 CSI Camera Gigabit Bluetooth 5.0 Dual Band- MicroSD
Pi 4 Connector Ethernet 2.4 GHz and
Model B 5GHz

Raspberry 1080p60 CSI Camera 10/100 Bluetooth Dual Band- MicroSD


Pi 3 Connector Mbit/s 4.2/BLE 2.4 GHz and
Model B+ 5GHz

Raspberry 1080p60 CSI Camera 10/100 Bluetooth 4.1 2.4 GHz MicroSD
Pi 3 Connector Mbit/s
Model B

Raspberry 1080p60 CSI Camera ___ Bluetooth Dual Band- MicroSD


Pi 3 Connector 4.2/BLE 2.4 GHz and
Model A+ 5GHz

Raspberry 1080p60 CSI Camera ___ Bluetooth 4.1 2.4 GHz MicroSD
Pi Zero Connector
Wireless
with
Headers

Raspberry 1080p60 CSI Camera ___ Bluetooth 4.1 2.4 GHz MicroSD
Pi Zero Connector
Wireless

Raspberry 1080p60 CSI Camera ___ ___ ___ MicroSD


Pi Zero Connector

Raspberry 1080p60 CSI Camera 10/100 ___ ___ MicroSD


Pi 2 Connector Mbit/s
Model B

Page | 37
Raspberry 1080p60 CSI Camera 10/100 ___ ___ MicroSD
Pi 1 Connector Mbit/s
Model B
+

EXAMPLE: Countdown time in Python


import time
def countdown(time_sec):
while time_sec:
mins, secs = divmod(time_sec, 60)
timeformat = '{:02d}:{:02d}'.format(mins, secs)
print(timeformat, end='\r')
time.sleep(1)
time_sec -= 1
print("stop")
countdown(5)

RESULT:

Thus the introduction to raspberry pi platform and python programming was studied
successfully.
Page | 38
INTERFACING SENSORS WITH RASPBERRY PI

EXP NO: 8

DATE :

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.

Circuit Diagram
The following image shows the connection diagram of Interfacing IR Sensor with Raspberry Pi.
You have already seen the circuit diagram of the IR Sensor Module.

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.

Page | 39
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.

Code
The following is the code for interfacing IR Sensor with Raspberry Pi. It is written in Python.

import RPi.GPIO as GPIO


import time

sensor = 16
buzzer = 18

GPIO.setmode(GPIO.BOARD)
GPIO.setup(sensor,GPIO.IN)
GPIO.setup(buzzer,GPIO.OUT)

GPIO.output(buzzer,False)
print "IR Sensor Ready....."
print " "

try:
while True:
if GPIO.input(sensor):
GPIO.output(buzzer,True)
print "Object Detected"
while GPIO.input(sensor):
time.sleep(0.2)
else:
GPIO.output(buzzer,False)

except KeyboardInterrupt:
GPIO.cleanup()

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.

Page | 40
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
 Mobile Proximity Sensor

RESULT:

Thus the Interfacing Sensors with Raspberry Pi was studied successfully

Page | 41
COMMUNICATE BETWEEN ARDUINO AND RASPBERRY PI USING ANY
WIRELESS MEDIUM
EXP NO: 9

DATE :

1. Summary:
 The process of how to communicate an Arduino and a Raspberry Pi with nRF24L01 module.
To Start off We will be learning Some basics of Raspberry Pi then we will have a look at
Headless Raspberry Pi setup. For the Implementation firstly, we will understand the simple
communication of Arduino to Arduino then we will learn Arduino to the raspberry pi.

2. Required Components:
 Ultrasonic Sensor
 2 Arduino Uno
 Raspberry Pi 3
 2 nRF24l01 transmitter and receiver
 Jump wires
 Arduino cable
 MINI USB 2.0 for Pi
 Breadboard

3. Required Software:
 Raspbian for pi
 Arduino IDE or Visual Studio
 Putty on a remote computer for SSH
 VNC viewer on a remote computer

4. Introduction to Raspberry Pi 3:

Page | 42
4.1. Components Specifications:
 1.4 GHz 64-bit quad-core ARM Cortex-A53, 1GB RAM
 2.4/5Ghz dual-band 802.11ac Wireless LAN, 10/100/1000Mbps Ethernet Bluetooth 4.2
 4 USB ports, Full HDMI port, Combined 3.5mm audio jack and composite video port,
40 GPIO pins
 Micro SD card slot, Video Core IV 3D graphics core, Camera interface (CSI), Display
interface (DSI)
4.2 Raspberry Pi Pinout:

Page | 43
4.3. Headless Raspberry Pi Setup:
 Say, I just bought a raspberry pi and wish to check out how it works. But all I have is
my Laptop, the Pi, a micro SD card, and my Wi-Fi network. How do I connect and
control the Pi?
1) Download Raspbian:
 Your Pi needs an OS. Download Raspbian from Raspberrypi.org „s download section:
 https://www.raspberrypi.org/downloads/raspbian/

2) Download SD Memory Card Formatter:


 It is used to format the SD card as it is needed that the SD card should be empty before
the flashing image you downloaded. You can download it
from https://www.sdcard.org/downloads/formatter/eula_windows/

3) Flash it onto an SD card:


 You need to flash this downloaded image to the micro SD card. Assuming your laptop
has an SD card slot or a micro Sd card reader, you need a flashing software like etcher.
Go ahead and download from https://etcher.io/

Page | 44
4) Configure Wi-Fi:
 It‟s easier to make two devices talk to each other if they are in the same network. An
ethernet cable can easily make your laptop‟s network available to the Pi. But we don‟t
have one. So, we are going to add a file to the SD card so that the Pi boots with a wifi
pre-configured.
 The SD card mounts as two volumes boot and rootfs . Open the boot volume and create
a file named wpa_supplicant.conf on booting the RPi, this file will be copied to
/etc/wpa_supplicant directory in /rootfs partition. The copied file tells the Pi the WIFI
setup information. This would overwrite any existing WIFI configuration, so if you had
already configured WIFI on the pi, then that will be overwritten.
 A typical wpa_supplicant.conf file is as follows:
ctrl_interface=DIR=/var/run/wpa_supplicant
GROUP=netdevupdate_config=1country=US
network={ ssid="«your_SSID»" psk="«your_PSK»" key_mgmt=WPA-PSK}
NOTE: Your SSID is your WIFI‟s name. And psk is the password of the WI-FI.
5) Enable SSH
 We will later access the Pi using a secured shell (SSH), SSH is disabled by default in
Raspbian. To enable SSH, create a file named ssh in the boot partition. If you are on
Linux, use the touch command to do that.

Page | 45
6) Find Pi‟s Ip address:
 Before switching on your raspberry pi, we need to find out the existing devices
connected to the network. Make sure your laptop is connected to the same WIFI
network as the one you configured on pi above.
 Download the Advanced IP Scanner to scan the IP of our raspberry pi. You can
download it from here https://www.advanced-ip-scanner.com/

7) SSH into your Pi:


 To create a secured shell connection in Linux we can use the ssh command. If you are
on windows, try downloading Putty from https://www.putty.org/

Page | 46
Default credentials are:
username: pipassword: raspberry

8) Access Pi remotely:
 Sometimes it doesn‟t feel right if we can‟t use the mouse. For that, we need to look into
the Raspbian desktop.
 We need to setup VNC (Virtual Network Connection) to see and control Pi graphically.
Let‟s do that.
 To access the remote desktop, you need VNC-viewer (client) for your laptop.
Fortunately, RealVNC is available for a lot of OSes, pick one for your OS
from https://www.realvnc.com/en/connect/download/viewer/
9) Commands for vncserver:

Page | 47
10) Now open VNC Viewer on your remote computer:

Page | 48
5. Implementation and Working:

5.1. Wireless communication of Arduino to Arduino with nRF24L01:


 In this, we will learn how to make wireless communication between two Arduino
boards using the NRF24L01. And measure distance with ultrasonic sensor and transmit
it to another Arduino with transceiver module.
Wiring Instructions:
To wire your NRF24L01+ wireless Sender to your Arduino, connect the following pins:
 Connect the VCC pin to 3.3 Volts
 Connect the GND pin to ground (GND)
 Connect the CE pin to Arduino 9
 Connect the CSN pin to Arduino 10
 Connect the SCK pin to Arduino 13
 Connect the MOSI pin to Arduino 11
 Connect the MISO pin to Arduino 12
To wire your ultrasonic sensor to your Arduino, connect the following pins:
 Connect the VCC pin to Arduino 5Volts
 Connect the GND pin to ground (GND)
 Connect the Trig pin to Arduino 4
 Connect the Echo pin to Arduino 3

Schematic Diagram for wiring of Arduino Uno with ultrasonic sensor and NRF24L01
To wire your NRF24L01+ wireless sender to your Arduino, connect the following pins:
 Connect the VCC pin to 3.3 Volts
 Connect the GND pin to ground (GND)
Page | 49
 Connect the CE pin to Arduino 9
 Connect the CSN pin to Arduino 10
 Connect the SCK pin to Arduino 13
 Connect the MOSI pin to Arduino 11
 Connect the MISO pin to Arduino 12

Schematic Diagram for wiring of Arduino Uno NRF24L01


NOTE: RF24 module is mandatory for the code to run so you can add the library
accordingly
 Start Arduino IDE then add the Downloaded Library from Here :

Page | 50
5.2. Code:
Sender Side code:
Receiver Side code:
Sending the Data

Page | 51
Receiving the data:

6. Wireless communication of Arduino to Raspberry Pi with nRF24L01:


6.1: Installation of RF24 Module on Raspberry Pi:
 It is the most important and foremost step for any Communication to work between
Arduino and Raspberry Pi as we have used RF24 library in Arduino for communication
so the same Library is needed on Pi.

Page | 52
 Further are the steps to which involve the installation of the Library. It took me almost
one week to install it as no clear idea about it is present.
=> Way to go:
1. Login to Raspberry Pi using Putty.
2. Go to the VNC server for GUI.
3. In the terminal type:
sudo raspi-config

Turn on SPI from Interfacing options in config

4. Reboot the Pi. In the terminal, type:


sudo reboot
Page | 53
5. In the terminal type:
sudo apt-get update
6. Download the install.sh file
from http://tmrh20.github.io/RF24Installer/RPi/install.sh or Run this on terminal:
wget http://tmrh20.github.io/RF24Installer/RPi/install.sh
7. Make it executable:
chmod +x install.sh
8. Run it and choose your options:

9. Run an example from one of the libraries: cdrf24libs/RF24/examples_linux


make
sudo ./gettingstarted
Run Following Commands to run the program.
10. Further, if we want to run Python Programs for the same purpose, we can do this:
Running the Example Edit the pingpair_dyn.py example to configure the appropriate
pins per the above documentation:
nano pingpair_dyn.py
 Configure another device, Arduino or RPi with the pingpair_dyn example
 Run the example
sudo python pingpair_dyn.py

Page | 54
6.2. Wireless communication of Arduino to Arduino with nRF24L01:
 In this, we will learn how to make wireless communication between Arduino and
Raspberry Pi using the NRF24L01. And measure distance with an ultrasonic sensor
with the help of Arduino Uno and transmit it to Raspberry Pi and Data is received.
Wiring Instructions:
To wire your NRF24L01+ wireless Sender to your Arduino, connect the following pins:
 Connect the VCC pin to 3.3 Volts
 Connect the GND pin to ground (GND)
 Connect the CSN pin to Arduino 10
 Connect the CE pin to Arduino 9
 Connect the SCK pin to Arduino 13
 Connect the MISO pin to Arduino 12
 Connect the MOSI pin to Arduino 11
To wire your ultrasonic sensor to your Arduino, connect the following pins:
 Connect the VCC pin to Arduino 5Volts
 Connect the GND pin to ground (GND)
 Connect the Trig pin to Arduino 4
 Connect the Echo pin to Arduino 3
Schematic Diagram:

Page | 55
Schematic Diagram for wiring of Arduino Uno with ultrasonic sensor and NRF24L01
To wire your NRF24L01+ Wireless Receiver to your Raspberry Pi, connect the
following pins:
 Connect the VCC pin to 3.3 Volts (Pin 1)
 Connect the GND pin to ground (GND) (Pin 6)
 Connect the CE pin to Raspberry GPIO 22
 Connect the CSN pin to Raspberry GPIO 8
 Connect the SCK pin to Raspberry GPIO 11
 Connect the MOSI pin to Raspberry GPIO 10
 Connect the MISO pin to Raspberry GPIO 09
Schematic Diagram:

Page | 56
Schematic Diagram for wiring of Raspberry Pi and NRF24L01
6.3. Code:
Sender Side Code:
Receiver Side Code:
 It's not mandatory to use this code as it is tweaked by me as per my requirement.
To check the proper functioning of your connection and code you can run the examples
present in the library like pingpair_dyn.ino on your Arduino and pingpair_dyn.py on
Raspberry Pi
 The snippet of my running communication:

Page | 57
RESULT:

Thus the communicate between arduino and Raspberry Pi Using Any Wireless Medium was
successfully studied.

Page | 58
LOG DATA USING RASPBERRY PI AND UPLOAD TO THE CLOUD PLATFORM

EXP NO: 11

DATE :

ThingSpeak is an open IoT platform for monitoring your data online. In ThingSpeak
channel you can set the data as private or public according to your choice. ThingSpeak takes
minimum of 15 seconds to update your readings. Its a great and very easy to use platform for
building IOT projects.
There are also some other platforms available for monitoring your data online which we will
cover in later articles but there are some advantages of ThingSpeak over other platforms like it
is very easy to set up and it also has many options to plot graph.
Components Required

1. Raspberry Pi
2. Power Cable
3. WiFi or Internet

Steps for building Raspberry Pi Data Logger on Cloud

Step 1: Signup for ThingSpeak


For creating your channel on ThingSpeak you first need to sign up on ThingSpeak. In case if
you already have account on ThingSpeak just sign in using your id and password.
For creating your account go to www.thinspeak.com

Page | 67
Click on signup if you don‟t have account and if you already have account click on sign in.
After clicking on signup fill your details.

After this verify your E-mail id and click on continue.

Step 2: Create a Channel for Your Data


Once you Sign in after your account verification, Create a new channel by clicking “New
Channel” button

After clicking on “New Channel”, enter the Name and Description of the data you want to
upload on this channel. For example I am sending my CPU data (temperature), so I named it as
CPU data.

Page | 68
Now enter the name of your data (like Temperature or pressure) in Field1. If you want to use
more than one Field you can check the box next to Field option and enter the name and
description of your data.
After this click on save channel button to save your details.

Step 3: Getting API Key in ThingSpeak


To send data to ThingSpeak, we need an unique API key, which we will use later in our python
code to upload our CPU data to ThingSpeak Website.
Click on “API Keys” button to get your unique API key for uploading your CPU data.

Now copy your “Write API Key”. We will use this API key in our code.

Step 4: Python Code for Raspberry Pi


Complete code is given at the end of this tutorial, just make a file with any name and .py
extension and copy-paste the code and save the file. Don‟t forget to replace the API key with
yours. You can run the python file any time using below command:

python /path/filename.py

Page | 69
Assuming you already installed python in Raspberry pi using this command

sudo apt-get install python

Case 1: If you are using monitor screen then just use the given code.
Now install all libraries:

sudo apt-get install httplib


sudo apt-get install urllib

After installing libraries run your python code (python /path/filename.py)


If the code runs properly you will see some CPU temperature values as shown in below image.

If there are any errors uploading the data, you will receive “connection failed” message.

Case 2: If you are using “Putty” then you should follow these commands:
First update your pi using:

sudo apt-get update

Page | 70
After this make a file cpu.py using:

nano cpu.py

After creating this file copy your code to this file and save it using CTRL + X and then „y‟ and
Enter.
After this install all libraries using:

sudo apt-get install httplib


sudo apt-get install urllib

After installing libraries run your python code using:

python cpu.py

If the code runs properly you will see some CPU temperature values as shown in above image.

Step 6: Check ThingSpeak site for Data Logging


After completing these steps open your channel and you will see the CPU temperature data is
updating into ThingSpeak website.

Page | 71
Like this you can send any sensor data connected with Raspberry pi to the ThingSpeak Cloud.
In next article we will connect LM35 temperature sensor with Raspberry Pi and send the
temperature data to ThingSpeak, which can be monitored from anywhere.
Complete Python code for this Raspberry Pi Cloud Server is given below. Code is easy and
self-explanatory to understand.

Code

import httplib
import urllib

import time

key = "ABCD" # Put your API Key here

def thermometer():

while True:

#Calculate CPU temperature of Raspberry Pi in Degrees C

Page | 72
temp = int(open('/sys/class/thermal/thermal_zone0/temp').read()) / 1e3 # Get Raspberry Pi
CPU temp

params = urllib.urlencode({'field1': temp, 'key':key })

headers = {"Content-typZZe": "application/x-www-form-urlencoded","Accept":


"text/plain"}

conn = httplib.HTTPConnection("api.thingspeak.com:80")

try:

conn.request("POST", "/update", params, headers)

response = conn.getresponse()

print temp

print response.status, response.reason

data = response.read()

conn.close()

except:

print "connection failed"

break

if __name__ == "__main__":

while True:

thermometer()

RESULT:

Thus the Log Data Using Raspberry Pi and Upload to The Cloud Platform was studied
successfully

Page | 73
DESIGN AN IOT BASED SYSTEM

EXP NO: 12

DATE :

Steps to Astounding Internet of Things Design


It would take an entire book to cover this topic. In that regard, we won‟t go into describing the
details of each step. Instead, we will help you get a comprehensive picture of what Internet of
Things design is all about.

#1 Step: All great projects start with research


The first step is a pre-development stage when you identify some challenges other people have
and understand the way IoT can address these challenges. This step is also called business
analysis, discovery phase, market research, or conceptual stage. You need to understand what
needs your future solution meets, identify the audience and ways to reach them, create profiles
of your users, describe distribution channels, find partners, draft a financial plan, and much
more. You also need to browse the market and look at similar existing solutions. Consider
yourself a startup that needs to pass the first startup development stage.
#2 Step: Engineer ergonomic IoT devices
An IoT fleet is the backbone of the network. So you should carefully design, prototype, test,
and construct the device before going to mass production. It‟s a very tricky journey especially
if you plan to utilize several types of sensors and actuators. A device for final users (like
fitness trackers) must be ergonomic, and simple-in-use, while for industrial gadgets one of the
biggest challenges is battery life. It‟s also necessary to find a reliable device vendor that has
enough experience in IoT fleet management and production.
In addition to all of the above, you need to understand whether your solution is possible to
build using IoT devices. IoT affects various industries, and devices in some industries like
healthcare are very complicated since the accuracy of these devices must be close to 100%,
and interruptions in operation can lead to people‟s death – so it requires a lot of financing and
expertise. On the other side, if your idea is connected with Smart Homes, it will be much
easier to find a device manufacturer or build a device on your own. Balance your desires with
possibilities.
Page | 74
#3 Step: Carefully design an IoT architecture
To build an IoT architecture you can use the services of specialized companies
like SumatoSoft or hire a highly qualified IoT architect. Whatever you choose, always keep in
mind that this step is extremely important and you shouldn‟t save on it. The system logic and
key elements of the entire IoT ecosystem are defined here. Pay special attention to network
characteristics and technologies since they must cope with the traffic volume it carries. Define
the types of data that it is going to transmit: voice, video, pictures, text, etc. Dealing with IoT
traffic entails the presence of special network requirements.
#4 Step: IoT system development and fleet deployment
When the IoT fleet is ready to deploy, a comprehensive system to manage the IoT fleet is
needed. Using specialized platforms is the best way to develop such a system. Choosing a
platform provider, you should examine the technologies they support, the possibility to
register devices from different vendors that use different protocols, and the price of the
platform.
Before the fleet deployment, you need to create an instance of every device in the system,
record the information about each device, provide secure residentials for every device, set up
permissions and access rights, and much more. Device onboarding can become a tricky issue
without the right platform for IoT fleet management. While the right platform can increase
production throughput and help to achieve a fourfold increase in device provisioning
throughput.

Best IoT platforms are:


 HomeKit
 AWS IoT Device Management Services
 Azure IoT Suite
Page | 75
 Oracle IoT
In case you work with the mass market, an additional step here is building a fast and user-
friendly application. The application development lifecycle consists of designing and
prototyping, programming, testing, and releasing the application.
9 Best Internet of Things Design Principles

#1 Principle: Think of security in advance


Privacy and security issues are the key challenge for IoT products. Incorrect or insecure
software may open a network to hackers‟ attacks and data leakage. In addition, there is a need
to establish proper security update processes as a part of IoT update management to deploy
security patches effectively and quickly.
#2 Principle: Test in the real environment
The IoT fleet interacts with the environment which makes it vulnerable to all kinds of physical
effects like hits, rapid temperature drops, pests, etc. All these treats are hard to test in
laboratory conditions, so it‟s necessary to test devices in a real environment where they are
supposed to work further.
#3 Principle: Apply UX in device and application development
UX aims to provide a positive experience and helps to meet user needs and requirements. UX-
based IoT design brings great value to the final user and the IoT system.
#4 Principle: Provide the autonomy of devices during connection loss
The Internet of Things is about connectivity. However, there will be a time when the device
will disconnect from the network. The device should continue to work properly and transfer the
collected information when the connection will be restored.
#5 Principle: Place getaways close to the maximum number of devices

The location of gateways should be as close to the IoT fleet as possible. It‟s necessary to
provide a lower latency in their communication.
#6 Principle: The system should be easily scalable
The future growth of the IoT system directly depends on its opportunities to scale efficiently
and stay robust when the volume of data and the number of devices increase.
#7 Principle: Build trust in your system
Since the Internet of Things often deals with sensitive information, you need to build trust in
your system to acquire more users. Trust should become one of the core values.
#8 Principle: Deploy only working products
Once the connected devices are deployed, their replacement with a newer version will be an
almost impossible task to accomplish because of high costs. That means that one single error in
the fleet which is detected after the fleet deployment can lead to large financial losses. Due to
that, it‟s good to avoid untested hardware iterations and deploy only working products.

#9 Principle: Data management and analysis should be effective


IoT systems generate enormous volumes of information. This data will be useless until the
system learns how to transform data streams into valuable insights. It is up to effective data
management and analysis whether the IoT system will generate value or just become a data
warehouse.
Page | 76
The Significance of the Ethical Aspect in IoT Design
As IoT devices and applications become more prevalent, it‟s important to consider the ethical
implications of IoT design. Some key ethical considerations include privacy, security, data
ownership, and transparency.
For example, imagine a smart home security system that uses cameras and sensors to monitor a
family‟s activity. While the system may be effective in preventing theft or intruders, it could
also collect personal data about the family‟s daily routines and habits, which could be used for
nefarious purposes if it falls into the wrong hands.
How IoT engineers can address this issue:
1. Implement security measures: IoT designers should implement security measures such as
encryption and authentication to protect user data from unauthorized access.
2. Develop transparent data policies: IoT designers should develop transparent data policies that
clearly explain what data is being collected and how it will be used, as well as obtain user
consent before collecting any personal data.
3. Consider the impact on vulnerable populations: IoT designers should consider the potential
consequences of their designs, particularly for vulnerable populations such as children, the
elderly, or people with disabilities, and work to ensure that their products are accessible and
inclusive to all users.
4. Prioritize privacy by design: IoT designers should prioritize privacy by design, which involves
incorporating privacy considerations into the design process from the beginning, rather than as
an afterthought.
5. Educate users: IoT designers should provide clear and concise instructions on how to use their
products safely and securely, as well as provide resources for users to learn more about IoT
security and privacy best practices.
Great Internet of Things Design Examples

Building a great IoT design is not an easy task. However, we managed to find 3 breathtaking
examples that managed to follow our principles above.
Whistle – Better tech for better care
Whistle is an application that connects to the IoT device on a pet through the cellular network.
Its goal is to take care of the pets by providing precise data to their owners. The IoT device
monitors key behaviors like scratching, drinking, sleep, licking, and other activities. Then it
analyzes them and assigns a score to the pet‟s health. The scoring system leverages machine
Page | 77
learning methods and health stories from 100 000 + dogs to evaluate a pet‟s behavior and track
its wellness.
Keymitt – Smart locks for your doors
Keymitt offers smart door locks with voice assistance. The Keymitt application is very
convenient and user-friendly, and it is compatible with Android and iOS smartphones. This IoT
solution is much safer than ordinary door locks because it ensures privacy and secure access
thanks to real-time notifications of the owner. Moreover, smart locks have one great advantage
compared to traditional locks – your application is responsible for lock control, there is no need
to hold keys.
Curve – The smart GPS tracker
Curve is a smart GPS tracker that can be attached to almost anything. You can track your keys,
pets, or your favorite bag. Curve uses 4 different tracking technologies; GPS, Wi-Fi, Cellular
and Bluetooth so even if you‟re at home or outside, you‟ll have a reliable connection to
whatever you‟re trying to find.
August Smart Lock Pro – Key-free access to your home
The August Smart Lock Pro is a smart lock that allows users to remotely control their door
locks using their smartphones. It integrates with popular smart home platforms like Alexa and
Google Assistant, allowing users to lock and unlock their doors with voice commands. The
smart lock also includes a range of security features, such as two-factor authentication and
activity alerts, to ensure that the user‟s home is secure. The lock also allows users to provide
temporary access to guests or service providers through the August app, making it easy to grant
and revoke access as needed.

RESULT:

Thus the design an IOT based system was studied successfully

Page | 78

You might also like