0% found this document useful (0 votes)
31 views74 pages

IOT Lab Manual-1

The document outlines the practical laboratory work for the CS3691 Embedded Systems and IoT course at the Global Institute of Engineering and Technology for the academic year 2024-2025. It includes a bonafide certificate, an index of experiments, and detailed procedures for various programming tasks using Keil and EDSIM51 software, as well as 8051 microcontroller operations. The experiments cover topics such as arithmetic operations, logical operations, data transfer, and comparison of numbers.

Uploaded by

gdharanidharan90
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)
31 views74 pages

IOT Lab Manual-1

The document outlines the practical laboratory work for the CS3691 Embedded Systems and IoT course at the Global Institute of Engineering and Technology for the academic year 2024-2025. It includes a bonafide certificate, an index of experiments, and detailed procedures for various programming tasks using Keil and EDSIM51 software, as well as 8051 microcontroller operations. The experiments cover topics such as arithmetic operations, logical operations, data transfer, and comparison of numbers.

Uploaded by

gdharanidharan90
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/ 74

GLOBAL

INSTITUTE OF ENGINEERING AND TECHNOLOGY


MELVISHARAM, RANIPET-632509

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E–

COMPUTER SCIENCE AND ENGINEERING

CS3691-EMBEDDED SYSTEMS AND IOT LABORATORY

ACADEMIC YEAR (2024-2025)

NAME :

REGNO :

YEAR/SEM : III/VI
BONAFIDE CERTIFICATE

Name :

Course : B.E -CSE

Year / Semester : III /VI

Register No :

Certified that this is a bonafide record of work done by the above student in the

CS3691-EMBEDDED SYSTEMS AND IOT LABORATORY during the period

2023 to 2024.

Staff-in-Charge Head of the Department

Submitted for the Practical examination held on at Global Institute of


Engineering and Technology, Melvisharam, Ranipet-632509.

Internal Examiner External Examiner


INDEX

Exp. No Date Name of the Experiment Page No Marks Sign


INDEX

Exp. No Date Name of the Experiment Page No Marks Sign


Exp. No : 1

KEIL SOFTWARE PROGRAMMING PROCEDURE


Date :

AIM:
To Write Embedded C Or Assembly Program In Keil, Software.

PROCEDURE :
STEP-1:
Install Keil Microvision-4 In Your Pc, Then After Click On That "Keil Uvision-2" Icon.
AfterOpening The Window Go To Toolbar And Select Project Tab Then Close Previous
Project.
STEP-2:
Next Select New Project From Project
Tab.

STEP-3:

Then It Will Open "Create New Project" Window. Select The Path Where You Want To Save
ProjectAnd Edit Project Name.
STEP-4:
Next It Opens "Select Device For Target" Window, It Shows List Of Companies And Here
You CanSelect The Device Manufacturer Company.
STEP-5:
For An Example, For Your Project Purpose You Can Select The Chip As 89c51/52 From
Atmel Group. Next Click Ok Button, It Appears Empty Window Here You Can Observe Left
Side A SmallWindow I.E, "Project Window". Next Create A New File.
STEP-6:
From The Main Tool Bar Menu Select "File" Tab And Go To New, Then It Will Open A
Window,There You Can Edit The Program.
STEP-7:
Here You Can Edit The Program As Which Language Will You Prefer Either
Assembly Or C.

1
STEP-8:
After Editing The Program Save The File With Extension As ".C" Or ".Asm", If You Write
A Program In Assembly Language Save As ".Asm" Or If You Write A Program In C
Language Save As".C" In The Selected Path. Take An Example And Save The File As
"Test.C".

STEP-9:
Then After Saving The File, Compile The Program, For Compilation Go To Project Window
Select"Source Group" And Right Click On That And Go To "Add Files To Group".

STEP-10:
Here It Will Ask Which File Has To Add. For An Example Here You Can Add "Test.C" As
YouSaved Before
STEP-11:
After Adding The File, Again Go To Project Window And Right Click On Your "C File"
Then Select"Build Target" For Compilation. If There Is Any "Errors Or Warnings" In Your
Program You Can Check In "Output Window" That Is Shown Bottom Of The Keil Window.
STEP-12:
Here In This Step You Can Observe The Output Window For "Errors And
Warnings.

STEP-13:
If You Make Any Mistake In Your Program You Can Check In This Slide For Which Error
AndWhere The Error Is By Clicking On That Error
STEP-14:
After Compilation Then Next Go To Debug Session.In Tool Bar Menu Go To "Debug" Tab
AndSelect "Start/Stop Debug Session".
STEP-15:
To See The Ports And Other Peripheral Features Go To Main Toolbar Menu And Select
Peripherals.

STEP-16:
In This Slide See The Selected Port I.E,
Port-1.

2
STEP-17:

Start To Trace The Program In Sequence Manner Ie, Step By Step Execution And Observe
TheOutput In Port Window
STEP-18:
After Completion Of Debug Session Create An Hex File For Burning The Processor. Here
To CreateAn Hex File Go To Project Window And Right Click On Target Next Select
"Option For Target".

STEP-19:
It Appears One Window; Here In "Target Tab" Modify The Crystal Frequency As You
Connected ToYour Microcontroller.
STEP-20:
Next Go To "Output' Tab. In That Output Tab Click On "Create Hex File" And Then
Click Ok.

STEP-21:
Finally Once Again Compile Your Program. The Created Hex File Will Appear In Your Path
Folder

RESULT:
Thus The Embedded C Or Assembly Program In Keil Software Is Written Successfully.

3
Exp. No : 2

EDSIM51 SOFTWARE PROGRAMMING PROCEDURE


Date :

AIM:
To Write Embedded C Or Assembly Program In EDSIM51 Software.

PROCEDURE:
1. Launch The Edsim51di Simulator.
2. Click New In The Edsim51di IDE.
3. Click New And Encode The Following Instructions At The IDE.
4. To speed up the output. Click Update Frequency (Update Freq.). For this program,
choose
1. his pr
5. To Save Your Program. Click Save. Use Any Filename In Saving Your Program.
6. Assemble The Program. Click Assm.
7. To Observe The Output. Click Run. Answer Q1.
8. To Pause The Execution. Click Pause.
9. To Stop Program Execution. Click RST.
10. Click Assm.
11. To Execute The Program Line Per Line. Click Step.
12. Observe The Content Of The Registers At The Left Side Of The Simulator.
13. Click Pause.
14. Το Encode, Edit, And Debug The Program. Click RST. 15. Add The Instruction MOV

R5,#256 After MOV RO, A.


16. Click Save.
17. Click Assm.
18. Click Run. Answer Q2.

4
19. Click RST. Add The Following Into The Encoded Program (After MOV RO, A)
A. Use Register B To Store 3CH.
B. Add The Content Of Registers A And B.
C. Store The Result (Sum) In Register A.
20. Click Save.
21. Click Assm.
22. Click Run. Answer Q3, Q4, And Q5.

RESULT:
Thus The Embedded C Or Assembly Program In EDSIM51 Software Is Written Successfully.

5
Exp. No : 3
8 BIT ADDITION USING ARITHMETIC OPERATION 8051
Date : MICROCONTROLLER (USING SIMULATOR)

AIM:
To write an ALP program to add, Subtract, multiply and divide two 8-bit
numbers using 8051 microcontroller.
Addition Program ALGORITHM:
➢ Clear carry.
➢ Load accumulator A with any desired 8-bitdata.
➢ Add accumulator with 8-bitnumbers.
➢ Store the result using DPTR.
➢ Stop the program.

Subtraction program ALGORITHM:


➢ Clear carry.
➢ Load accumulator A with any desired 8-bitdata.
➢ Subtract accumulator with 8-bitnumbers.
➢ Store the result using DPTR.
➢ Stop the program.

Multiplication program ALGORITHM:


➢ Load accumulator A with any desired 8-bitdata.
➢ Load B Register with any desired 8-bitdata.
➢ Multiply Accumulator with B register.
➢ Store the result Present in Accumulator and B register using DPTR.
➢ Stop the program.

Division program ALGORITHM:


➢ Load accumulator A with any desired 8-bitdata.
➢ Load B Register with any desired 8-bitdata.
➢ Divide Accumulator with B register.
➢ Store the result Present in Accumulator and B register using DPTR.
➢ Stop the program.

6
FLOW CHART:

7
MEMORY
OPCODES LABEL PROGRAM COMMENDS
LOCATION

Addition program
0000 74, 07 MOV A, #07 Move data to Acc

0002 75 ,F0, 03 MOV B, #03 Move data to B Reg

0005 25, F0 ADD A,B Adding Acc with B Reg.

0007 F8 MOV R0,A Move result to R0 Reg.

0008 80, FE HERE: SJMP HERE Short jump here

Subtraction program
0000 74, 07 MOV A, #07 Move data to Acc

0002 75, F0, 03 MOV B, #03 Move data to B Reg

0005 95, F0 SUBB A,B Subtract Acc with B Reg.

0007 F9 MOV R1,A Move result to R1 Reg.

0008 80, FE HERE: SJMP HERE Short jump here

Multiplication program
0000 74, FF MOV A,#0FFH Move data to Acc

0002 75, F0, 03 MOV B,#03 Move data to B Reg

0005 A4 MUL AB Multiplying Acc wit B Reg.

0006 FB MOV R3,A Move Result to R3 Reg.

0007 AC, F0 MOV R4,B Move Carry to R4 Reg.

0009 80, FE HERE: SJMP HERE Short jump here

8
MEMORY
OPCODES LABEL PROGRAM COMMENDS
LOCATION

Division program
0000 74, 0D MOV A,#13 Move data to Acc

0002 75, F0, 02 MOV B,#03 Move data to B Reg.

0005 84 DIV AB Divide Acc with B Reg.

0006 FB MOV R3,A DPTR = 4500

AC, F0 Store result in 4500 memory


0007 MOV R4,B location

0009 80, FE HERE: SJMP HERE DPTR = DPTR+1

INPUT OUTPUT

ADDITION
ACC R0
B Reg
SUBTRACTION
ACC R1
B Reg
MULTIPLICATION
ACC R3
B Reg R4
DIVISION
ACC R3
B Reg R4

RESULT:
Thus the 8051 ALP for Addition, Subtraction, Multiplication and Division of two 8bit numbers
is executed.

9
Exp. No : 4
LOGICAL OPERATIONS AND 2’s COMPLEMENT USING
Date : 8051 MICROCONTROLLER

AIM:
To perform logical operation using 8051 microcontroller AND, OR & EX-OR.

ALGORITHM:

1. Get the input value and store data in the accumulator.

2. Get the second values and store the B register.

3. Logical operation to perform the given number

4. Store the output value in memory.

10
MEMORY
OPCODES LABEL PROGRAM COMMENDS
LOCATION

AND Operation program


0000 C3 CLR C Clear the carry
0001 74,07 MOV A, #07 Move data to Acc

0003 54,03 ANL A, #03 AND Acc with immediate


0005 F8 MOV R0, A Move result to R0 Reg

0006 80,FE HERE: SJMP HERE Short jump here

OR Operation program
0000 C3 CLR C Clear the carry
0001 74,07 MOV A, #07 Move data to Acc
0003 44,03 ORL A, #03 OR Acc with immediate
0005 F4 MOV R1, A Move result to R1 Reg
0006 80,FE HERE: SJMP HERE Short jump here

XOR OPERATION PROGRAM

0000 C3 CLR C Clear the carry

0001 74,07 MOV A, #07 Move data to Acc


XOR Acc with immediate
0003 64,03 XRL A, #03 data
0005 FA MOV R2, A Move result to R2 Reg

0006 80,FE HERE: SJMP HERE Short jump here

2’s COMPLEMENT PROGRAM


0000 C3 CLR C Clear the carry

0001 74,07 MOV A, #07 Move data to Acc

0003 F4 CPL A Complement Accumulator

0004 04 INC A A = A+1

0005 FB MOV R3,A Move result to R3 Reg

0006 80,FE HERE: SJMP HERE Short jump here

11
INPUT OUTPUT

ADD
DATA1
R0
DATA 2

OR
DATA1
R1
DATA 2
XOR
DATA1
R2
DATA 2

2’s COMPLEMENT
DATA1
R3

RESULT:
Thus the assembly language program to perform logical operations AND,
OR & EX-OR and 2’s Complement using 8051 Performed and the result is
stored.

12
Exp. No : 5
TEST DATA TRANSFER BETWEEN REGISTER AND
Date : MEMORY

AIM:
To do test data transfer between registers and memory using instructions.

APPARATUS REQUIRED:
8051 Microcontroller Emulator Software

ALGORITHM:
1. Load Accumulator with value

2. The value of accumulator is moved to an address

3. Load accumulator to Register R2

4. The value of accumulator is moved to another address

5. Move the value 0 to Register R1

6. Move the value 0 to another address

13
PROGRAM:

LABEL ADDRESS MNEMONICS COMMENTS


ORG 00H Start

MOV A, #54H Load Accumulator with value

MOV 01H, A The value of accumulator is


moved to an address

MOV R2, A Load accumulator to Register R2

MOV 07H, A The value of accumulator is


moved to another address

MOV R1, #00H Move the value 0 to Register R1

MOV 02H,#00H Move the value 0 to another


address

HALT: SJMP HALT Stop

RESULT:
Thus the programs to move the value between registers and memory with 8051
microcontrollers has been written and executed.

14
Exp. No : 6

COMPARE 2 NUMBERS IN 8051


Date :

AIM:
To write a program to compare 2numbers in 8051 using stimulator.

ALGORITHM:
1. Load the first number into a region.
2. Load the second number into another register.
3. Compare the two numbers using comparison instruction CJNE.
4. Compare and jump if not equal.
5. If the numbers are equal , execute code block A.
6. If the numbers are not equal , execute code block B.
7. End the program.

PROGRAM:
ORG 0000H;
MOV A,#10H;
MOV B,#15H;
CJNE A,B,NOT_EQUAL;
SJMP END_PROGRAM;
NOT_EQUAL;
END_PROGRAM;

OUTPUT:
10H is not equal to
15H
NOT_EQUAL

RESULT:

Thus, to compare 2 numbers using stimulator has been done successfully and executed.

15
Exp. No : 7
8 BIT ARITHMETIC OPERATION USING 8051
Date : MICROCONTROLLER – C PROGRAMMING

AIM:
To write an Arithmetic program to add, Subtract, multiply and divide two8-bit
numbers using C Programming for 8051 microcontroller.
Addition Program ALGORITHM:
➢ Assign any desired 8-bitdata to a variable x.
➢ Assign another desired 8-bitdata to another variable y.
➢ Add two 8-bitnumbers and store in another variable z.
➢ Store the result in Port 0

Subtraction program ALGORITHM:


➢ Assign any desired 8-bitdata to a variable a.
➢ Assign another desired 8-bitdata to another variable b.
➢ Subtract two 8-bitnumbers and store in another variable c.
➢ Store the result in Port 1

Multiplication program ALGORITHM:


➢ Assign any desired 8-bitdata to a variable d.
➢ Assign another desired 8-bitdata to another variable e.
➢ Multiply two 8-bitnumbers and store in another variable f.
➢ Store the result in Port 2

Division program ALGORITHM:


➢ Assign any desired 8-bitdata to a variable p.
➢ Assign another desired 8-bitdata to another variable q.
➢ Divide two 8-bitnumbers and store in another variable r.
➢ Store the result in Port 3
➢ Stop the program.

16
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=0x03; //first 8-bit number

y=0x04; //second 8-bit number

P0=0x00; //declare port 0 as output port

z=x+y; // perform addition

P0=z; //display result on port 0


//subtraction
a=0x03; //first 8-bit number

b=0x04; //second 8-bit number

P1=0x00; //declare port 1 as output port

c=b-a; // perform subtraction

P1=c; //display result on port 1

//multiplication
d=0x03; //first 8-bit number

e=0x04; //second 8-bit number

P2=0x00; //declare port 2 as output port

f=e*d; // perform multiplication

P2=f; //display result on port 2

//division
p=0x03; //first 8-bit number

q=0x04; //second 8-bit number

P3=0x00; //declare port 3 as output port

17
r=q/p; // perform division

P3=r; //display result on port 3

while(1);}

OUTPUT:

INPUT OUTPUT

ADDITION
DATA1 PORT 0
DATA 2

SUBTRACTION
DATA1 PORT 1
DATA 2

MULTIPLICATION
DATA1
PORT 2
DATA 2
DIVISION
DATA1 PORT 3
DATA 2

RESULT:
Thus the 8051 C – Programming for Addition, Subtraction, Multiplication and Division of
two 8 bit numbers is executed in Keil.

18
Exp. No : 8

TRANSFER BETWEEN 2 REGISTERS IN 8051


Date :

AIM:
To write a C program in embedded for transferring the data between 2 registers.

ALGORITHM:

1. Declare two unsigned char variables to represent the source register and the destination register.
2. Assign a value to source register.
3. Transfer the data from source register to destination register by assigning the values of
sourceregister to destination.
4. Display or use the data stored.
5. End the program.

PROGRAM:
#include<reg51.h>
Void main()
{
unsigned char src_reg,dest_reg;
src_reg=0x0A;
dest_reg=src_reg;
P0=dest_reg;
while(1);
}

OUTPUT:

P0=0x0A

RESULT:
Thus, writing a program for transferring data between 2registers using embedded C has been
donesuccessfully and executed.

19
Exp. No : 9

ASCENDING ORDER USING EMBEDDED C


Date :

AIM:

To write a program to find the ascending order using embedded c.

ALGORITHM:

1. Initialize the variables and get the array to be sorted.


2. Iterate through the array and compare each element with every other element .
3. If the current element is greater than the next element swap them.
4. Repeat this process until the entire array is sorted in ascending order.
5. Once the array is sorted the elements will be in ascending order.
6. End the program.

PROGRAM:

#include<reg51.h>int
main()
{
unsigned char temp,i,j,a[5];
printf(“enter array elements:”);
for(i=0;i<5;i++){
scanf(“%d”,&a[i]);}
for(i=0;i<5;i++){
for(j=i+1;j<5;j++){ if(a[i]>a[j]){
temp=a[i];a[i]=a[j];
a[j]=temp;}}} printf(“array
elements:”);for(i=0;i<5;i++){
printf(“%d”,a[i]);}
return 0;`}

OUTPUT:
Enter the array elements:2 1 5 3 4
Array elements: 1 2 3 4 5

RESULT:
Thus to write a program to find the ascending order using embedded c has been done
successfully and executed.

20
Exp. No : 10

COMPARE 2 NUMBER USING EMBEDDED C


Date :

AIM:
To write a program for comparing two numbers in embedded c.

ALGORITHM;
1. Define two variable to hold the numbers to be compared.
2. Get the values .
3. Compare the two numbers using if statement .
4. If two numbers are equal the print the values are equal.
5. If the numbers are not equal then check whether n1 is greater than n2 .
6. Print n1 is bigger.
7. Else print n2 is bigger.
8. End the program.

PROGRAM:
#include<reg51.h
>int main()
{
float num1,num2;
printf(“enter the first number(integer):”);
scanf(“%F”,&num1);
printf(“enter the second number (integer):”);
scanf(“%F”,&num2);
int
n1,n2;
n1=num1
;
n2=num2
;
if((n1!=num1)||(n2!=num2))
{
printf(“Warning 1comparing only inter part\n”);}
If(n1=n2){
printf(“number are qual\n”);}
else {
if(n1<n2){
printf(“%d is bigger
\n”,n2);}else{
printf(“%d is bigger \n”,n1);
21
}}

OUTPUT:
Enter the first number(integer):4.0
Enter the second number(integer):4.0
Numbers are equal

RESULT:
Thus to write a program for comparing two numbers using embedded c has been done successfully and executed.

22
Exp. No : 11

DESCENDING ORDER USING EMBEDDED C


Date :

AIM:
To write a program to find the descending order using embedded c.

ALGORITHM:
1. Initialize the variables and get the array to be sorted.
2. Iterate through the array and compare each element with every other element .
3. If the current element is less than the next element swap them.
4. Repeat this process until the entire array is sorted in ascending order.
5. Once the array is sorted the elements will be in descending order.
6. End the program.

PROGRAM:
#include<reg51.h>
int main()
{
unsigned char temp,i,j,a[5];
printf(“enter array
elements:”);for(i=0;i<5;i++){
scanf(“%d”,&a[i]);}
for(i=0;i<5;i++){
for(j=i+1;j<5;j++){
if(a[i]<a[j]){
temp=a[i];
a[i]=a[j];
a[j]=temp;
}}}
printf(“array elements:”);
for(i=0;i<5;i++){
printf(“%d”,a[i]);}
return 0;`
}
OUTPUT:
Enter the array elements:2 1 3 5 4
Array elements: 5 4 3 2 1

RESULT:
Thus to write a program to find the descending order using embedded c has been done
successfullyand executed.

23
Exp. No : 12

IDENTIFY PARTICULAR NUMBER USING EMBEDDED C


Date :

AIM:
To write a program to identify particular number in the group using embedded C.

ALGORITHM:
1. Initialize an array with the elements of the group.
2. Define the target number that you want to identify within the group.
3. Iterate through the array.
4. For each element in the array, compare it with the target number.
5. If the current element matches the target number, set a flag to indicate that the
targetnumber is found and exit the loop.
6. After iterating through all elements, check the flag to determine whether the
targetnumber was found or not.
7. Display a message indicating whether the target number was found or not.

PROGRAM:
#include <reg51.h>
#define SIZE 5
void main() {
unsigned char arr[SIZE] = {5, 2, 8, 1,
6};unsigned char target ;
unsigned char found =
0;unsigned char i;
printf(“enter the target
number:”);scanf(“%d”,&target);
for (i = 0; i < SIZE; i++)
{if (arr[i] == target) {
found = 1;
break; }}
if (found){
P0 = 0xFF; }
else{
P1 = 0x00; }
while (1);
}

24
OUTPUT:
Enter the target
number: 8
P0=0Xff

RESULT:
Thus to write a program to find the descending order using embedded c has been done
successfullyand executed.

25
Exp. No : 13

LOGICAL OPERATION USING EMBEDDED C


Date :

AIM;

To write a program for logical operation using embedded c.

ALGORITHM;

1. Define variables x, y, z, a, b, c, p, q.
2. Assign values to x and y.
3. Perform NOT operation: Store the result in z, Display z on Port 0.
4. Perform AND operation: Store the result in a, Display a on Port 1.
5. Perform OR operation: Store the result in b, Display b on Port 2.
6. Perform XOR operation: Store the result in c, Display c on Port 3.
7. Perform left shift operation: Store the result in p.,Display p on Port 3.
8. Perform right shift operation: Store the result in q.Display q on Port 3.
9. Enter an infinite loop (while(1)).
10. End the program.

PROGRAM:

#
include<reg51.h>
void main(void)
{
unsigned char x,y,z, a,b,c,p,q; //define
variablesx=0x12; //first 8-bit number
y=0x34; //second 8-bit number
P0=0x00; //declare port 0 as output
portP1=0x00; //declare port 1 as
output portP2=0x00; //declare port 2
as output portP3=0x00; //declare port
3 as output portz=~x; // perform NOT
operation
P0=z; //display result of addition on port 0
a=x&y;//perform AND operation

26
P1=a;// display result of subtraction on port
1b=x|y;// perform OR operation
P2=b;//display result of multiplication on port
2c=x^y;//perform XOR operation
P3=c; // display result of division on port
3p=x<<1;//perform Left shift operation
P3=p; // display result of division on port
3
q=x>>1;//perform Right shift operation
P3=q; // display result of division on port
3while(1);
}

OUTPUT:
P0=0x0E
P1=0x10
P2=0x36
P3=0x26
Left shift P3=0x24
Right shift P3=0x09

RESULT:

Thus to perform a logical operation using embedded c has been done successfully and executed.

27
Exp. No : 14

SWAPPING DATA BETWEEN MEMORY AND REGISTER


Date :

AIM:
To write a program to swap data between memory and register using embedded c

ALGORITHM:
1. Define variables to hold the data stored in memory and the particular register.
2. Assign values to these variables to represent the initial data.
3. Use a temporary variable to store the data from memory.
4. Copy the data from the register to memory.
5. Copy the data from the temporary variable to the register.
6. Optionally, display or use the swapped data as needed

PROGRAM:
#include <reg51.h>
void main() {
unsigned char data_in_memory = 0x12; // Data stored in memory
unsigned char data_in_register = 0x34; // Data stored in a register
// Swap data between memory and register
unsigned char temp = data_in_memory; // Store data in memory in a temporary
variabledata_in_memory = data_in_register; // Store data from register in memory
data_in_register = temp; // Store data from temporary variable in register
// Display the swapped data
// Assuming P0 is used for displaying the data
P0 = data_in_memory; // Display data stored in
memoryP1 = data_in_register; // Display data stored in
register while (1); // Endless loop
}

OUTPUT:
P0=0x34
P1=0x12

RESULT:

Thus to write a program to swap the data between memory and register using embedded c has
been done successfully and executed .

28
Exp. No : 15

SMALLEST NUMBER USING EMBEDDED C


Date :

AIM:

To find the smallest number using embedded c.

ALGORITHM:

1. Declare an array of numbers.


2. Initialize variables to hold the smallest number.
3. Iterate through the array, comparing each element with the current smallest number.
4. Update the smallest number if a smaller number is found

PROGRAM:

#include <8051.h>
void main() {
unsigned char numbers[] = {5, 8, 2, 10, 6, 3, 1, 9, 4, 7};
unsigned char smallest = numbers[0]; // Assume the first number is the
smallestfor (unsigned char i = 1; i < 10; i++) {
// Compare each element with the current smallest
numberif (numbers[i] < smallest) {
// Update the smallest number if a smaller number is found
smallest = numbers[i];
}
}
while (1) {
// Your main application logic here
}
}

OUTPUT:

Smallest number=1

RESULT:
Thus to find the smallest number using embedded c has been done successfully and
executed .

29
Exp. No : 16

ARDUINO PROGRAMMNG
Date :

AIM:
To study about Arduino Board and how to do programming in Arduino.

APPARATUS REQUIRED:
• Arduino Development Board
• Arduino IDE Software

Arduino IDE
(Integrated Development Environment)

Arduino Software (IDE) is easy-to-use and is based on the Processing programming


environment. The Arduino Integrated Development Environment (IDE) is a cross-
platform application (for Windows, macOS, Linux) that is written in functions from C and
C++.The open-source Arduino Software (IDE) makes it easy to write code and upload it
to the board. This software can be used with any Arduino board.

The Arduino Software (IDE) – contains:

• A text editor for writing code


• A message area
• A text consoles
• A toolbar with buttons for common functions and a series of menus. It
connects to the Arduino hardware to upload programs and communicate
with them.

30
Installation of Arduino Software (IDE)

Step1: Downloading

➢ To install the Arduino software, download this page:


http://arduino.cc/en/Main/Softwareand proceed with the installation by allowing the
driver installation process.

Step 2: Directory Installation

➢ Choose the installation directory.

31
Step 3: Extraction of Files

➢ The process will extract and install all the required files to execute properly the
ArduinoSoftware (IDE)

Step 4: Connecting the board

➢ The USB connection with the PC is necessary to program the board and not just to power
it up. The Uno and Mega automatically draw power from either the USB or an external
power supply. Connect the board to the computer using the USB cable. The green power
LED (labelled PWR) should go on.

Step 5: Working on the new project

➢ Open the Arduino IDE software on your computer. Coding in the Arduino
language will control your circuit.
➢ Open a new sketch File by clicking on New.

32
Step 6: Working on an existing project

➢ To open an existing project example, select File → Example → Basics →Blink

33
Step 7: Select your Arduino board.

➢ To avoid any error while uploading your program to the board, you must select the
correct Arduino board name, which matches with the board connected to your computer.
➢ Go to Tools → Board and select your board.

Step 8: Select your serial port

➢ Select the serial device of the Arduino board.


➢ Go to Tools → Serial Port menu. This is likely to be COM3 or higher (COM1and COM2are
usually reserved for hardware serial ports).

34
➢ To find out, you can disconnect your Arduino board and re-open the menu, the entry that
disappears should be of the Arduino board. Reconnect the board and select that serial port.

Step 9: Upload the program to your board.

➢ Click the "Upload" button in the environment.


➢ Wait a few seconds; you will 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.

35
A Verify

B Upload

C New

D Open

E Save

F Serial Motor

36
Step 10: Example Code (Blink a LED light)
int ledPin = 13;

void setup ( )
{
pinMode (ledPin, OUTPUT); // Declare the LED as an output
}

void loop ( )
{
digitalWrite (ledPin, HIGH); // Turn the LED on
Delay (1000); // Delay 1000
millisecondsdigitalWrite (ledPin, LOW); // Turn the
led on
delay (1000); // Delay 1000 milliseconds
}

37
ARDUINO BOARDS

Arduino is a software as well as hardware platform that helps in making electronic projects.
It isan open source platform and has a variety of controllers and microprocessors. There are various
types ofArduino boards used for various purposes.

It also provides an IDE (Integrated Development Environment) project, which is based on the Processing
Language to upload the code to the physical board.

The Arduino is a single circuit board, which consists of different interfaces or parts. The board
consists of the set of digital and analog pins that are used to connect various devices and components,
which wewant to use for the functioning of the electronic devices.

The Arduino board consists of sets of analog and digital I/O (Input / Output) pins, which are further
interfaced to breadboard, expansion boards, and other circuits. Such boards feature the model,
Universal Serial Bus (USB), and serial communication interfaces, which are used for loading programs
from the computers.

The Arduino UNO is a standard board of Arduino. Here UNO means 'one' in Italian. It was named
as UNO to label the first release of Arduino Software. It was also the first USB board released by
Arduino.It is considered as the powerful board used in various projects. Arduino.cc developed the
Arduino UNOboard.

Arduino UNO is based on an ATmega328P microcontroller. It is easy to use compared to other


boards,such as the Arduino Mega board, etc. The board consists of digital and analog Input/Output
pins (I/O), shields, and other circuits.

The Arduino UNO includes 6 analog pin inputs, 14 digital pins, a USB connector, a power jack, and
anICSP (In-Circuit Serial Programming) header. It is programmed based on IDE, which stands for
Integrated Development Environment. It can run on both online and offline platforms.

38
Power USB
Arduino board can be powered by using the USB cable from your computer.

Power (Barrel Jack)


Arduino boards can be powered directly from the AC mains power supply
byconnecting it to the Barrel Jack (2).

Voltage Regulator
The function of the voltage regulator is to control the voltage given to the
Arduino board and stabilize the DC voltages used by the processor and other
elements.

Crystal Oscillator
The crystal oscillator helps Arduino in dealing with time issues. The number
printed on top of the Arduino crystal is 16.000H9H. It tells us that the
frequency is 16,000,000 Hertz or 16 MHz.

39
Arduino Reset
You can reset your Arduino board, i.e., start your program from the
beginning. You can reset the UNO board in two ways. First, by using the
reset button (17) on the board. Second, you can connect an external reset
button to the Arduino pin labelled RESET (5).

Pins (3.3, 5, GND, Vin)


• 3.3V (6) − Supply 3.3 output volt
• 5V (7) − Supply 5 output volt
• Most of the components used with Arduino board works fine with
3.3volt and 5 volt.
• GND (8) (Ground) − There are several GND pins on the Arduino, any
ofwhich can be used to ground your circuit.
• Vin (9) − This pin also can be used to power the Arduino board from
anexternal power source, like AC mains power supply.
Analog pins
The Arduino UNO board has six analog input pins A0 through A5. These
pins can read the signal from an analog sensor like the humidity sensor or
temperature sensor and convert it into a digital value that can be read by the
microprocessor.
Main microcontroller
Each Arduino board has its own microcontroller (11). You can assume it as
thebrain of your board. The main IC (integrated circuit) on the Arduino is
slightlydifferent from board to board. The microcontrollers are usually of the
ATMEL Company. You must know what IC your board has before loading
up a new program from the Arduino IDE. This information is available on
the top of theIC..
ICSP pin
Mostly, ICSP (12) is an AVR, a tiny programming header for the Arduino
consisting of MOSI, MISO, SCK, RESET, VCC, and GND. It is often
referred to as an SPI (Serial Peripheral Interface), which could be considered
as an "expansion" of the output.

Power LED indicator


This LED should light up when you plug your Arduino into a power source
to indicate that your board is powered up correctly. If this light does not turn
on, then there is something wrong with the connection.

TX and RX LEDs
On your board, you will find two labels: TX (transmit) and RX (receive).
Theyappear in two places on the Arduino UNO board. First, at the digital
pins 0 and 1, to indicate the pins responsible for serial communication.
Second, the TX and

40
RX led (13). The TX led flashes with different speed while sending the serial
data. The speed of flashing depends on the baud rate used by the board. RX
flashes during the receiving process.

Digital I/O
The Arduino UNO board has 14 digital I/O pins (of which 6 provide PWM
(Pulse Width Modulation) output. These pins can be configured to work as input
digital pins to read logic values (0 or 1) or as digital output pins to drive different
modules like LEDs, relays, etc. The pins labeled “~” can be used to generate
PWM.
AREF
AREF stands for Analog Reference. It is sometimes, used to set an external
reference voltage (between 0 and 5 Volts) as the upper limit for the analog input
pins.

RESULT:
Thus the Arduino Programming was studied and a sample program was executed in IDE.

41
Exp. No : 17

INTERFACING SENSORS WITH ARDUINO


Date :

AIM:
To interface various types of sensors with Arduino Board and display the result in the serial
monitor.

APPARATUS REQUIRED:
• Arduino Development Board
• Arduino IDE Software
• IR Sensor
• Ultrasonic Sensor
• Humidity Sensor
• Buzzer

ULTRASONIC SENSOR

Aim
Calculate the distance to an object with the help of an ultrasonic sensor and display it on an
LCD

Ultrasonic Sensors:
The HC-SR04 ultrasonic sensor uses SONAR to determine the distance of an object just like
thebats do. It offers excellent non-contact range detection with high accuracy and stable readings in an
easy- to-use package from 2 cm to 400 cm or 1” to 13 feet. It comes complete with ultrasonic
transmitter and receiver module. The ultrasonic sensor uses the reflection of sound in obtaining the
time between the wave sent and the wave received. It usually sent a wave at the transmission terminal
and receives the reflected waves. The time taken is used together with the normal speed of sound in
air (340ms-1) to determine the distance between the sensor and the obstacle. The Ultrasonic sensor
is used here for the intruder detection.

42
PROGRAM:
int trigPin= 9;
int echoPin= 10;void
setup ()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop ()
{
Serial.println("loop"); long
duration, distance;
digitalWrite(trigPin,HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration=pulseIn(echoPin, HIGH);
distance =(duration/2)/29.1;
Serial.print(distance);
Serial.println("CM"); delay(10);
}

43
OUTPUT:

RESULT:

Thus the Interfacing sensors with Arduino was studied and a sample program was executed .

44
Exp. No : 18

HUMIDITY SENSOR
Date :

AIM:
To study and Interface the Temperature and Humidity with the Arduino.

HUMIDITY SENSORS:

The Temperature Humidity sensor provides a pre-calibrated digital output. A unique capacitive
sensor element measures relative humidity and the temperature is measured by a negative
temperature coefficient (NTC) thermistor. It has excellent reliability and long term stability.

45
PROGRAM:
#include<dht11.h>
#define DHT11PIN 4
dht11 DHT11;
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println();
int chk = DHT11.read(DHT11PIN);
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);
Serial.print("Temperature (C): ");
Serial.println((float)DHT11.temperature, 2);delay(2000);
}

OUTPUT:

RESULT:

Thus the Humidity sensor with Arduino was studied and a sample program was executed .

46
Exp. No : 19

IR SENSOR
Date :

AIM:
To Identify the object detection using IR Sensor.

IR SENSOR:
An IR sensor or infrared sensor is a type of electronic device that emits light in order to detect certain
aspects of its surroundings. The sensor module is ambient light-adaptable, with a pair of infrared emitting
and receiving tubes. At a specific frequency, the transmitting tubes emit infrared. When the direction of
an obstacle is detected (reflective surface), the receiving tube receives the infrared reflected. After a
comparator circuit processing, the green light turns on. And the signal output interfaces a digital signal (a
low-level signal). The sensor’s effective distance range is 2 ~ 30cm. The sensor’s detection range can be
adjusted by adjusting the potentiometer.

47
PROGRAM:
const int irSensorPin = 2; // Change this to the appropriate pin

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

// Initialize the IR sensor pin as an INPUT


pinMode(irSensorPin, INPUT);
}

void loop() {
// Read the IR sensor value
int sensorValue = digitalRead(irSensorPin);

// Check if an obstacle is detectedif


(sensorValue == LOW)
{
// Obstacle detected Serial.println("Obstacle
detected!");
}
else {
// No obstacle detected Serial.println("No obstacle
detected.");
}
}

OUTPUT:

RESULT:

Thus the object detection using IR Sensor has been done successfully.

48
Exp. No : 20

BUZZER
Date :

AIM:
To create an alarm for the code using buzzer.

BUZZER:
Buzzer is the easiest and cost-effective way to add sound to your Arduino projects. Using a buzzer
we can create projects like timer, stopwatch, fire alarm, siren, etc. Most of the active buzzer works at a
voltage range of 3.3V – 5V and generate only one sound frequency. It can only generate a sound of fixed
frequency when you provide the required voltage to it.

49
PROGRAM:
int buzzerPin = 9; // You can change this to the appropriate pin

void setup() {
// Initialize the buzzer pin as an OUTPUTpinMode(buzzerPin,
OUTPUT);
}

void loop() {
// Turn the buzzer on
digitalWrite(buzzerPin, HIGH);

// Wait for a short duration (e.g., 500 milliseconds)delay(500);

// Turn the buzzer off


digitalWrite(buzzerPin, LOW);

// Wait for another short durationdelay(500);


}

RESULT:
Thus the various sensors are interfaced with Arduino and the outputs were obtained.

50
Exp. No : 21

COMMUNICATION MODULE – ZIGBEE & ARDUINO


Date :

AIM:
To communicate with Arduino using Zigbee Protocol model.

APPARATUS REQUIRED:
• Arduino Development Board
• Arduino IDE Software
• Zigbee modules

ZIGBEE MODULE:

Zigbee is a wireless communication protocol targeted for battery powered devices (it has both low power
and low cost). It generally operates in the 2.4GHz range and supports data ranges from 20 to 250
kbits/s.

Digi International developed the XBee modules, a family of wireless communication devices. These
modules support various wireless communication protocols, including Zigbee, Wi-Fi, and cellular,
and they can communicate over UART (Universal Asynchronous Receiver-Transmitter) interfaces.
These modules utilize Zigbee communication, which is a low-power wireless communication
protocol commonly used in home automation, industrial control, and sensor networks. XBee Zigbee
modules are

51
capable of forming mesh networks, making them suitable for applications where reliability and long-
range communication are essential.

PROGRAM:
#include <SoftwareSerial.h>

SoftwareSerial zigbeeSerial(2, 3); // RX (pin 1), TX (pin 2)void setup()


{
// Initialize the Hardware Serial interface (usually connected to yourcomputer)
Serial.begin(9600); // Use the appropriate baud rate

// Initialize the Software Serial interface (for the Zigbee module) zigbeeSerial.begin(9600); //
Use the same baud rate as your Zigbee module
}
void loop()
{
// Read data from Zigbee

52
if (zigbeeSerial.available()) {
char receivedChar = zigbeeSerial.read();
Serial.print("Received: ");
Serial.println(receivedChar); // Print received data to the Serial Monitor
}

// Send data to Zigbee


zigbeeSerial.print("Hello, Zigbee!"); // Send a message to the Zigbee moduledelay(1000); // Add a
delay to control message transmission rate
}

OUTPUT:
h
e
l
l
o

zigbee…

RESULT:
Thus the communication was established between Arduino and Zigbee Module. The data is
transmitted from Zigbee to Arduino.

53
Exp. No : 22
COMMUNICATE BETWEEN ARDUINO AND BLUETOOTH
Date : COMMUNICATION MODULE

AIM:

To communicate with Arduino using Bluetooth model.

APPARATUS REQUIRED:
• Arduino Development Board
• Arduino IDE Software
• Bluetooth Module

BLUETOOTH MODULE:

HC-05 is a Bluetooth device used for wireless communication with Bluetooth enabled devices (like
smartphone). It communicates with microcontrollers using serial communication (USART).
There is a simple example of establishing a serial connection between the HC -05 and the Smart
Phone and send/receive message

We will use pins 2and 3 of the Arduino to connect the HC-05 and use the SoftwareSerial library to
communicate with the module. The Hardware serial port on arduino is used to send/receive messages
from the computer to the Arduino.

CONNECTION ESTABLISHMENT OF BLUETOOTH HC05 AND SMARTPHONE


1) Pair HC05 module with your smartphone’s Bluetooth using 1234 as password. After getting
paired, the LED on HC05 module will blink intermittently.

To pair: Go to the smartphone Bluetooth settings and find nearby available Bluetooth devices. In this list
you will find HC05, select it and then it requires a password which is by default set as 1234 or 0000
enterthe password and devices are now paired.
2) Go to Google Play store and download the “Bluetooth terminal” app from it

3) Open the Bluetooth terminal app and search for the paired device and select it. Now, click on the
connect button that appears on the top right of your screen. Wait for the 5 seconds till you get
notification connected at the bottom and connect button changes in disconnect.

Now you just need to send data from the app which will be transmitted by phones BT through the
antenna and received by the HC05 antenna then HC05 transmit this data from its Tx to RX of the
arduino, but

54
data should be a character (integers are also characters in ASCII) not string here the instruction
Serial.read() works.

Serial.print() will transmit data from Arduino Tx to Rx of BT and then BT transmits it to the smartphone
through its antenna and that’s how the two-way communication works.

PROGRAM:

#include<SoftwareSerial.h>
/* Create object named bt of the class SoftwareSerial */SoftwareSerial
bt(2,3); /* (Rx,Tx) */

void setup() {
bt.begin(9600); /* Define baud rate for software serial communication */Serial.begin(9600); /*
Define baud rate for serial communication */

55
void loop() {

if (bt.available()) /* If data is available on serial port */


{
Serial.write(bt.read()); /* Print character received on to the serialmonitor */
}
}

OUTPUT:

RESULT:
Thus the communication was established between Arduino and Bluetooth Module. The data is
transmitted from Bluetooth to Arduino.

56
Exp. No : 23

RASPBERRY PI PROGRAMMING
Date :

AIM:
To study Raspberry Pi programming and installation procedure.
INTRODUCTION:
The Raspberry Pi is a low cost, credit-card sized computer that plugs into a computer monitor
or TV, and uses a standard keyboard and mouse. It is a capable little device that enables people of
all agesto explore computing, and to learn how to program in languages like Scratch and Python. It’s
capable ofdoing everything you’d expect a desktop computer to do, from browsing the internet and
playing high- definition video, to making spreadsheets, word-processing, and playing games.

ARCHITECTURE:

PIN DIAGRAM:

57
COMPONENTS:
● System on a Chip (SoC):
○ This is the main component of the Raspberry Pi, integrating the CPU, GPU, RAM,
andother essential elements.
● Central Processing Unit (CPU):
○ The CPU is the primary processing unit responsible for executing instructions,
runningprograms, and handling computations.
● Graphics Processing Unit (GPU):
○ The GPU handles graphical computations and is responsible for rendering video
andimages on the screen.
● RAM (Random Access Memory):
○ This is the memory that the Raspberry Pi uses to temporarily store data for quick
accessby the CPU. It's crucial for multitasking and running applications.
● GPIO (General Purpose Input/Output):
○ These pins allow the Raspberry Pi to interact with external components like
sensors,LEDs, buttons, and other devices.
● USB (Universal Serial Bus) Ports:
○ These ports enable the connection of various peripherals such as keyboards,
mice,storage devices, and other USB-compatible hardware.
● HDMI (High Definition Multimedia Interface):
○ The HDMI port provides high-definition audio and video output, allowing the
RaspberryPi to connect to monitors, TVs, or displays.
● Audio Output Jack:
○ This allows the connection of speakers, headphones, or audio systems for sound output.

● MicroSD Card Slot:


○ The Raspberry Pi uses a microSD card as its primary storage, where the
operatingsystem and user data are stored.
● Ethernet Port:
○ Some models include an Ethernet port for a wired network connection, enabling
internetaccess and local network communication.
● Wi-Fi and Bluetooth (on some models):
○ Integrated wireless connectivity allows the Raspberry Pi to connect to Wi-Fi networks
and Bluetooth-enabled devices.

58
● Camera and Display Ports:
○ Some models feature ports for connecting the Raspberry Pi Camera Module and
officialDisplay Module, enabling camera and display functionalities.
● Power Port:
○ The power port supplies the Raspberry Pi with the necessary electrical power,
oftenthrough a micro USB or USB-C port.

INSTALLATION:
1. Write the bootable Raspberry Pi OS image to the micro SD card or the USB drive directly
using the Raspberry Pi imager application.
2. Download the bootable ISO image of Raspberry Pi OS from the official Raspberry Pi
website and write using the Raspberry Pi imager or Etcher application to the micro SD
card or the USB drive.

Method 1: Flash the Ubuntu image to the micro SD or USB drive directly from the Raspberry
PiImager
Download the Raspberry Pi Imager application on your Windows PC or mac book. Just follow the
on- screen instructions, and the installation process should be completed in a few minutes. Once the
installation is complete, you can start exploring the features of the Raspberry Pi Imager application.
STEP 1: Download and Install the Raspberry Pi Imager application Raspberry
Pi Imager is a quick and easy way to install Raspberry Pi OS and other operating systems to
amicroSD card or USB drive.

59
STEP 2 : Run the Raspberry Pi Imager application

Upon installation, when you run the Imager application, you will be greeted with this window.

STEP 3: Choose Raspberry Pi OS Image on the Raspberry PI

STEP 4: Choose the Storage

Click on the Choose Storage button on the Imager application. That will show up on the list of
connectedmicros SD cards or USB storage devices. Select the one you want to install Raspberry Pi
OS.

STEP 5: Write the Raspberry Pi OS image to the


storage
Click on the Write button to start the writing process.

STEP 6: Raspberry Pi OS image is being written to the USB storage

STEP 7: Raspberry Pi OS image is being verified

STEP 8: Raspberry Pi OS image is written to the USB storage drive

STEP 9: Boot the Raspberry Pi inserting the USB drive

60
STEP 10: The colored window of Raspberry Pi. You will see a colored window like shown here.
Thisindicates that your Raspberry Pi passed the POST test and is ready to load the operating system.

STEP 11: Raspberry Pi OS is in the boot process

STEP 12: System Configuration Wizard

Upon the completion of the boot process. Raspberry Pi OS will throw a system configuration
wizard.Raspberry Pi OS will ask for several configurations to be set up. You should need to
Select the preferred settings to configure.
The configuration wizard starts from the Language selection all the way it goes to the keyboard,
network, time zone, and login user account settings.

61
STEP 13: Reboot the Raspberry Pi. Upon the completion of the set up process, system will ask
toreboot to complete the process. Click on the Reboot button to continue Reboot.

STEP 14: Raspberry Pi OS is running on the Raspberry Pi. That’s it. Immaterially, upon login,
youwill be greeted with this desktop screen.

RESULT:

Thus the study of Raspberry Pi and installation procedure was done.

62
Exp. No : 24

INTERFACE IR SENSOR WITH RASPBERRY PI


Date :

AIM:
To interface IR sensor with Raspberry PI

APPARATUS REQUIRED:
• Raspberry Pi
• IR Sensor
• Connecting cables

IR SENSOR:
An IR sensor or infrared sensor is a type of electronic device that emits light in order to detect certain
aspects of its surroundings. The sensor module is ambient light-adaptable, with a pair of infrared emitting
and receiving tubes. At a specific frequency, the transmitting tubes emit infrared. When the direction of
an obstacle is detected (reflective surface), the receiving tube receives the infrared reflected. After a
comparator circuit processing, the green light turns on. And the signal output interfaces a digital signal (a
low-level signal). The sensor’s effective distance range is 2 ~ 30cm. The sensor’s detection range can be
adjusted by adjusting the potentiometer.

63
PROGRAM:

import RPi.GPIO as
GPIOimport time
sensor=3
GPIO.setmode(GPIO.BOARD)
GPIO.setup(sensor,GPIO.PI
N) print “IR sensor
detected” print “”
Try:
While True:
If GPIO.input(sensor):
print(“object not detected”)
While GPIO.input(Sensor):
time.sleep(0.2)
Else:
print(“object detected”)
Except

KeyboardInterrupt
:
GPIO.cleanup()

RESULT:

Thus the IR sensor is interfaced with Raspberry Pi and the obstacle detection was monitored.

64
Exp. No : 25

COMMUNICATE ARDUINO AND RASPBERRY PI


Date :

AIM:
To communicate between Arduino and Raspberry Pi and forward a message from Arduino to
Raspberry Pi.

APPARATUS REQUIRED:
• Arduino UNO Board
• Raspberry Pi
• Connecting Cables

DIAGRAM:

65
PROGRAM:

Raspberry Pi and Arduino Communication

Step 1: Connect the Arduino to the raspberry pi with the help of a USB cable

Step 2: Open thonny and type in the following code to create a serial communication device
with the specified name and port
import serial
ser = serial.Serial('/dev/ttyACM0', 9600)

Step 3: check if the device was created by opening the terminal and typing the following
commandls /dev/tty*

Step 4: Open the arduino ide and upload the following code to the arduino board
void setup()
{
Serial.begin(9600);
}
void loop(){
Serial.println(“Hello Pi”);
delay(2000);
}

Step 5: Now connect the arduino to the raspberry pi again and add the following code to thonny
while 1 :
ser.readline()

Step 6: Now run the code again to observe the data being sent

OUTPUT:
Hello Pi

RESULT:
Thus the communication between Arduino and Raspberry Pi was established and the message was
sentfrom Arduino to Raspberry Pi using serial communication.

66
Exp. No : 26

LOG DATA USING CLOUD PLATFORM


Date :

AIM:
To create the simplest experiment by using an IoT module with interfaces on the ESP32.

PROCEDURE:
1. Set up the circuit as described in the “Circuit Connection” section.
2. Connect the ESP 32 to your computer using a USB cable.
3. Open the Arduino IDE software on your computer.
4. Write the code for adafruit io interface with Arduino.
5. Verify and upload the code to the ESP 32.

ARDUINO CODE:

#include <ESP8266WiFi.h> #include


"Adafruit_MQTT.h" #include
"Adafruit_MQTT_Client.h"#include
"DHT.h"
#define WLAN_SSID "YOUR_WIFI_SSID"
#define WLAN_PASS
"YOUR_WIFI_PASSWO
RD"
#define AIO_SERVER "io.adafruit.com"
#define AIO_SERVERPORT 1883 // use 8883 for SSL
#define AIO_USERNAME "umaece1982"
#define AIO_KEY "aio_EpaH61HXULkHr4c8izGTucz5Fqoi"
#define DHTPIN D6
#define DHTTYPE DHT11
DHT dht(DHTPIN,
DHTTYPE);
WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME,
AIO_KEY);
Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME
"feeds/temperature1");
Adafruit_MQTT_Publish humidity = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME
"feeds/humidity1");
void MQTT_connect();
void setup() {

67
Serial.begin(115200);
dht.begin();

delay(10);
Serial.println(F("Adafruit MQTT demo"));
Serial.println(); Serial.println();
Serial.print("Connecting to ");
Serial.println(WLAN_SSID);
WiFi.begin(WLAN_SSID, WLAN_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();

Serial.println("WiFi connected");
Serial.println("IP address: "); Serial.println(WiFi.localIP());
}

uint32_t x=0;
void loop() {
MQTT_connect();
float h = dht.readHumidity(); float t =
dht.readTemperature();
Serial.print(F("\nTemperature: "));
Serial.print(t); Serial.print(F("\nHumidity:
")); Serial.print(h); temperature.publish(t);
humidity.publish(h);
delay(60000);
}

void MQTT_connect() {
int8_t ret;
if (mqtt.connected()) {return;
}

Serial.print("Connecting to MQTT... ");uint8_t


retries = 3;
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
Serial.println(mqtt.connectErrorString(ret));
Serial.println("Retrying MQTT connection in 5 seconds...");
mqtt.disconnect();
delay(5000); // wait 5 secondsretries--;
if (retries == 0) {
// basically die and wait for WDT to reset mewhile (1);
}
}
68
Serial.println("MQTT Connected!");
}

Create Adafruit Account in https://accounts.adafruit.com/users/sign_in

Create Account using sign Up

OUTPUTS:

69
RESULT:
The ESP 32 successfully interfaces Adafruit io with Wi-Fi as programmed.

70

You might also like