IOT Lab Manual
IOT Lab Manual
EMBEDDED SYSTEMS
AND IOT
1
2
TABLE OF CONTENTS
3. Introduction to Arduino 25
platform and programming
Introduction to Raspberry pi
5. platform and python 34
programming
Interfacing Sensors with
6. 38
Raspberry PI
Setup a cloud platform to log
7. 41
the data
3
Ex. No:1
Date: 8501 simple programs
Aim:
To write 8051 assembly language experiments using ride software.
Launch RIDE:
After installation, launch the RIDE software from the desktop shortcut or from the installation
directory.
Configure RIDE:
Once RIDE is launched, configure the software according to your microcontroller specifications.
This may involve selecting the correct microcontroller model, setting communication parameters,
and specifying the programming method (e.g., ISP, JTAG).
Write/Load Program:
Write your program in the integrated development environment (IDE) provided by RIDE.
Alternatively, if you already have a program written, load it into the IDE.
Compile Program:
After writing or loading your program, compile it within the RIDE environment. This step checks
for syntax errors and generates the corresponding machine code.
4
Arithmetic operations:
Addition
Algorithm:
Step1: Initialize ports p0 and p1 as input ports.
Step2: Initialize ports p2 and p3 as output ports.
Step3: Initialize the r1 register.
Step4: Move the contents from port 0 to b.
Step5: Move the contents from port 1 to a.
Step6: Add contents in a and b.
Step7: If carry is present increment r1.
Step8: Move contents in r1 to port 2.
Step9: Move the sum to port 3.
Program:
Software code:
$include(reg51.inc);
Mov a,#02h;
Mov b,#03h;
Add a,b;
Mov dptr,#4500h;
Mov @dptr,a;
L: sjmp
5
8051 Microcontroller code:
Origin:4100
Mov a,#44
Add a,#44
Mov dptr,#4500
Movx @dptr,a
Sjmp 4108
#go 4100
Output:
Subtraction:
Algorithm:
Step1: Clear c register for carry.
Step2: Get the data immediately.
Step3: Subtract the two data.
Step4: Store the result in memory pointed by dptr.
Program:
Software code:
$include(reg51.inc);
Mov a,#04h;
Mov b,#03h;
6
Subb a,b;
Mov dptr,#4500h;
Mov @dptr,a;
L: sjmp l
Output
Multiplication:
Algorithm:
Step1: Clear c register for carry.
Step2: Get the data immediately.
Step3: Multiply the two data.
Step4: Store the result in memory pointed by dptr.
7
Program:
Software code:
$include(reg51.inc);
Mov a,#03h;
Mov b,#02h;
Mul a,b;
Mov dptr,#4500h;
Mov @dptr,a;
L: sjmp l
Output
8
Division:
Algorithm:
Step1: Clear c register for carry.
Step2: Get the data immediately.
Step3: Divide the two data.
Step4: Store the result in memory pointed by dptr.
Program:
Software code:
$include(reg51.inc);
Mov a,#04h;
Mov b,#02h;
Div a,b;
Mov dptr,#4500h;
Mov @dptr,a;
L: sjmp l
9
Output:
Logical operators:
OR:
Step 1: Clear c
Step 2: Get the two data
Step 3: Perform or operation on two data
Step 4: Store the result in memory pointed by dptr.
Program:
Software code:
$include(reg51.inc)
Mov a,#04h;
Mov b,#02h;
Orl a,b;
Mov dptr,#4500h;
Movx @dptr,a;
L:sjmp l
10
Orl a,#2;
Mov dptr,#4500;
Movx @dptr,a;
Sjmp 4108;
#go 4100
Output:
And:
Step 1: Clear c
Step 2: Get the two data
Step 3: Perform and operation on two data
Step 4: Store the result in memory pointed by dptr.
Program:
Software code:
$include(reg51.inc)
Mov a,#04h;
Mov b,#02h;
Anl a,b;
Mov dptr,#4500h;
Movx @dptr,a;
L:sjmp l
Output:
XOR:
Step 1: Clear c
Step 2: Get the two data
Step 3: Perform XOR operation on two data
Step 4: Store the result in memory pointed by dptr.
Software code:
$include(reg51.inc)
Mov a,#04h;
Mov b,#02h;
Xrl a,b;
Mov dptr,#4500h;
Movx @dptr,a;
12
L:sjmp l
8051 Microcontroller code:
Origin :4100;
Mov a,#3;
Orl a,#2;
Mov dptr,#4500;
Movx @dptr,a;
Sjmp 4108;
#go 4100
Output:
Complement:
Step 1: Clear c
Step 2: Get the two data
Step 3: Complement the data
Step 4: Store the result in memory pointed by dptr.
Program:
Software code:
$include(reg51.inc)
13
Mov a,#03h;
Crl a,b;
Mov dptr,#4500h;
Movx @dptr,a;
L:sjmp l
Output:
14
Result:
Thus the assembly language programs are written, executed and the output was verified.
15
Ex. No:2
Date: Arithmetic Programs Using Embedded C
Aim:
To write and perform arithmetic operations Using Embedded C
Addition
Algorithm:
Step 1: Initialize register a,b
Step2: Add the contents a and b
Step3: Set the data pointer dptr to the memory address 4500h
Step4: Moves the value stored in register a to the memory location .
Program:
#include<reg51.h>
void main()
{
unsigned int a,b,c;
a=0X03;
b=0X02;
c=a-b;
P1=c;
}
Output:
16
Subtraction
Algorithm:
Step 1: Initialize register a,b
Step 2: Subtract the contents a and b
Step 3: Set the data pointer dptr to the memory address 4500h
Step 4: Moves the value stored in register a to the memory location
Program:
#include<reg51.h>
void main()
{
unsigned int a,b,c;
a=0X03;
b=0X02;
c=a-b;
P1=c;
}
Output:
17
Multiplication
Algorithm:
Step 1: Initialize register a,b
Step2: Multiply the contents a and b
Step3: Sets the data pointer dptr to the memory address 4500h
Step4: Moves the value stored in register a to the
Program:
#include<reg51.h>
void main()
{
unsigned int a,b,c;
a=0X03;
b=0X02;
c=a*b;
P1=c;
}
Output:
18
Division
Algorithm:
Step 1: Initialize register a,b
Step2: Divide the two data
Step3: Sets the data pointer dptr to the memory address 4500h
Step4: Moves the value stored in register a to the memory location
Program:
#include<reg51.h>
void main()
{
unsigned int a,b,c;
a=0X03;
b=0X02;
c=a/b;
P1=c;
}
Output:
19
Logical operations:
OR:
Algorithm:
Step1: Get two data immediately.
Step2: Perform or operation on two data.
Step3: Sets the data pointer dptr to the memory address 4500h
Step4: Moves the value stored in register a to the memory location
Program:
$include(reg51.inc)
Mov a,#06h;
Mov b,#02h;
Orl a,b;
Mov dptr,#4500h;
Movx @dptr,a;
L: sjmp l
Output:
20
AND:
Algorithm:
Step1: Get two data immediately.
Step2: Perform and operation on two data.
Step3: Sets the data pointer dptr to the memory address 4500h
Step4: Moves the value stored in register a to the memory location
Program:
$include(reg51.inc);
Mov a,#06h;
Mov b,#02h;
Anl a,b;
Mov dptr,#4500h;
Movx @dptr,a;
L: sjmp l
Output:
21
XOR:
Algorithm:
Step1: Get two data immediately.
Step2: Perform xor operation on two data.
Step3: Set the data pointer dptr to the memory address 4500h
Step4: Moves the value stored in register a to the memory location
Program:
$include(reg51.inc)
Mov a,#03h;
Mov b,#02h;
Xrl a,b;
Mov dptr,#4500h;
Movx @dptr,a;
L: sjmp l
Output:
22
Complement:
Algorithm:
Step1: Initialize register a.
Step2: Complement the data.
Step3: Sets the data pointer dptr to the memory address 4500h
Step4: Moves the value stored in register a to the memory location
Program:
$include(reg51.inc)
Mov a,#05h;
Cpl a;
Mov dptr,#4500h;
Movx @dptr,a;
L: sjmp l
Output:
23
Result:
Thus the arithmetic logic unit operations was written, executed and output was verified
successfully.
24
Ex. No:3
Date: Introduction to Arduino platform and programming
LED blink:
Aim:
To write a program to make the led blink using Arduino.
Algorithm:
Step1: Start
Step2: Initialize the led pin
Step3: Turn on the led x wait for a second
Step 4: Turn off led x wait for a second
Step 5: Stop
Program:
const int ledpin=13;
Void setup(){
Pinmode(ledpin, output);
}
Void loop(){
Digitalwrite(ledpin, high);
Delay(1000);
Digitalwrite(ledpin, low);
Delay(1000);
}
Output:
Result:
Thus, the program to make the led blink using Arduino was developed successfully
25
Light sensor:
Aim:
To write a program to detect light using light sensor and Arduino.
Algorithm:
Step 1: Start.
Step 2: Initialize the digital pin.
Step 3: Read the analog value to the sensor.
Step 4: Display the amount of brightness based on the analog value.
Step 5: Stop.
Program:
void setup()
{
Serial.begin(9600);
}
Void loop()
{
Int analogvalue = analogread(a0);
Serial.print("analog reading = ");
Serial.print(analogvalue);
If (analogvalue < 100)
{
Serial.println(" - very bright");
}
Else if (analogvalue < 200)
{
Serial.println(" - bright");
}
Else if (analogvalue < 500)
{
Serial.println(" - light");
}
Else if (analogvalue < 800)
{
Serial.println(" - dim");
}
Else
{
Serial.println(" - dark");
}
Delay(500);
}
26
Output:
Result:
Thus the program detect light using LDR sensor and arduino was developed
successfully.
27
Temperature sensor
Aim:
To write a program to detect temperature using temperature sensor and
Arduino.
Algorithm:
Step 1: Start.
Step 2: Initialize the digital pin.
Step 3: Read the analog value to the sensor.
Step 4: Read the temperature.
Step 5: Display the temperature using serial monitor.
Step 6: Stop.
Program:
Int val;
Int temppin=2;
Void setup()
Serial.begin(9600);
Void loop()
Serial.print("temprature = ");
Serial.print(cel);
Serial.print("*c");
Serial.println();
Delay(1000);
28
Output:
Result:
Thus the program to detect temperature using temperature sensor and Arduino
was developed successfully.
29
LED Fade:
Aim:
Algorithm:
Step 1: Start
Step 2: Initialize variables: led = 9, brightness = 0, fadeamount = 5
Step 3: Set up pin 9 as output to control the led brightness.
Step 4: Enter the loop routine.
Step 5: Set the brightness of pin 9 using analogwrite(led, brightness).
Step 6: Increment the brightness by fadeamount.
Step 7: Check if brightness is at its minimum (0) or maximum (255).
Step 8: If so, reverse the direction of fading by changing the sign of fadeamount
. Step 9: Wait for 30 milliseconds to observe the dimming effect using delay(30).
Step 10: Repeat from step 5 until the program stops.
Step 11: Stop.
Program:
Int led = 9;
brightness = 0;
Int fadeamount = 5;
void setup() {
pinmode(led, output);
}
void loop() {
analogwrite(led, brightness);
30
Output:
Result:
Thus the program to make the led fade using Arduino is written and verified successfully.
31
Ex. No. 4
Date: 03/04/2024 GSM IoT Exploration
Aim:
To initialize communication between an Arduino board and two external modules
(SIM800L GSM module and NEO-6M GPS module) using SoftwareSerial library.
Algorithm:
Step 1:Start
Step 2:Init serials, modules, pins.
Step 3: Begin serials at 9600.
Step 4: Loop for data handling.
Step 5: Read sensor data.
Step 6:Handle GSM communication.
Step 7: Handle GPS communication.
Step 8: Stop
Program:
#include <SoftwareSerial.h>
void setup() {
Serial.begin(9600);
sim800L.begin(9600);
neo6m.begin(9600);
void loop()
32
Output:
Result:
Thus, communication between an Arduino board and two external modules (SIM800L
GSM module and NEO-6M GPS module) using SoftwareSerial library was verified successfully
33
Ex. No:5 Introduction to Raspberry pi platform and python
programming
Date:
Simple program:
Led blink:
Algorithm:
Step 1: Start
Step 2: Import the pin class from the machine module and the sleep function from the utime
module.
Step 3: Initialise a new pin object named led with pin number 11 and set it as an output pin.
Step 4: Enter an infinite loop.
Step 4.1: Toggle the state of the led connected to pin 11 (if it's on, turn it off, and if It's off, turn
it on).
Step 4.2: Pause the execution for 0.5 seconds using the sleep function to create a blinking
effect.
Step 5: Stop
Program:
While true:
Led.toggle()
Sleep(0.5)
34
Output:
Step 1 : Start
Step 2 : Initialize led connected to pin 15 and set it as an output.
Step 3 : Initialise the push button connected to pin 16 and set it as an input.
Step 4 : If the button is pressed (high),then turn the led on.
Step 5 : Wait for a short duration (0.1 seconds).
Step 6 : Otherwise,turn the led off.
Step 7 : Stop
Program :
35
Output:
Algorithm :
Step 1 : Start
Step 2 : Import the pin class from the machine module and the sleep function
From the time module.
Step 3 : Define four led objects (led1, led2, led3, led4) each connected to gpio pins 6, 7, 8, and
9 respectively, all set as output pins.
Step 4 : Turn all leds on simultaneously.
Step 5 : Wait for 1 second.
Step 6 : Turn all leds off simultaneously.
Step 7 : Wait for 1 second.
Step 8 : Stop.
Program :
From machine import pin
From time import sleep
Led1 = pin(5, pin.out)
Led2 = pin(9, pin.out)
Led3 = pin(13, pin.out)
Led4 = pin(15, pin.out)
While true:
Led1.on()
Led2.on()
Led3.on()
Led4.on()
Sleep(1)
Led1.off()
Led2.off()
Led3.off()
Led4.off()
Sleep(1)
36
Output:
Result:
Thus the introduction to raspberry pi platform and python programming was studied
successfully.
37
Ex. No: 6
Date: Interfacing Sensors with Raspberry PI
Aim:
To implement object distance detection using ultrasonic sensor in Raspberry PI.
Algorithm:
Step 1: Set up pin configurations for trigger pin, echo pin, and buzzer pin.
Step 2: Configure PWM (Pulse Width Modulation) for the buzzer.
Step 3: Define a function to measure the distance using the ultrasonic sensor.
Step 4: Inside measure_distance(), send a 10 microsecond pulse to trigger the sensor.
Step 5: Measure the duration of the pulse from the echo pin to calculate the distance.
Step 6: Repeat the distance measurement in a continuous loop in the main program.
Step 7: If an object is detected within 20 cm, activate the buzzer with reduced volume.
Step 8: Pause for a moment before the next measurement.
Program:
import machine
import utime
38
return distance
# Main loop
while True:
# Measure distance
distance = measure_distance()
Circuit Diagram:
39
Output:
Result:
Thus the object distance detection using ultrasonic sensor in Raspberry PI was
implemented.
40
Ex. No:7
Date: Setup a cloud platform to log the data
Aim:
To setup a cloud platform to log the data from IOT devices.
Hardware/software requirements:
Cloud platform:
Blynk:
Blynk is a smart platform that allows users to create their internet of things applications without
the need for coding or electronics knowledge. It is based on the idea of physical programming &
provides a platform to create and control devices where users can connect physical devices to the
internet and control them using a mobile app.
41
Procedure:
Step 1: Visit blynk.cloud and create a blynk account on the blynk website. Or you can simply
signin using the registered email id.
.
Step 3: Give any name to the template such as raspberry pi pico w. Select ‘hardware type’ asother
and ‘connection type’ as wifi. So a template will be created now.
42
Step 4: Now we need to add a ‘new device’ now. Select a new device from ‘template’.
Step 5: Select the device from a template that you created earlier and also give any name to the
device. Click on create. A new device will be created. You will find the blynk authentication
token here. Copy it as it is necessary for the code.
43
44
Step 6: Now go to the dashboard and select ‘web dashboard’.from the widget box drag a switch
and place it on the dashboard screen.
Step 7: On the switch board click on settings and here you need to set up the switch. Give any
title to it andcreate datastream as virtual pin configure the switch settings as per the image below
and click on create.
45
46
Step 8: Configure the final steps again.
Result:
Thus the setup of a cloud platform to log the data from IOT devices was created and
implemented successfully.
47
Ex. No: 8 Uploading raspberry pi data to cloud
Date:
Aim:
To log data using raspberry pi and upload to the thingspeak cloud platform.
Procedure:
Step 1: Set up a channel in thingspeak with the necessary field.
Step 2: Establish a connection between a raspberry pi rp2040 and your system.
Step 3: Establish a link between thingspeak and the raspberry pi using theprovided code.
Step 4: Measure the distance of an object using an ultrasonic sensor connected tothe raspberry
pi.
Step 5: Transmit the calculated distance to thingspeak
Step 6: Run the code to execute the process.
Program:
Import machine
import utime
import requests
import network
# initialize pins
Trigger_pin = machine.pin(trigger_pin, machine.pin.out)
echo_pin = machine.pin(echo_pin, machine.pin.in) buzzer_pin =
machine.pin(buzzer_pin)
Buzzer_pwm = machine.pwm(buzzer_pin
# initialize wlan
Wlan = network.wlan(network.sta_if)
wlan.active(true)
Wlan.connect("wifi ssid", "password") #insert your wifi ssid and password
print("connected to wifi:", wlan.isconnected())
48
Api_url = f"https://api.thingspeak.com/update.json?Api_key={api_key}"
Def send_data_to_thingspeak(api_key, field1): payload = {"api_key": api_key, "field1":
field1} headers = {"content-type": "application/json"}try:
While echo_pin.value() == 0:
pulse_start = utime.ticks_us()
While echo_pin.value() == 1: pulse_end
= utime.ticks_us()
# main loop
while true:
Distance = measure_distance()
send_data_to_thingspeak(api_key, distance)
utime.sleep(0.1)
49
Output:
Result:
Thus the setup of a cloud platform to log the data from IOT devices was created and
implemented successfully.
50
Ex. No: 9 Design IOT based system
Date:
Aim:
To design an iot-based system that adjusts the brightness of an led based on the ambient
light intensity sensed by an ldr (light dependent resistor).
Algorithm:
Step 1: Start
Step 2: Set up pin a0 as input to read the analog value from the ldr.
Step 3: Set up pin 6 as output to control the led brightness.
Step 4: Read the analog value from the ldr.
Step 5: Map the ldr reading to the brightness range.
Step 6: Adjust the brightness of the led based on the mapped value.
Step 7: Repeat step 3 to 5
Step 8: Stop
Program:
Void setup() {
Pinmode(a0, input);
Pinmode(6, output);
Void loop() {
Analogwrite(6, bri);
51
Output:
Result:
Thus the experiment to design an iot-based system that adjusts the brightness of an led
based on the ambient light intensity sensed by an ldr (light dependent resistor) is written, executed
and output is verified.
52