0% found this document useful (0 votes)
11 views65 pages

Esiot Lab Print

Uploaded by

SOUNDARYA C
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 views65 pages

Esiot Lab Print

Uploaded by

SOUNDARYA C
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/ 65

ARUNAI ENGINEERING COLLEGE

(Affiliated to Anna University)


Velu Nagar, Thiruvannamalai-606603
www.arunai.org

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

BACHELOR OF ENGINEERING

2023–2024

SIXTH SEMESTER

CS3691-EMBEDDED SYSTEMS AND IOT LABORATORY


ARUNAI ENGINEERING COLLEGE
TIRUVANNAMALAI–606603

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CERTIFICATE
Certified that this is a Bonafide record of work done by

Name :

UniversityReg.No :

Semester :

Branch :

Year :

Staff-in-Charge Head of the Department

Submitted for the


Practical Examination held on

Internal Examiner External Examiner


LIST OF CONTENT

SIGNATURE
S.NO DATE NAME OF THE EXPERIMENT PAGE NO
OF STAFF

10

11

12
REGISTER NO:

EXP.NO: 1 Write 8051 Assembly Language experiments using simulator


DATE:

a) Write an assembly language program to find the largest element in a given array of
N =06 h bytes at location 4000h. Store the largest element at location 4062h.

AIM:
To find the largest element in a given array using assembly language program

PROCEDURE:
1. Start
2. Initialize a variable 'largest' with the first element of the array.
3. Iterate through the array:
Compare each element with 'largest'.
If the current element is greater than 'largest', update 'largest' to the current element.
4. Once all elements are checked, 'largest' will contain the largest element in the array.
5. End

PROGRAM:

Let N =06h
mov r3,#6 //length of the array
mov dptr,#4000H //starting address of array
movx a ,@dptr
mov r1,a

next byte: inc dptr


movx a, @dptr
clrc //reset borrow flag
mov r2,a //next number in the array
subb a,r1 //other Num-Prev largest no.
jc skip //jnc for smallest element
mov a,r2 //update larger number in r1
mov r1,a

skip: djnz r3,nextbyte


mov dptr, #4062H //location of the result-4062h
mov a,r1 //largest number
movx @dptr,a //store at #4062H
end

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

O OUTPUT:

Before Execution: After Execution:

RESULT:

Thus the program for the largest element in a given array using assembly language was
executed successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EXP.NO:1(b) Write an assembly language program to sort an array of N =06h bytes of data
in Ascending/Descending order stored from location 9000h
DATE: (Using bubble sort algorithm)

AIM:
To sort number in a given array using assembly language program.

PROCEDURE:
1. Start
2. Iterate over the array from the beginning to the second-to-last element:
a. For each iteration, iterate over the unsorted portion of the array:
i. Compare each element with its adjacent element.
ii. If the current element is greater (for ascending order) or smaller (for descending
order) than the next element: - Swap the elements.
3. Repeat step 2 until no swaps are made in a pass.
4. End

PROGRAM:

Let N=06h
Mov r0, #05H //count (N-1) array size=N
loop1: mov dptr, #9000h //array stored from address 9000h
mov r1, #05h //initialize exchange counter
loop2: movx a, @dptr //get number from array and store in B register
mov b, a
inc dptr
movx a, @dptr //next number in the array
clr c //reset borrow flag
mov r2, a //store in R2
subb a, b //2nd-1stNo,sinceno compare instruction in 8051
jnc noexchg // jc-for descending order
mov a,b //exchange the 2 nos in the array
movx @dptr, a
dec dpl //DEC DPTR-instruction not present
mov a,r2
movx@dptr,a
nc dptr
noexchg: djnz r1,loop2 //decrement compare counter
djnzr0,loop1 //decrement pass counter
end

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

OUTPUT:

Before Execution: After Execution :( Ascending order)

RESULT:

Thus the program for sort the number in a given array using assembly language was executed
successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EXP.NO: 2(a) Test data transfer between Registers and memory


DATE:

a) Write an assembly language program to transfer N=05h bytes of data from Location A: 30 h
to location B: 40 h.

AIM:
To do data transferring between register and memory using assembly language program

PROCEDURE:
1. Start
2. Set up a counter to keep track of the number of bytes transferred, initialized to 0.
3. Repeat the following steps until the counter reaches N:
a. Load a byte of data from location A into a register.
b. Store the byte of data from the register into location B.
c. Increment the counter by 1.
d. Move to the next byte in both locations A and B.
4. End

PROGRAM:

Let N =05h, A: 30h B: 40h


Mov r0, #30h //source address
Mov r1, #40h //destination address
movr7, #05h //Number of bytes to be moved
back: mov a, @r0
mov@r1, a
inc r0
inc r1
djnz r7,back //repeat till all data transferred
end

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

OUTPUT:

RESULT:

Thus the program to data transferring between register and memory using assembly language
were executed successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:
EXP.NO:2(b) Write an assembly language program to exchange N =05 h bytes of data
DATE: at location A: 30 h and at location B: 40 h

AIM:
To do data exchange between register and memory using assembly language program.

PROCEDURE:
1. Start
2. Set up a loop to iterate N times:
a. Load a byte from location A and store it in a temporary register.
b. Load a byte from location B and store it in location A.
c. Load the byte stored in the temporary register and store it in location B.
d. Move to the next byte in both location A and location B.
3. End

PROGRAM:

Let N=05h, A: 30h, B: 40h


Mov r0, #30h //source address
Mov r1, #40h //destination address
Mov r7, #05h //count the number of data to be exchanged
back: mov a,@r0
mov r4, a
mov a,@r1
mov @r0,a
mov a,r4
mov @r1,a
inc r0
inc r1
djnz r7,back
end

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

OUTPUT:

RESULT:

Thus the program to exchange data between register and memory using assembly language
were executed successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EX. NO: 3 (a) Perform ALU operations


DATE:

a) Write an assembly language program to perform the addition of two 16-bit numbers.

AIM:
To do arithmetic operation using assembly language program.

PROCEDURE:
1. Start
2. Initialize variables:
Load the first 16-bit number (num1) into a register (e.g., AX)
Load the second 16-bit number (num2) into another register (e.g., BX)
Set a register (e.g., CX) to store the carry if needed
3. Set another register (e.g., DX) to store the result
4. Add the two numbers:
Add the contents of AX and BX registers
If there is a carry from the addition, add it to the result of the next addition
5. Store the result in DX
6. End

PROGRAM:

Mov r0, #34h //lower nibble of No.1


Mov r1, #12h //higher nibble of No.1
Mov r2, #0dch //lower nibble of No.2
Mov r3, #0feh //higher nibble of No.2
Clr c
mov a, r0
add a, r2
mov 22h,a
mov a, r1
addc a, r3
mov 21h, a
mov 00h, c
end

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

OUTPUT:

RESULT:

Thus the program to do arithmetic operation like addition using assembly language was
executed successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EXP.NO: 3(b) Write an assembly language program to perform the subtraction of two
16-bit numbers
DATE:

AIM:
To do arithmetic operation using assembly language program.

PROCEDURE:

1. Start
2. Initialize variables:
Load the first 16-bit number (minuend) into a register (e.g., AX)
Load the second 16-bit number (subtrahend) into another register (e.g., BX)
Set a register (e.g., CX) to store the borrow if needed
Set another register (e.g., DX) to store the result
3. Subtract the second number from the first:
Subtract the contents of BX from AX
If there is a borrow from the subtraction, adjust the result accordingly
Store the result in DX
4. End

PROGRAM:

mov r0, #0dch //lower nibble of No.1


mov r1, #0feh //higher nibble of No.1
mov r2, #34h //lower nibble of No.2
mov r3, #12h //higher nibble of No.2
Clr c
mov a, r0
Subb a, r2
mov 22h, a
mov a, r1
Subb a, r3
mov 21h, a
mov 00h, c
end

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

OUTPUT:

RESULT:

Thus the program to do arithmetic operation like subtraction using assembly language was
executed successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EXP.NO: 3(C) Write an assembly language program to perform the multiplication of two
DATE: 16-bit numbers

AIM:
To do arithmetic operation using assembly language program.

PROCEDURE:
1. Start
2. Initialize variables:
Load the first 16-bit number (multiplicand) into a register (e.g., AX)
Load the second 16-bit number (multiplier) into another register (e.g., BX)
Set another register (e.g., DX) to store the result
3. Multiply the numbers:
Multiply the contents of AX and BX registers
Store the result in DX
4. End

PROGRAM:
Mov r0, #34h // 5678*1234
Mov r1, #12h
Mov r2, #78h
Mov r3, #56h
mov a, r0
mov b, r2
mul ab
mov 33h,a
mov r4,b
mov a, r0
mov b,r3
mul ab
add a, r4
mov r5,a
mov a,b
addc a,#00h
mov r6,a
mov a,r1
movb,r2mulab
add a,r5
mov 32h,a
mov a,b
addc a,r6
mov 00h,c
mov r7,a
mov a,r3
mov b,r1
mulab
adda,r7
mov 31h, a
mov a, b
addc a,20h
mov30h,a
end

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

OUTPUT:

RESULT:

Thus the program to do arithmetic operation like multiplication using assembly language was
executed successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EXP.NO: 3(d) Write an assembly language program to perform logical operations AND, OR,
XOR on two eight bit numbers stored in internal RAM locations 21h, 22h.
DATE:

AIM:
To do logical operation using assembly language program.

PROCEDURE:
1.Start
2.Load the first eight-bit number from RAM location 21h into a register (e.g., AL)
3.Load the second eight-bit number from RAM location 22h into another register (e.g., BL)
4.Perform logical AND operation:
AND the content of AL and BL registers
Store the result in a register (e.g., CL)
5.Perform logical OR operation:
OR the contents of AL and BL registers
Store the result in a register (e.g., DL)
6. Perform logical XOR operation:
XOR the content of AL and BL registers
Store the result in a register (e.g., BL)
7. End

PROGRAM:
mov a, 21h //do not use #,as data ram 21h is to be accessed
anl a, 22h //logical and operation
mov 30h, a //and operation result stored in 30h
mov a, 21h
orl a, 22h //logical or operation
mov 31h, a //or operation result stored in 31h
mov a, 21h
xrl a,22h //logical xor operation
mov 32h,a //xor operation result stored in 32h
end

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

OUTPUT:
Before Execution: D: 21H= 03h 22H= 05h

After Execution: D:030H= 01h //ANDoperation


D:031H= 07h //ORoperation
D:032H = 06h //XORoperation

RESULT:

Thus the program to do logical operation like OR, AND, XOR using assembly language was
executed successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EXP.NO: 4(a) Write Basic and arithmetic Programs Using Embedded C.


Arithmetic operation
DATE:

AIM:
To do arithmetic operation using assembly language program.

PROCEDURE:
1. Start
2. Initialize variables:
Declare variables for storing operands (e.g., operand1, operand2)
Declare variables for storing results (e.g., result_add, result_sub, result_mul, result_div)
Input values for operands from sensors, switches, or other sources.
3. Perform addition:
Add operand1 and operand2
Store the result in result_add
4. Perform subtraction:
Subtract operand2 from operand1
Store the result in result_sub
5. Perform multiplication:
Multiply operand1 and operand2
Store the result in result_mul
6. Perform division:
Divide operand1 by operand2
Store the result in result_div
7. Output/display the results using LEDs, displays, or other output methods.
8. End

PROGRAM:
#include<reg51.h>
Void main(void)
{
Unsigned char x,y,z,a,b,c,d,e,f,p,q,r;//define variables
//addition
x=0x12; //first 8 bit number
y=0x34; //second 8 bit number
P0=0x00; //declare port 0 as output port
z=x+y; //perform operation
P0=z; //display result in port 0
//subtraction
a=0x12; //first 8 bit number
b=0x34; //second 8 bit number
P1=0x00; //declare port 1 as output port
c=a-b; //perform operation
P1=c; //display result in port 1
//multiplication
d=0x12; //first 8 bit number
e=0x34; //second 8 bit number
P2=0x00; //declare port 2 as output port

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

f=d*e; //perform operation


P2=f; //display result in port 2
//divison
p=0x12; //first 8 bit number
q=0x34; //second 8 bit number
P3=0x00; //declare port 3 as output port
r=q/p; //perform operation
P3=r; //display result in port 3
while(1)
}

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

OUTPUT:

Port 0: 0x46
Port 1: 0xFE
Port 2: 0x48
Port 3: 0x02

RESULT:

Thus the program to do arithmetic operation using assembly language was executed
successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EXP.NO: 4(b) Write and embedded C language program to perform basic logic operations like
NOT/complement/inverse, AND, OR, XOR, Left shift, Right shift LOGICAL
DATE: OPERATION

AIM:
To do logical operation using assembly language program.

PROCEDURE:
1. Start
2. Initialize variables:
Declare variables for operands (if needed)
Declare variables for storing results
3. Perform NOT operation:
Input an operand (if needed)
Apply the bitwise NOT operator to the operand
Store the result
4. Perform AND operation:
Input two operands (if needed)
Apply the bitwise AND operator to the operands
Store the result
5. Perform OR operation:
Input two operands (if needed)
Apply the bitwise OR operator to the operands
Store the result
6. Perform XOR operation:
Input two operands (if needed)
Apply the bitwise XOR operator to the operands
Store the result
7. Perform left shift operation:
Input an operand and the number of bits to shift
Apply the left shift operator to the operand
Store the result
8. Perform right shift operation:
Input an operand and the number of bits to shift
Apply the right shift operator to the operand
Store the result
9. Output/display the results
10. End

PROGRAM:
# include<reg51.h>
void main(void){
unsigned char x,y, a,b,c, d,e,f, p,q,r; //define variables
//NOT operation
x=0x12; //first 8-bit number
P0=0x00; //declare port 0 as output port
y=~x; // perform NOT operation
P0=y; //display result on port 0
DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:
REGISTER NO:

//AND operation
a=0x12; //first 8-bit number
b=0x34; //second 8-bit number
P1=0x00; //declare port 1 as output port
c=a&b; // perform AND operation
P1=c; //display result on port 1

//OR operation
d=0x12; //first 8-bit number
e=0x34; //second 8-bit number
P2=0x00; //declare port 2 as output port
f=e|d; // perform OR operation
P2=f; //display result on port 2

//XOR operation
p=0x12; //first 8-bit number
q=0x34; //second 8-bit number
P3=0x00; //declare port 3 as output port
r=q^p; // perform XOR operation
P3=r; //display result on port 3

//Left shift operation


x=0x12; //first 8-bit number
P0=0x00; //declare port 0 as output port
y=x<<1; // perform Left shift operation
P0=y; //display result on port 0

// Right shift operation


x=0x12; //first 8-bit number
P1=0x00; //declare port 0 as output port
y=x>>1; // perform Right shift operation
P1=y; //display result on port 1
while(1);
}

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

OUTPUT:

Port 0: 0xED
Port 1: 0x10
Port 2: 0x36
Port 3: 0x26

RESULT:

Thus the program to do logical operation like OR, AND, XOR,NOT, LEFT SHIFT, RIGHT
SHIFT using assembly language was executed successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EXP.NO: 5 Introduction to Arduino platform and programming


DATE:

AIM:
To learn the basics of Arduino platform and do the program using the hardware component and
arduino IDE.

INTRODUCTION:
Arduino is an open-source electronics platform that uses simple hardware and software to make it
easy to use. Arduino boards can read inputs such as light from a sensor or motor activation. The
Arduino project started in 2005 as a tool for students at the Interaction Design Institute in Ivrea,
Italy, with the goal of providing a low-cost and uncomplicated way for novices and experts to
design devices that interact with their surroundings using sensors and actuators.
The Diecimila, the first widely marketed Arduino board, was produced in 2007, and the Arduino
family has expanded since then to take use of several types of Atmel AVR MCU chips.
Arduino LLC was formed in early 2008 by the five co-founders of the Arduino project to hold the
trademarks related with Arduino. External firms were to manufacture and sell the boards, and
Arduino LLC would get a royalty from them. The Arduino LLC statutes stipulated that each of the
five founders’ hand over ownership of the Arduino brand to the newly established corporation.
The Arduino Programming Language, or Arduino Language, is a native language supported by
Arduino. The Arduino Programming Language is essentially a framework built on top of the C++
programming language. The Arduino IDE (Integrated Development Environment) is based on
processing, and this programming is often based on wiring.
Arduino boards, unlike other microcontroller boards in India, were just released a few years ago and
were first restricted to small-scale applications. Since then, Arduino has powered hundreds of
projects ranging from simple household items to major scientific apparatus. Students, amateurs,
artists, programmers, and professionals from all around the world are all part of this global
community of creators.

II.NEED FOR ARDUINO

Beginners will find the Arduino software simple to use, while expert users will find it adaptable. It
is compatible with Mac, Windows, and Linux. It is used by teachers and students to create low-cost
scientific equipment, to demonstrate chemistry and physics principles, and to begin learning
programming and robotics. There are many alternative microcontrollers and microcontroller
platforms available.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

1. Microcontroller:ATmega328
2. OperatingVoltage:5V
3. Input Voltage(recommended):7-12V
4. InputVoltage(limits):6-20V
5. DigitalI/OPins: 14 (of which 6 provide PWMoutput)
6. AnalogInput Pins:6
7. DCCurrentperI/OPin:40mA
8. DCCurrent for3.3VPin:50 mA
9. Flash Memory: 32 KB of which 0.5 KB used by
bootloader10.SRAM: 2KB (ATmega328)
11. EEPROM:1 KB(ATmega328)
12. ClockSpeed:16 MHz

I. TYPES OFARDUINOS
1. Arduinoboards areavailablewith manydiverse types.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

V. ELEMENTS OF ARDUINO BOARD

The elements in Arduino are divided in two categories:

 Hardware
 Software
A. Hardware

1. Microcontroller: Each Arduino board comes with its own microcontroller. It is possible to
think of it as the board's brain. The primary IC (Integrated Circuit) differs slightly from
board to board. Arduino mostly use ATMEL microcontrollers.
2. USB Port: The USB port is used to power the Arduino board. It is also used to upload
programmes from a computer to the microcontroller.
3. Power Barrel Jack: The Arduino board is powered by a battery through this power jack.
4. Digital Pins: The Arduino UNO board features 14 digital I/O pins, with 6 ofthem providing
PWM output (Pulse Width Modulation). These pins can also beset up to function as digital
input or output pins. PWM may be generated by using the pins designated with "~".
5. Analog Pins: A0 through A5 are the six analog pins of the Arduino UNO. These pins can be
used to read an analog sensor's signal.
6. Power Pins: The Arduino UNO has a Vin, 5V, 3.3V and three GND pins supplying power to
various sensors.
7. Crystal Oscillator: The crystal oscillator aids Arduino in resolving timing problems. The
Arduino UNO operates at a16MHz frequency.
8. Arduino Reset: The Arduino board's programme may be reset with the aid of this reset
button. There are two methods for resetting the UNO board. The first method is to use the
reset button on the board. Second, the pin labelled RESET may be used to connect an
external reset button (5).
9. Voltage Regulator: The voltage regulator on the Arduino board's role is to control the
voltage supplied to the board via the power supply.
10. Tx and Rx Pins: The serial communication pins on the Arduino board are Tx (1)and Rx(0).

B. Software
The software component of Arduino is crucial to its operation. The Arduino board must be
programmed using the Arduino IDE open-source software. Sketch is the name of the programme
created with the Arduino IDE. The Arduino program's core programming structure is detailed here.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

Fig.2.ArduinoProgramStructure

1. setup(): When the sketch starts, the setup() method is invoked. After each power up or
reset of the Arduino board, this function will run just once. It is used to configure
variables, pin modes, and other features.

2. loop() : This loop() function performs exactly what its name implies. This function will continue
to execute indefinitely until the Arduino board receives power. This function will be used to declare
the statements that must be run repeatedly.

Some of the basic Arduino functions are discussed below:


pinmode ():Thepinmode()functionisusedtoConfiguresthespecifiedpintobehaveeitherasan input or an
output.
DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:
REGISTER NO:

digitalWrite ():To write HIGH or LOW values to a digitalpin, use the digitalWrite() function.
digitalRead(): To read digital data from a digital pin, use the digitalread() function is used.
analogWrite(): To write analog data to an analogpin, use the analogWrite() function.
analogRead(): The anagolRead() function is used to read the analog data from an analog sensor
through the analog pin.
delay() : This delay() function is used to add time delays between any two continuous processes in
the drawing.
Here is a sample program for understanding purpose:

Arduino Procedures

Launch the Arduino application

Double-click the Arduino application (arduino.exe) you have previously downloaded. (Note: if
the Arduino Software loads in the wrong language, you can change it in the preferences dialog.
See the Arduino Software(IDE) page for details.)

Open the blink example

Open the LED blink example sketch: File >Examples>01.Basics>Blink.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

Select your board

You'll need to select the entry in the Tools > Board menu that corresponds to your Arduino.

Select your serial port

Select the serial device of the Arduino board from the Tools | Serial Port menu. This is likely to be
COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you
can disconnect your Arduino board and re-open the menu; the entry that disappears should be the
Arduino board. Reconnect the board and select that serial port.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

Upload the program

Now, simply click the "Upload" button in the environment. Wait a few seconds – you should see the
RX and TX leds on the board flashing. If the upload is successful, the message "Done uploading." will
appear in the status bar. (Note: If you have an Arduino Mini, NG, or other board, you'll need to
physically press the reset button on the board immediately before clicking the upload button on the
Arduino Software.)

A few seconds after the upload finishes, you should see the pin 13 (L) LED on the board start to blink
(in orange). If it does, congratulations! You've gotten Arduino up-and-running. If you have problems,
please see the trouble shooting suggestions.

RESULT:

Thus learn the basics of Arduino platform and do the program using the hardware component and
arduino IDE can be done.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EXP.NO : 5(b) Arduino program for Turn on a LED


DATE:

AIM:
To write the Arduino program for Turn on a LED.

APPARATUS REQUIRED:

1. Arduino UNO AtMega328 circuit Board – 1 No


2. LED – 1 No
3. Breadboard – 1 No
4. Connecting Jumper wire as per required
5. Power supply

Connection Details for LEDs:

Arduino Uno
LED
13 AtMega328

PROCEDURE:
1.Start
2.Initialize the Arduino setup function:
Set the pin connected to the LED as an output pin.
3.Initialize the Arduino loop function:
Turn on the LED by setting the output pin HIGH.
4.End

PROGRAM:
void setup()
{pinMode(13,OUTPUT
);
}
void loop()
{digitalWrite(13,HIGH
);
}

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

OUTPUT:

RESULT:

Thus the Arduino program for Turn on a LED can be visualized using Arduino board and IDE
successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EXP.NO : 5(C) Write an Arduino program for Turn ON & OFF a LED
DATE:

AIM:
To write the Arduino program for Turn on & Off a LED.

APPARATUS REQUIRED:
1. Arduino UNO AtMega328 circuit Board – 1 No
2. LED – 1 No
3. Breadboard – 1 No
4. Connecting Jumper wire as per required
5. Power supply
Connection Details for LEDs:

Arduino
LED
UnoAtMega
13
328

PROCEDURE:
1. Setup:
Connect the LED to one of the digital pins of the Arduino board. Note down the pin
number you've chosen.
2. Define Constants:
Define constants for the LED pin and the time intervals for on and off periods.
3. Setup Function:
In the setup() function, set the LED pin as an output pin using pinMode().
4. Main Loop:
Enter the loop() function.
Turn on the LED by setting the digital pin HIGH using digitalWrite().
Wait for the specified on period using delay().
Turn off the LED by setting the digital pin LOW using digitalWrite().
Wait for the specified off period using delay().
5. Repeat the above steps indefinitely.

PROGRAM:
void setup()
{pinMode(13,OUTPUT);
}
void loop()
{digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
}

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

OUTPUT:

RESULT:

Thus the Arduino program for Turn on and off LED can be visualized using Arduino board and
IDE successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EXP.NO:6 EXPLORE DIFFERENT COMMUNICATION METHODS WITH IOT DEVICES


DATE: (ZIGBEE, GSM, BLUETOOTH)

AIM:
To write the Arduino program for Bluetooth transmission and reception.

APPARATUS REQUIRED:
1. Arduino UNO AtMega328 circuit Board – 1 No
2. Bluetooth chip
3. LED – 1 No
4. Breadboard – 1 No
5. Connecting Jumper wire as per required
6. Power supply

Connection Details for Bluetooth:

Note: DIP Switch S1 in 16 X 2 LCD Display Block should be all ON position.

BluTooth Arduino
HC-05 UnoAtMega
BTx 328A0
BRx A1

PROCEDURE:
1. Setup
2. Include Libraries
3. Define Constants and Variables
4. Setup Function
5. Setup Function
6. End
PROGRAM:

//HC-05 pair password 1234


//Connection A0 ~ BTx, A1 ~ BRx
#include<LiquidCrystal.h>
#include<SoftwareSerial.h>
//Create Liquid Crystal Object called LCD
LiquidCrystallcd (7,6,5,4,3,2);
SoftwareSerialmySerial(A0,A1); //(Connect TX, RX from bluetooth to PinA0,A1 in Arduino);

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

String val = "No Data";


String oldval;
String newval = "No Data";
Int i = 0;

Void setup ()
{
//Initialize the LCD
lcd.begin(16,2); //Tell Arduino to start your 16 column 2 row LCD
mySerial.begin(9600);
Serial.begin(9600);
lcd.setCursor(0, 0); //Set cursor to first column of first row
lcd.print("Welcome!");
delay(2000);
}

void loop()
{
val = mySerial.readString();
val.trim();
Serial.println(val);
if(val!= oldval)
{
newval=val;
}
lcd.clear();
lcd.setCursor(i, 0);
lcd.print(newval);
i++;
if(i>=15)
{
i=0;
}
val = oldval;
}

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

OUTPUT:

RESULT:

Thus the Arduino program for wireless data transmission and reception using Bluetooth chips
can be visualized using Arduino board and IDE successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EXP.NO: 6(b) ARDUINO PROGRAM FOR COMMUNICATION BETWEEN IOT DEVICES


THROUGH ZIGBEE PROTOCOL
DATE:

AIM:
To write the Arduino program for communication between zigbee devices for transmission and
reception.
.
APPARATUS REQUIRED:
1. Arduino UNO AtMega328 circuit Board – 1 No
2. Zigbee module
3. LED – 1 No
4. Breadboard – 1 No
5. Connecting Jumper wire as per required
6. Power supply

Connection Details for Xigbee Transmitter:


Note: DIP Switch S3 in PUSH Button Block switch 7 should be ON position.

Arduino Uno
AtMega328
ZigBee
2
ZTx
3
ZRx

PROCEDURE:
1. Setup
2. Include Libraries
3. Define Constants and Variables
4. Setup Function
5. Main Loop

PROGRAM:
For ZigBee Transmitter:
//Pin2 connected to ZTx
//Pin3Connected to ZRx
//Switch on 7 in Dip switch S3
//Press SW3 Push Button for Led On in Receiver Trainer

#include"SoftwareSerial.h"
SoftwareSerialXBee(2,3);
Int SW1 = A4;

Void setup()
{
Serial.begin(9600);
DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:
REGISTER NO:

pinMode(SW1, INPUT);
XBee.begin(9600);
}

void loop()
{
if(digitalRead(SW1)== HIGH)
{
Serial.println("Turn on LED");
XBee.write('1');
delay(1000);
}
elseif (digitalRead(SW1)==LOW)
{
Serial.println("Turn off LED");
XBee.write('0');
delay(1000);
}
}

ConnectionDetailsforXigbeeReciver:

Arduino
ZigBee UnoAtMega
ZTxZ 3282
Rx 3

PROCEDURE:
1. Identify Components
2. Understand Pinout
3. Select Connection Method
4. Hardware UART Connection (assuming Arduino Uno)
5. SoftwareSerial Connection
6. Power Supply
7. Verify Connections
8. Test Communication, Antenna
9. Enclosure and Mounting
10. End

PROGRAM:
For ZigBee Reciver:

//Pin2 connectedto ZTx


//Pin 3 Connected to ZRx
#include "SoftwareSerial.h"
#include<SoftwareSerial.h>
Int led = 13;

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

int received = 0;
int i;

//For communicating with zigbeeSoftware


Serialzigbee(2,3);

voidsetup()
{
Serial.begin(9600);
zigbee.begin(9600);
pinMode(led,OUTPUT);
}
void loop()
{
//check if the data is received
if(zigbee.available() > 0)
{
received=zigbee.read();
//if the data is 0, turn off the LED
if(received== '0')
{
Serial.println("Turning off LED");
digitalWrite(led,LOW);
}
//if the data is 1, turn on the LED
Else if(received== '1')
{
Serial.println("Turning on LED");
digitalWrite(led,HIGH);
} }}

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

OUTPUT:

RESULT:

Thus the Arduino program for wireless data transmission and reception using Zigbee module can be
visualized using Arduino board and IDE successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EXP.NO: 6(C) ARDUINO PROGRAM FOR DETECT THE FLAME AND SEND A SMS.
DATE:

AIM:
To write the Arduino program for detect the flame and send a sms.

APPARATUS REQUIRED:
1. Arduino UNO AtMega328 circuit Board – 1 No
2. GSM module
3. LED – 1 No
4. Breadboard – 1 No
5. Connecting Jumper wire as per required
6. Power supply

Connection Details for Xigbee Transmitter:


Note: DIP Switch S3 in Buzzer Block switch 6 should be ON position.

Arduino
GSM UnoAtMega
GTx 3282
GRxI 3
RTx Sensor
COM O/P I/PA0

PROCEDURE:
1. Start
2. import libraries
3. Initialize the pins and board
4. Setup
5. Loop
6. Send SMS Function

PROGRAM:
#include<SoftwareSerial.h>
Software SerialmySerial(2,3); // RX, TX
Int flame=A0;
Int buz=7;

voidsetup()
{
pinMode(A0,INPUT);
pinMode(buz,OUTPUT);
mySerial.begin(9600);

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

Serial.begin(9600);
}
void loop()
{
if(digitalRead(flame)== LOW)
{
init_sms();
send_data("Flame Alert");
mySerial.println(" ");
Serial.println(" ");
send_sms();
digitalWrite(buz,HIGH);
while(1);
}
else
{
digitalWrite(buz,LOW);
}

Void init_sms()
{
mySerial.println("AT+CMGF=1");
Serial.println("AT+CMGF=1");
delay(400);
mySerial.println("AT+CMGS=\"8838961153\""); // use your 10 digit cell no.here
Serial.println("AT+CMGS=\"8838961153\"");
delay(400);
}
Void send_data(String message)
{
mySerial.print(message);
Serial.print(message);
delay(200);
}
void send_sms()
{
mySerial.write(26);
Serial.write(26);
}

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

OUTPUT:

RESULT:
Thus the Arduino program for wireless data transmission and reception using GSM module can
be visualized using Arduino board and IDE successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:
EXP.NO:7 INTRODUCTION TO RASPBERRY PI PLATFORM AND PYTHON
PROGRAMMING
DATE:

AIM:
To write the python program for Turn on & off a LED.

APPARATUS REQUIRED:
1. Raspberry Pi circuit Board – 1 No
2. LED – 1 No
3. Breadboard – 1 No
4. Connecting Jumper wire as per required
5. Power supply
Connection Details for LEDs:

Raspberry
LED PiPiCoWGP1
2 5

PROCEDURE:
1. Import Libraries
2. Set up GPIO
3. Define GPIO Pin
4. Main Loop: Enter a loop that runs indefinitely (while True).
5. Turn On LED
6. Turn Off LED
7. Cleanup
8. Stop

PROGRAM:
import machine
import time
led=machine.Pin(15,machine.Pin.OUT)
while(True):

led.on()

time.sleep(1)

led.off()

time.sleep(1)

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

OUTPUT:

RESULT:

Thus the python program for LED turn on and off can be visualized using Raspberry Pi and
software successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EXP.NO: 8 INTERFACING SENSORS WITH RASPBERRY PI


DATE:

AIM:
To write the python program for Measure the obstacle distance in cm using Ultrasonic Sensor.
APPARATUS REQUIRED:
1. Raspberry Pi circuit Board – 1 No
2. LED – 1 No
3. Ultrasonic sensor
4. Breadboard – 1 No
5. Connecting Jumper wire as per required
6. Power supply

Connection Details for Ultra Sonic Sensor (HC-SR04):

UltrasonicSensor Raspberry Pi
PiCo W
Trigger GP16
ECHO GP17

PROCEDURE:
1. Setup: Import necessary libraries
2. GPIO Setup
3. Measure Distance Function
4. Main Loop: Continuously measure the distance in a loop
5. Cleanup: If the user interrupts the program
PROGRAM:
from machine import Pin
import utime
trigger = Pin(16, Pin.OUT)
echo= Pin(17, Pin.IN)

def ultra():
trigger.low()
utime.sleep_us(2)
trigger.high()

utime.sleep_us(5)

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

trigger.low()

while echo.value() == 0:
signaloff=utime.ticks_us()

while echo.value() == 1:
signalon=utime.ticks_us()

timepassed = signalon – signaloff


distance= (timepassed* 0.0343)/ 2
print("The distance fromobjectis ",distance,"cm")

while True:
ultra()
utime.sleep(1)

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

OUTPUT:

The distance from object is 25.0 cm


The distance from object is 24.5 cm
The distance from object is 25.2 cm
...

RESULT:

Thus the python program for Measure the obstacle distance in cm using Ultrasonic Sensor.
can be visualized using Raspberry Pi and software successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EXP.NO:9 COMMUNICATE BETWEEN ARDUINO AND RASPBERRY PI USING ANY

DATE: WIRELESS MEDIUM

AIM:
To write the python program for communication between Arduino and Raspberry Pi Using ZigBee
Wireless Medium.

APPARATUS REQUIRED:
1. Raspberry Pi circuit Board – 1 No
2. LED – 1 No
3. Ultrasonic sensor
4. Breadboard – 1 No
5. Connecting Jumper wire as per required
6. Power supply

Connection Details for ZigBee Transmitter Interface with Raspberry Pi PiCo W:

Raspberry
ZigBee PiPiCoW
ZTxZR GP1
x GP0

PROCEDURE:
1. Raspberry Pi Program:
•Import the serial library for serial communication.
•Initialize serial communication with the ZigBee module connected to the Raspberry Pi.
•Define a function to send data to the Arduino via the ZigBee module.
•Enter a loop to continuously send data to the Arduino. Adjust the data and delay as
necessary.
•Handle KeyboardInterrupt to close the serial port properly.
2. Arduino Sketch:
•Initialize serial communication.
•Enter a loop to continuously check for incoming data from the Raspberry Pi.
•When data is available, read it and print it to the serial monitor.
•Add any additional code or conditions as needed.
•Introduce a delay to avoid overwhelming the Arduino with constant checks.

Raspberry Pi Interface with ZiGBee Transmitter

PROGRAM:
#Pin GP0 connectedto ZRx
#Pin GP1 Connected to ZTx
#Switch off 7 in Dip switch S3
#Press SW3 Push Button in Transmitter for Led On in Receiver Trainer.
From machine import UART, Pin
Import time

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

sw=machine. Pin(16,machine.Pin.IN)
uart0=UART (0, baudrate=9600, tx=Pin (0),rx=Pin(1))

While True:
a = sw.value()
if(a==1):
uart0.write ('1')
else:
uart0.write ('0')

Connection Details for Xigbee Reciver:

Arduino
ZigBee UnoAtMega
ZTxZ 3282
Rx 3

Arduino Interface with ZigBee Reciver

Program:
//Pin2 connectedto ZTx
//Pin3ConnectedtoZRx
//Led13 On in receiver kit while press sw3 switch in Tranmitter Trainer.
#include"SoftwareSerial.h"
#include<SoftwareSerial.h>
intled = 13;
int received = 0;
int i;
//For communicating with zigbee
SoftwareSerialzigbee(2,3);
Void setup()
{
Serial.begin(9600);
zigbee.begin(9600);
pinMode(led,OUTPUT);

}
void loop()
{
//check if the data is received
if(zigbee.available() > 0)
{
received=zigbee.read();
//if the data is 0, turn off the LED
if(received== '0')
{
DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:
REGISTER NO:

Serial.println("Turning off LED");


digitalWrite(led,LOW);
}
//if the data is 1, turn on the LED
Else if(received== '1')
{
Serial.println("Turning on LED");
digitalWrite(led,HIGH);
}
} }

OUTPUT:

If the transmitter sends '0', the LED will turn off


"Turning off LED" will be printed to the Serial monitor.

If the transmitter sends '1', the LED will turn on,


"Turning on LED" will be printed to the Serial monitor.

RESULT:
Thus the python program for communication between Arduino and Raspberry Pi Using ZigBee
Wireless Medium can be executed successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:
EXP.NO:10 SET UP A CLOUD PLATFORM TO LOG THE DATA

DATE:

AIM:

To create a channel through ThingSpeak cloud Account.

PROCEDURE:
1. Input: Obtain user information such as email, username, and password.
2. Validate Input:
Check if the email format is valid.
Check if the username meets any requirements (e.g., length, allowed characters).
Ensure the password meets security requirements (e.g., minimum length,
combination of characters).
3. Send Registration Request:
Construct a request containing the user's information (email, username, password).
Send the registration request to the ThingSpeak server.
4. Receive Response:
Wait for a response from the ThingSpeak server.
Handle different types of responses:
Success: Account created successfully.
Failure: Registration failed, handle error messages accordingly (e.g., email
already in use, invalid username).
5. Verify Email:
If the registration is successful, send a verification email to the provided email
address.
Include a verification link that the user can click to confirm their email.
6. Handle Verification:
Wait for the user to click the verification link in the email.
Once clicked, mark the email as verified in the system.
7. Log In (Optional):
If desired, automatically log the user into their new ThingSpeak account.
8. Completion
Notify the user that their account has been successfully created and verified.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

RESULT

Thus creation of channel through Thing Speak cloud Account can be done.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EXP.NO: 11 LOG DATA USING RASPBERRY PI AND UPLOAD TO THE CLOUD PLATFORM

DATE:

AIM:
To write the python program for Log Temperature Data using raspberry Pi and Upload to the Cloud
Platform.

Connection Details for LM35 Temperature Sensor:


Note: See J13 Connector from left to right 3rd

Raspberry
PiPiCoW
LM35
GP26

PROCEDURE:
1.Setup Raspberry Pi and Sensor
2.Install Required Libraries:
3.Write Python Program
4.Set Up Cloud Platform
5.Upload Data to Cloud
6.Schedule Data Upload

PROGRAM:
import network
import urequests
from time import sleep
import machine
sensor_temp = machine.ADC(26)
#NetworkInitialization
ssid = "IElec
Systems"password="9840838264"

def ConnectWiFi():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
while wlan.isconnected()==False:
print('Waiting for connection...')sleep(1)
ip = wlan.ifconfig()[0]
print(f'Connected on {ip}')
returnip

#Connect to Network
ip = ConnectWiFi()
#ThingSpeakInitialization

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

server = "http://api.thingspeak.com/"
apikey="74085BCYRZG0G9YJ"
field =1

#Main Program
whileTrue:
temperature = sensor_temp.read_u16()
temperature = ((temperature/65535)*3300)/10
print(temperature)

url = f"{server}/update?api_key={apikey}&field{field}={temperature}"
request = urequests.post(url)
request.close()

sleep(20)

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

OUTPUT:

RESULT:
Thus the python program for Log Temperature Data using raspberry Pi and Upload to the Cloud
Platform can be done successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

EXP.NO: 12 DESIGN AN IOT BASED SYSTEM


DATE:

AIM:
To design smart healthcare using IOT.
INTRODUCTION:
Smart healthcare using IoT involves leveraging IOT technologies to enhance healthcare
services, improve patient monitoring, enable remote healthcare delivery and streamline
healthcare operations.

EQUIPMENT REQUIRED
S.No Components Quantity
1 Arduino UNO Board 1
2 Pulse Sensor 1
3 16X2 I2C LCD Display 1
4 Jumper Wires 10
5 Breadboard 1

CIRCUIT DIAGRAM:

PULSE SENSOR
A pulse sensor is a hardware device that can be used to measure heart rate in real-
time. When paired with an Arduino microcontroller, you can create a simple yet effective
heart rate monitor. This sensor is quite easy to use and operate. Place your finger on top of

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

the sensor and it will sense the heartbeat by measuring the change in light from the expansion
of capillary blood vessels.
Physical Characteristics

 Dimensions: Approximately 0.625″ (15.875mm) in diameter


 Weight: Lightweight, usually around a few grams
 Material: Biocompatible materials for safe skin contact

Electrical Characteristics

 Operating Voltage: 3V – 5.5V


 Current Consumption: Typically around 4mA
 Output Signal: Analog (0.3V to VCC)
 Signal Range: 0-1023 (10-bit ADC output of Arduino)

Sensing Technology

 Sensor Type: Photo plethysmo gram (PPG)


 Wavelength: Typically around 565nm (Green LED)

Working of the Pulse Sensor


The Pulse Sensor works on the principle of Photoplethysmography (PPG), which is a non-
invasive method for measuring changes in blood volume under the skin. The sensor
essentially consists of two main components: a light-emitting diode (LED) that shines light
into the skin and a photo detector that measures the amount of light that is reflected back.
Here’s a detailed explanation of its working:

Pulse Sensor Library Installation


Before moving to the coding part, you need to add the Pulse Sensor Library on your Arduino
Library Folder.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

Download the Pulse Sensor Playground Library from the Arduino IDE (Go to Sketch -
> Include Library -> Manage Libraries, then search for “PulseSensor Playground” and install
it).

You visit Pulse Sensor Github repository to see the examples code with different
microcontrollers.

Source Code/Program
#define USE_ARDUINO_INTERRUPTS true
// Include necessary libraries
#include <PulseSensorPlayground.h>

// Constants
const int PULSE_SENSOR_PIN = 0; // Analog PIN where the PulseSensor is connected
const int LED_PIN = 13; // On-board LED PIN
const int THRESHOLD = 550; // Threshold for detecting a heartbeat

// Create PulseSensorPlayground object


PulseSensorPlaygroundpulseSensor;

void setup()
{
// Initialize Serial Monitor
Serial.begin(9600);

// Configure PulseSensor
pulseSensor.analogInput(PULSE_SENSOR_PIN);
pulseSensor.blinkOnPulse(LED_PIN);
pulseSensor.setThreshold(THRESHOLD);

// Check if PulseSensor is initialized


if (pulseSensor.begin())
{
Serial.println("PulseSensor object created successfully!");
}
}

void loop()
{
// Get the current Beats Per Minute (BPM)
int currentBPM = pulseSensor.getBeatsPerMinute();

// Check if a heartbeat is detected


if (pulseSensor.sawStartOfBeat())
{
Serial.println("♥ A HeartBeat Happened!");
Serial.print("BPM: ");
Serial.println(currentBPM);
}

// Add a small delay to reduce CPU usage

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

delay(20);
}

OUTPUT:

Displaying Pulse Rate (BPM) Value on LCD Display


Instead of displaying the BPM value on Serial Monitor, we can display the value on LCD
Display. We can use a 16×2 I2C LCD Display Code and interface with Arduino Board to
display Pulse Sensor BPM Value.

Hardware Wiring Diagram


Since we are using an I2C LCD Display, connect it to the Arduino I2C Pins.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

 VCC (Power): Connect the VCC pin on the I2C LCD to the 5V pin on the Arduino.
 GND (Ground): Connect the GND pin on the I2C LCD to the GND pin on the
Arduino.
 SCL (Clock): Connect the SCL pin on the I2C LCD to the SCL pin (A5) on the
Arduino.
 SDA (Data): Connect the SDA pin on the I2C LCD to the SDA (A4) pin on the
Arduino.

Source Code/Program
The code requires I2C LCD Library for compilation. Therefore download the library and
add it to the Arduino library folder.

// Include necessary libraries


#define USE_ARDUINO_INTERRUPTS true
#include <PulseSensorPlayground.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line
display

// Constants
const int PULSE_SENSOR_PIN = 0; // Analog PIN where the PulseSensor is connected
const int LED_PIN = 13; // On-board LED PIN
const int THRESHOLD = 550; // Threshold for detecting a heartbeat

// Create PulseSensorPlayground object


PulseSensorPlaygroundpulseSensor;

void setup()
{
// Initialize Serial Monitor
1
Serial.begin(9600);
lcd.init();
lcd.backlight();

// Configure PulseSensor
pulseSensor.analogInput(PULSE_SENSOR_PIN);
pulseSensor.blinkOnPulse(LED_PIN);
pulseSensor.setThreshold(THRESHOLD);

// Check if PulseSensor is initialized


if (pulseSensor.begin())
{
Serial.println("PulseSensor object created successfully!");
}
}

void loop()
{
lcd.setCursor(0, 0);
lcd.print("Heart Rate");

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:


REGISTER NO:

// Get the current Beats Per Minute (BPM)


int currentBPM = pulseSensor.getBeatsPerMinute();

// Check if a heartbeat is detected


if (pulseSensor.sawStartOfBeat())
{
Serial.println("♥ A HeartBeat Happened!");
Serial.print("BPM: ");
Serial.println(currentBPM);

lcd.clear();
lcd.setCursor(0, 1);
lcd.print("BPM: ");
lcd.print(currentBPM);
}

// Add a small delay to reduce CPU usage


delay(20);
}

RESULT:
Thus the design smart healthcare using IOT can be done successfully.

DEPARTMENT OF CSE CS3691/EMBEDDED SYSTEMS AND IOT LAB PAGE NO:

You might also like