0% found this document useful (0 votes)
3 views52 pages

IOT Lab Manual

IOT lab manual
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)
3 views52 pages

IOT Lab Manual

IOT lab manual
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/ 52

CS3691

EMBEDDED SYSTEMS
AND IOT

1
2
TABLE OF CONTENTS

S.NO DATE EXPERIMENT TITLE PAGENO MARKS SIGNATURE

1. 8501 simple programs 4

Arithmetic Programs Using


2. 16
Embedded C

3. Introduction to Arduino 25
platform and programming

4. GSM IoT Exploration 32

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

Uploading raspberry pi data to


8. 48
cloud

9. Design IOT based system 51

3
Ex. No:1
Date: 8501 simple programs

Aim:
To write 8051 assembly language experiments using ride software.

Ride Software Installation Steps:


Download RIDE Software:
Go to the official website of the software provider or a trusted source and download the RIDE
software. Make sure you download the version compatible with your operating system.

Install RIDE Software:


Once the download is complete, locate the downloaded file and run the installer. Follow the on-
screen instructions to install the software on your computer.

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

8051 Microcontroller code:


Origin:4100;
Mov a,#50;
Subb a,#25;
Mov dptr,#4500;
Movx @dptr,a;
Sjmp 4108;
#go 4100

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

8051 Microcontroller code:


Origin:4100;
Mov a,#10;
Mul a,#10;
Mov dptr,#4500;
Movx @dptr,a;
Sjmp 4108;
#go 4100

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

8051 Microcontroller code:


Origin:4100;
Mov a,#4;
Div a,#2;
Mov dptr,#4500;
Movx @dptr,a;
Sjmp 4108;
#go 4100

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

8051 Microcontroller code:


Origin :4100;
Mov a,#4;

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

8051 Microcontroller code:


Origin :4100;
11
Mov a,#4;
Anl a,#2;
Mov dptr,#4500;
Movx @dptr,a;
Sjmp 4108;
#go 4100

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

8051 Microcontroller code:


Origin :4100;
Mov a,#3;
Crl a;
Mov dptr,#4500;
Movx @dptr,a;
Sjmp 4108;
#go 4100

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

Val = analogread (temppin);

Float mv = (val/1024.0) *5000;

Float cel = mv/10;

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:

To write a program to make the led fade using Arduino

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

Brightness = brightness + fadeamount;


if (brightness <= 0 || brightness >= 255) {
Fadeamount = -fadeamount;
}
delay(30);
}

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>

SoftwareSerial sim800L(2, 3);

SoftwareSerial neo6m(6, 7);

const uint8_t buzzPin = 12;

const uint8_t motionPin = 13;

const uint8_t button_VIN = 9;

const uint8_t button_VOUT = 11;

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:

Introduction to Raspberry pi:


Raspberry pi is a series of small single-board computers (sbcs) that are the size of a credit card.
The raspberry pi foundation, a uk charity, develops the computers in partnership with broadcom.
The charity uses the money from raspberry pi sales to educate people about computing. The
raspberry pi was released in 2012, and since then there have been several variations. The original
model had a single-core 700mhz cpu and 256mb ram, while the latest model has a quad-core cpu
clocking in at over 1.5ghz.

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:

from machine import pin

from utime import sleep

Led = pin(11, pin.out)

While true:

Led.toggle()

Sleep(0.5)

34
Output:

Push button and led


Algorithm:

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 :

From machine import pin


From time import sleep
Led = pin(15, pin.out)
Button = pin(16, pin.in)
While true:
If button.value() == 1:
Led.on()
Sleep(0.1)
Else:
Led.off()

35
Output:

Multile LED’s Blink:

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

# Define pin numbers


trigger_pin = machine.Pin(15, machine.Pin.OUT)
echo_pin = machine.Pin(14, machine.Pin.IN)
buzzer_pin = machine.Pin(6)

# Configure PWM for the buzzer


buzzer_pwm = machine.PWM(buzzer_pin)

# Function to measure distance


def measure_distance():
# Send a 10 microsecond pulse to trigger the sensor
trigger_pin.low()
utime.sleep_us(2)
trigger_pin.high()
utime.sleep_us(10)
trigger_pin.low()

# Measure the duration of the pulse from the echo pin


while echo_pin.value() == 0:
pulse_start = utime.ticks_us()
while echo_pin.value() == 1:
pulse_end = utime.ticks_us()

# Calculate the duration of the pulse and convert it to distance (cm)


pulse_duration = utime.ticks_diff(pulse_end, pulse_start)
distance = pulse_duration * 0.0343 / 2

38
return distance

# Main loop
while True:
# Measure distance
distance = measure_distance()

# Check if an object is within 5 cm


if distance < 20:
# Activate the buzzer with reduced volume (50% duty cycle)
buzzer_pwm.duty_u16(32768) # 50% duty cycle
print("Object detected! Distance:", distance, "cm")
else:
# Deactivate the buzzer
buzzer_pwm.duty_u16(0)

# Pause for a moment before the next measurement


utime.sleep(0.1)

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:

S.no Software Quantity


1 Blynk cloud 1

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 2: Click on +new template

.
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

# define pin numbers


trigger_pin = 15
Echo_pin = 14
Buzzer_pin = 6

# 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())

# thingspeak api endpoint and api key


Api_key = "thingspeak write api key" # insert your api key

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:

Response = requests.post(api_url, json=payload, headers=headers)


response.raise_for_status() # raise an exception for error status codesprint("data
sent successfully.")
Except:
Print(f"data sent successfully ")

# function to measure distancedef


measure_distance():
Trigger_pin.low()
utime.sleep_us(2)
trigger_pin.high()
utime.sleep_us(10)
trigger_pin.low()

While echo_pin.value() == 0:
pulse_start = utime.ticks_us()
While echo_pin.value() == 1: pulse_end
= utime.ticks_us()

Pulse_duration = utime.ticks_diff(pulse_end, pulse_start)


distance = pulse_duration * 0.0343 / 2
Return distance

# main loop
while true:
Distance = measure_distance()
send_data_to_thingspeak(api_key, distance)

# check if an object is within 10 cmif


distance < 10:
Buzzer_pwm.duty_u16(32768) # 50% duty cycle
print("object detected! Distance:", distance, "cm")
Else:
Buzzer_pwm.duty_u16(0)

utime.sleep(0.1)

49
Output:

Logged data in thingspeak using raspberry pi:

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() {

Int ldr = analogread(a0);

Int bri = map(ldr, 0, 1023, 0, 255);

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

You might also like