OCS352 Lab
OCS352 Lab
R-2021
IV Semester
BONAFIDE CERTIFICATE
Certified that this is the bonafide record of the practical work done by
………...………………………………..……..…SPRNO……………………of IV
Semester / II Year B.E. – Electronics and Instrumentation Engineering in OCS352
– IoT Concepts and Applications during the academic year 2023-
2024.
DEPARTMENT OF ECE
VISION
To produce competent electronics and instrumentation engineers towards new
technology along with social responsible citizen.
MISSION
M1 To provide quality learning environment with well-defined teaching learning
process.
PEO 1 Engage in designing, manufacturing, operating and testing in the field of electronics
and instrumentation engineering and allied engineering industries.
PEO 2 Solve problems of social relevance by applying the knowledge of electronics and
instrumentation engineering and pursue higher education and research.
PSO 2 Design and build modern electronic systems for engineering applications.
PSO 3 Specify, select and formulate the instruments for industrial engineering environments
Total 10
4
CONTENTS
Ex.No Date Title Page No Initials
5
Ex.No.: 1 Introduction to Arduino platform and programming
Date:
Aim:
To study about the Arduino board and how to program it.
Theory:
6
Arduino Board Processor Memory Digital I/O Analogue I/O
2KB SRAM, 32KB
Arduino Uno 16Mhz ATmega328 flash 14 6 input, 0 output
96KB SRAM, 12 input, 2
Arduino Due 84MHz AT91SAM3X8E 512KB flash 54 output
8KB SRAM, 16 input, 0
Arduino Mega 16MHz ATmega2560 256KB flash 54 output
2.5KB SRAM, 12 input, 0
Arduino Leonardo 16MHz ATmega32u4 32KB flash 20 output
Arduino IDE
Programs written using Arduino Software (IDE) are called sketches. These sketches are
written in the text editor and are saved with the file extension .ino . The editor has
features for cutting/pasting and for searching/replacing text. The message area gives
feedback while saving and exporting and also displays errors. The console displays text
output by the Arduino Software (IDE), including complete error messages and other
information. The bottom righthand corner of the window displays the configured board and
serial port. The toolbar buttons allow you to verify and upload programs, create, open,
and save sketches, and open the serial monitor.
Before you can start doing anything in the Arduino programmer, you must set the board-
type and serial port.
7
After the sketch has been written, the next step is to upload it to the Arduino. To upload a
sketch, click the arrow button in the upper left side of the window. The IDE will then verify
your code by checking for any typos or syntax errors. If it finds an error, it will let you
know with an orange error message. If the code is correct and free of any errors, the IDE
will compile the sketch. Compiling is the process of converting human readable code like C
and C++ into machine readable code that the microcontroller can understand.
After the sketch has been compiled, the IDE transfers the code through the USB port to the
Arduino where it is saved in the ATMEGA328’s flash memory. The sketch starts running
right away and keeps running until the power is removed.
Result:
8
Ex.No.: 2 Interfacing Arduino to Temperature sensor and LCD Display
Date:
Aim:
To read the temperature and display it into the LCD Display using Arduino.
Apparatus Required
Procedure
Circuit
Connection Details
Arduino Board
//code//
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int celsius = 0;
int fahrenheit = 0;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode(A0, INPUT);
// Print a message to the LCD.
}
void loop() {
celsius = map(((analogRead(A0) - 20) * 3.04), 0, 1023, -40, 125);
fahrenheit = ((celsius * 9) / 5 + 32);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("C = ");
lcd.setCursor(5,0);
lcd.print(String(celsius));
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("F = ");
lcd.setCursor(5,1);
lcd.print(String(fahrenheit));
delay(1000);
}
Result:
Ex.No.: 3 Interfacing Arduino to Zigbee module
Date:
Aim:
To transmit and receive the data using Arduino with interfacing of Zigbee Module
Apparatus Required:
1. Arduino Uno Bard – 2 Nos.
2. Xbee Pro Module – 2 Nos.
3. Xbee Explorer / USB Adaptor Board – 1 No.
4. Adruion IDE
5. XCTU 6.11 Software
6. USB Cable
Procedure:
1. Download and install XCTU software on PC
2. Place the Xbee Module 1 in Xbee Adaptor board and connect to PC
3. Connect the Xbee module by select the correct port setting.
4. Now configure PAN ID and the radio as “coordinator”
5.
12
7. Make the connection as per the diagram
8. Connect the Arduino with PC
9. Write the program using IDE and download the sketch into board
Now run the transmitter and receiver programs
Circuit Diagram
13
Transmitter Program
#include <SoftwareSerial.h>
SoftwareSerial xbeeSerial(2,3); //RX, TX
void setup() {
Serial.begin(9600);
xbeeSerial.begin(9600);
}
void loop() {
if(Serial.available() > 0){
char input = Serial.read();
xbeeSerial.print(input);
}
}
Receiver Program
#include <SoftwareSerial.h>
SoftwareSerial xbeeSerial(2,3); //RX, TX
void setup() {
Serial.begin(9600);
xbeeSerial.begin(9600);
}
void loop() {
if(xbeeSerial.available() > 0){
char input = xbeeSerial.read();
Serial.print(input);
}
}
Result:
14
Ex.No.: 4 Interfacing Arduino to GSM module
Date:
Aim:
To develop a project to send or receive the message using GSM module with Arduino.
Apparatus Required
1. Arduino Uno R3
2. SIM 900 A GSM Module
3. 12v Power Adapter
4. Working SIM Card
5. Connecting Wires
Procedure
1. First, we will need to insert the SIM card onto the SIM card tray on the GSM module
and lock it
2. Connect the external antenna to the module, if not done already
3. Make the following connections between your Arduino and the GSM module
Note: We won’t be connecting VCC from the GSM module to the Arduino since the GSM
module will be directly powered by the 12V supply we plug into the barrel jack. But we will
connect GNDs to make the ground plane common between the two devices.
4. Once the connections are done, you can power on the GSM module by plugging in
your external 12V DC Jack
5. The onboard Network LED will initially blink rapidly. After a few minutes, the
blinking should slow down to a steady pace. This means the GSM module has
successfully been registered on the mobile network and is ready to be used
6. Programming Steps
15
Program
#include <SoftwareSerial.h>
SoftwareSerial Sim(9, 10);
void setup()
{
Sim.begin(9600); // Setting the baud rate of Sim
Module
Serial.begin(9600); // Setting the baud rate of
Serial Monitor (Arduino)
delay(100);
}
void loop()
{
if (Serial.available()>0)
switch(Serial.read()) // Read data given in Serial
Monitor
{
case 's': // If data is 's', goto
SendMessage() function
SendMessage();
break;
case 'r': // If data is 'r', goto
ReceiveMessage() function
ReceiveMessage();
break;
16
}
if (Sim.available()>0)
Serial.write(Sim.read()); // If SIM module sends messages,
print it to Serial monitor
}
void SendMessage()
{
Sim.println("AT+CMGF=1"); // Sets the Sim Module in send
SMS mode
delay(1000); // Delay of 1 second
Sim.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile number
delay(1000); // Delay of 1 second
Sim.println("I am SMS from Sim Module"); // Type in the SMS text you want
to send
delay(100); // Delay of 0.1 second
Sim.println((char)26); // ASCII code of CTRL+Z (to exit
out)
delay(1000); // Delay of 1 second
}
void ReceiveMessage()
{
Sim.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live
SMS
delay(1000); // Delay of 1 second
}
Result
17
Ex.No.: 5 Interfacing Arduino to Bluetooth module
Date:
Aim:
To develop a system to interface the Bluetooth module with Arduino board and receive
the message
Apparatus Required
1. Arduino Uno R3
2. HC-05 BT Module
3. Resistors 1k 2k
4. Breadboard
5. Bluetooth Terminal App on Mobile
6. Connecting Wires
Procedure
1. Connections are made as per the diagram
2. Write the program in Arduino IDE and download the sketch
3. Pair and connect the HC-05 module with Mobile phone
4. Open the BT terminal in Mobile phone
5. Send the message to Arduino
6. Check the serial monitor in IDE to display the message.
Circuit
18
Program
#include<SoftwareSerial.h>
void setup() {
bt.begin(9600); /* Define baud rate for software serial communication */
Serial.begin(9600); /* Define baud rate for serial communication */
}
void loop() {
Result
19
Ex.No.: 6 Introduction to Raspberry PI platform and python
programming
Date:
Aim:
To study about the Raspberry Pi Soc and python programming
Theory
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.
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.
The respective processes to connect your Raspberry Pi board to different devices is explained
below in detail. Let us begin by understanding how to connect a display device to your Pi
board.
Display device
Depending on the screen type, you have two ways to connect the display device to your Pi
board. In these two ways, we are assuming that you are going to use either monitor or
television. Apart from these two ways, there is an official Pi touchscreen that connects using
the display socket. Let us check how we can connect an HDMI display and television, as
explained below.
HDMI or DVI display
The HDMI connector is on the top surface of your Raspberry Pi board. But for the Raspberry
Pi Zero model, you need to use an adapter that converts Mini HDMI to an HDMI socket. For
connecting, insert one end of the HDMI cable in the board or Pi ZERO connector and the
other end into your monitor.
20
On the other hand, if you are using a DVI display, an adapter should be used.
Television
If the TV you are using is having a HDMI socket, you can use that for optimal results. But if
in case, your TV does not have an HDMI socket, you need to use the composite video socket.
On the Raspberry Pi Model-A and Model-B, the composite video socket is placed on the top
edge of the board. It is a round, yellow-and-silver sockets.
On other models, Raspberry Pi 3, Pi 2, and Model B+, the same socket as the audio output
can be used as a composite video socket. It is placed on the bottom of the board.
One thing you should note is that you will need to use a special RCA cable for this socket.
Connect one end of the RCA cable to the audio output socket and the other end to Video
in socket of the TV.
If you are using Pi Zero or Zero W boards then, you need to solder your own connector to the
board, where it is labelled TV. This should be done because, both these boards do not have
composite video socket.
Keyboard and Mouse
On Raspberry Pi Model B+, Model Pi 2, and Model Pi 3 the keyboard and mouse can be
directly connected. They should work fine. But for earlier models of Raspberry Pi, you
should use an external USB hub to connect keyboard and mouse.
Because with this, the devices will not draw too much power from the Pi board, and we can
reduce the risk of heat and other problems caused by devices.
On the other hand, for Raspberry Pi Zero, Model A, and Model A+, we must use a USB hub,
since these boards have only one USB socket.
Audio devices
Raspberry Pi’s audio socket is a small black or blue box. On Model A and Model B, it is
stuck along the top edge of the board. Whereas, on Model B+, Pi 2 and Pi 3, it is stuck along
the bottom edge of the board.
If you have connected an HDMI TV, then you do not need to connect a separate audio cable,
as the sound is routed through your HDMI cable.
On the other hand, if you have earphones or headphones with a 3.5mm jack, you can directly
plug them into the audio socket.
Raspbian
Raspbian, a version of a Linux distribution called Debian, is the distribution that is
recommended by the Raspberry Pi foundation. It has been optimized for the Raspberry Pi
board.
Most of the Raspberry Pi users start with Raspbian and it includes −
RISC OS
It is an alternative to Linux OS, which most of the people use on the Raspberry Pi. It has a
GUI (Graphical User Interface). In 1987, it was created by Acorn Computers and now-a-
days, it is maintained and managed by RISC OS open Limited.
Data Partition
If you use the Data Partition option, it will give you an option to sort the data. The sorted data
can be accessed by various Linux distributions.
Lakka
It is a retro gaming system that includes emulators for a range of vintage home computers
such as Commodore 64 and Amiga, Amstrad CPC, ZX Spectrum and various Atari machines.
22
It also includes emulators for a range of game consoles such as Nintendo machines and Sony
PlayStation. Although the Bomberman clones and 2048 games are included but, if you want
to use Lakka, you need to get the games separately.
Plug your USB with games files and you will be ready to get games into Lakka.
Screenly OSE
As the name implies, it is a digital signage system. It enables the users to use a Raspberry Pi
with a connected HD screen as a digital sign. Here, OSE refers to Open Source Edition.
It enables the following to be displayed on the screen −
Videos
Images
Web pages
Windows 10 IoT Core
As the name implies, it is the version of Windows which is designed to support the IoT
(Internet of things) devices. It is actually different from the windows desktop experience we
are familiar with.
THONNY IDE
Thonny is the perfect IDE for Pi if you want to code in Python. It's easy to use and comes
with Python 3.7 built-in. If you're new to Python and want to create a basic program with it,
Thonny offers a clean, vanilla interface. This helps to ensure that you don't get bogged down
with all the fancy features — like the ones found on most IDEs — and focus on getting your
code right. As an IDE, Thonny comes with a debugger to help you detect and correct errors
in your code. It has features like expression evaluation, scope explaining, syntax highlighting,
and code completion, which add convenience and improve your coding experience.
Similar to other IDEs, Thonny also supports plugins so that you can get more functionalities
onboard.
Thonny IDE comes pre-installed with the Raspberry Pi OS desktop version. If you're running
any other version of Pi OS, you can install it with:
Result:
23
Ex.No.: 7 Interfacing sensors to Raspberry PI
Date:
Aim:
To measure the distance using Raspberry Pi interface with Ultrasonic distance sensor
Apparatus Required
1. Raspberry Pi 3 Model B
2. HC-SR04 Ultrasonic Sensor
3. 680 Ω Resistor (1/4 Watt)
4. 1.5 KΩ Resistor (1/4 Watt)
5. Connecting Wires
6. Mini Breadboard
Procedure:
The Ultrasonic Transmitter in the Sensor generates a 40 KHz Ultrasound. This signal then
propagates through air and if there is any obstacle in its path, the signal hits the object and
bounces back. This bounced signal is then collected by the Ultrasonic Receiver. Based on the
signal’s time of travel, you can calculate the distance of the object as you already know the
speed of sound. The Ultrasonic Transmitter, will transmits a burst of 8-pulses of ultrasound
at 40 KHz. Immediately, the control circuit in the sensor will change the state of the ECHO
pin to HIGH. This pins stays HIGH until the ultrasound hits an object and returns to the
Ultrasonic Receiver. Based on the Time for which the Echo Pin stays HIGH, you can
calculate the distance between the sensor and the object. For example, if we calculated the
time for which ECHO is HIGH as 588µS, then you can calculate the distance with the help of
the speed of sound, which is equal to 340m/s.
24
Program
GPIO.setmode(GPIO.BOARD)
TRIG = 16
ECHO = 18
i=0
GPIO.setup(TRIG,GPIO.OUT)
GPIO.setup(ECHO,GPIO.IN)
GPIO.output(TRIG, False)
print "Calibrating....."
time.sleep(2)
try:
while True:
GPIO.output(TRIG, True)
time.sleep(0.00001)
GPIO.output(TRIG, False)
while GPIO.input(ECHO)==0:
pulse_start = time.time()
25
while GPIO.input(ECHO)==1:
pulse_end = time.time()
distance = round(distance+1.15, 2)
except KeyboardInterrupt:
GPIO.cleanup()
Result:
26
Ex.No.: 8 Communicate between Arduino and Raspberry PI using any
wireless medium
Date:
Aim:
To develop the communication between Arduino uno and Raspberry Pi via Bluetooth
module.
Apparatus Required
1. Raspberry Pi Board
2. Arduino Uno R3
3. HC-05 BT Module
4. Resistors 1K 2K
5. Breadboard
6. Connecting Wires
Circuit Diagram
Procedure
27
sudo apt-get install pi-bluetooth
sudo apt-get install bluetooth bluez blueman
Program
Arduino Code:
28
}
}
void blinkLED(int inputVal)
{ for (int i=0; i< inputVal; i++)
{ digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}
}
import serial
import time
port = serial.Serial("/dev/rfcomm0", baudrate=9600)
Result:
29
Ex.No.: 9 Setup a cloud platform to log the data
Date:
Aim:
To setup Thinkspeak cloud for IoT Applications
Apparatus Required:
1. PC With Internet Connection
2. Matlab Login
Procedure
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
30
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.
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.
python /path/filename.py
31
Now copy your “Write API Key”. We will use this API key in our code.
Case 1: If you are using monitor screen then just use the given code.
Now install all libraries:
Case 2: If you are using “Putty” then you should follow these commands:
First update your pi using:
32
sudo apt-get update
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:
python cpu.py
33
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
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")
34
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:
35
Ex.No.: 10 Log Data using Raspberry PI and upload to the cloud platform
Date:
Aim:
To send the room temperature to cloud using raspberry pi
Apparatus Required:
1. Raspberry Pi
2. DHT11 sensor
3. Connecting Cables
Procedure
36
Program
import thingspeak
import time
import Adafruit_DHT
channel_id = 1391845 # put here the ID of the channel you created before
write_key = 'TNXXJJII892UHJ1C' # update the "WRITE KEY"
pin = 4
sensor = Adafruit_DHT.DHT11
def measure(channel):
try:
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
print('Temperature = {0:0.1f}*C Humidity = {1:0.1f}%'.format(temperature,
humidity))
else:
print('Did not receive any reading from sensor. Please check!')
# update the value
response = channel.update({'field1': temperature, 'field2': humidity})
except:
print("connection failure")
Result:
37
PROGRAM OUTCOMES
PO8- Ethics
PO10- Communication
RBT LEVELS
K1 - Remembering
K2 - Understanding
K3 - Applying
K4 - Analyzing
K5 - Evaluating
K6 - Creating
38