0% found this document useful (0 votes)
15 views

Embedded lab manual

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Embedded lab manual

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 86

C.

ABDUL HAKEEM COLLEGE OF ENGINEERING AND TECHNOLOGY

MELVISHARAM- 632509

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEEIRNG

LAB MANUAL
CS3691
EMBEDDED SYSTEMS AND IOT (R-2021)
Sixth Semester

PREPARED BY
Ms. CHANDRIKA G
Ms. G. DIVYA
Assistant professor / ECE
INDEX
EXP Pg. Staff
Date Name of the experiment Mark
NO. No. Sign

1. 8 BIT USING ARITHMETIC OPERATION 8051 1


MICROCONTROLLER (USING SIMULATOR)
2. LOGICAL OPERATIONS AND 2’S COMPLEMENT USING 5
8051 MICROCONTROLLER (USING SIMULATOR)
3. TEST DATA TRANSFER BETWEEN REGISTER AND MEMORY 8

4. COMPARE 2 NUMBERS IN 8051 10

5. 8 BIT ARITHMETIC OPERATION USING 8051 11


MICROCONTROLLERC PROGRAMMING
6. TRANSFER BETWEEN 2REGISTERS IN 8051 14

7. ASCENDING ORDER USING EMBEDDED C 15


COMPARE TWO NUMBER USING EMBEDDED C
8. 16
DESCENDING ORDER USING EMBEDDED C
9. 18

10. IDENTIFY PARTICULAR NUMBER USING EMBEDDED C 19

11. LOGICAL OPERTAION USING EMBEDDED C 20


12. SWAPPING DATA BETWEEN MEMORY AND REGISTER 22
13. SMALLEST NUMBER USING EMBEDDED C 23
14. ARDUINO PROGRAMMING 24
15. INTERFACING SENSORS WITH ARDUINO 36
16. HUMIDITY SENSOR 38

17. IR SENSOR 40

18 BUZZER 42

19. COMMUNICATION MODULE-ZIGBEE & ARDUINO 44


20. COMMUNICATE BETWEEN ARDUINO AND BLUETOOTH 47
COMMUNICATION MODULE
21 RASPBERRY PI PROGRAMMING 50

22 INTERFACE IR SENSOR WITH RASPBERRY PI 56

23 COMMUNICATE ARDUINO AND RASPBERRY PI 58

24 LOG DATA USING CLOUD PLATFORM 60


EXP Pg. Staff
Date Name of the experiment Mark
No. Sign
NO.
CONTENT BEYOND SYLLABUS
1. ARITHMETIC OPERATION USING 8051 65

2. LARGEST NUMBER IN ARRAY OF 70


NUMBER
3. ASCENDING ORDER USING 8086 KIT 73

4. DESCENDING ORDER USING 8086 KIT 74

5. ONE’S &TWO’S COMPLEMENT:-USING 8051 75

ANNEXURE
Ex No:1
8 BIT USING ARITHMETIC OPERATION 8051
Date
MICROCONTROLLER (USING SIMULATOR)

AIM:

Addition Program ALGORITHM:


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

Subtraction program ALGORITHM:


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

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 theprogram.

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 theprogram.

1
FLOW CHART

2
MEMORY
OPCODES LABEL PROGRAM COMMENDS
LOCATION

Addition program
ORG 0H

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: JMP $ Short jump here

Subtraction program
ORG 0H

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: JMP $ Short jump here

Multiplication program
ORG 0H

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: JMP $ Short jump here

3
MEMORY
LOCATION OPCODES LABEL PROGRAM COMMENDS

Division program
ORG 0H

0000 74, 0D MOV A,#06 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: JMP $ 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.

4
Ex No:2 LOGICAL OPERATIONS AND 2’S COMPLEMENT USING 8051
Date MICROCONTROLLER (USING SIMULATOR)

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.

5
MEMORY
OPCODES LABEL PROGRAM COMMENDS
LOCATION

AND Operation program


0000 C3 ORG 0H 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: JMP $ Short jump here

OR Operation program
0000 C3 ORG 0H 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: JMP $ Short jump here

XOR OPERATION PROGRAM


0000 C3 ORG 0H 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: JMP $ Short jump here

2’s COMPLEMENT PROGRAM


0000 C3 ORG 0H 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: JMP $ Short jump here

6
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.

7
Ex No:3 TEST DATA TRANSFER BETWEEN REGISTER AND MEMORY
Date

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

APPARATUS REQUIRED:
8052Microcontroller 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

8
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: JMP $ Stop

RESULT:
Thus the programs to move the value between registers and memory with 8051
microcontrollers has been written and executed.
9
Ex No:4 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 note equal to 15H


NOT_EQUAL

RESULT:

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

10
Ex No:5 8 BIT ARITHMETIC OPERATION USING 8051 MICROCONTROLLER

C PROGRAMMING
Date

To write an Arithmetic program to add, Subtract, multiply and divide two8-bit


AIM: 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 theprogram.

11
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

r=q/p; // perform division

P3=r; //display result on port 3

while(1);}

12
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
bitnumbers is executed in Keil.
13
Ex No:6 TRANSFER BETWEEN 2REGISTERS 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 source
register 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 done
successfully and executed.
14
Ex No:7 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.

15 15
Ex No:8 COMPARE TWO 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);
}}

16
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.
17
Ex No:9 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 successfully
and executed.

18
Ex No:10 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 target
number is found and exit the loop.
6. After iterating through all elements, check the flag to determine whether the target
number 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);
}
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 successfully
and executed.

19
Ex No:11 LOGICAL OPERTAION 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 variables
x=0x12; //first 8-bit number
y=0x34; //second 8-bit number
P0=0x00; //declare port 0 as output port
P1=0x00; //declare port 1 as output port
P2=0x00; //declare port 2 as output port
P3=0x00; //declare port 3 as output port
z=~x; // perform NOT operation
P0=z; //display result of addition on port 0
a=x&y;//perform AND operation
P1=a;// display result of subtraction on port 1
b=x|y;// perform OR operation
P2=b;//display result of multiplication on port 2
c=x^y;//perform XOR operation
P3=c; // display result of division on port 3
p=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 3
while(1);
}
20
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 bee =n done successfully and executed

21
Ex No:12 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 variable
data_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 memory
P1 = 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 ahs been
done successfully and executed .

22
Ex No:13 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 smallest
for (unsigned char i = 1; i < 10; i++)
{
// Compare each element with the current smallest number
if (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 ,

23
Ex No:14 ARDUINO PROGRAMMING
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 DevelopmentEnvironment)

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


environment. The Arduino IntegratedDevelopment 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 Arduinoboard.

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.

24
Installation of Arduino Software (IDE)

Step1: Downloading

 To install the Arduino software, download this page: http://arduino.cc/en/Main/Software


and proceed with the installation by allowing the driver installation process.

Step 2: Directory Installation

 Choose the installation directory




25
Step 3: Extraction of Files

 The process will extract and install all the required files to execute properlythe Arduino
Software (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 fromeither 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 Arduinolanguage
will control your circuit.
 Open a new sketch File by clicking on New.

26
Step 6: Working on an existing project

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

27
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 COM2
are usually reserved for hardware serial ports).

28
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 boardand 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 thestatus bar.

29
A Verify

B Upload

C New

D Open

E Save

F Serial Motor

30
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 milliseconds
digitalWrite (ledPin, LOW); // Turn the led on
delay (1000); // Delay 1000 milliseconds
}

31
ARDUINO BOARDS

Arduino is a software as well as hardware platform that helps in making electronic projects. It is
an open source platform and has a variety of controllers and microprocessors. There are various types of
Arduino 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 we
want 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 UNO
board.

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 an
ICSP (In-Circuit Serial Programming) header. It is programmed based on IDE, which stands forIntegrated
Development Environment. It can run on both online and offline platforms.

32
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 by
connecting 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.

33
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.3
volt and 5 volt.
 GND (8) (Ground) − There are several GND pins on the Arduino, any of
which can be used to ground your circuit.
 Vin (9) − This pin also can be used to power the Arduino board from an
external 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 the
brain of your board. The main IC (integrated circuit) on the Arduino is slightly
different 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 the
IC..

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). They
appear 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

34
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

35
Ex No:15 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 the
bats 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.

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

OUTPUT:

37
Ex No:16 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

38
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:

39
Ex No:17 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.

40
REG

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 detected


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

OUTPUT:

41
Ex No:18 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 fixedfrequency
when you provide the required voltage to it.

42
PROGRAM:

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

void setup() {
// Initialize the buzzer pin as an OUTPUT
pinMode(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 duration


delay(500);
}

RESULT:

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

43
Ex No:19 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

44
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 your
computer)
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

45
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 module
delay(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.

46
Ex No:20 COMMUNICATE BETWEEN ARDUINO AND BLUETOOTH COMMUNICATION MODULE

Date

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 enter
the 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

47
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 */
}

48
void loop() {

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


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

OUTPUT:

RESULT:

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

49
Ex No:21 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 ages
to explore computing, and to learn how to program in languages like Scratch and Python. It’s capable of
doing 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:

50
COMPONENTS:

● System on a Chip (SoC):


○ This is the main component of the Raspberry Pi, integrating the CPU, GPU, RAM, and
other essential elements.
● Central Processing Unit (CPU):
○ The CPU is the primary processing unit responsible for executing instructions, running
programs, and handling computations.
● Graphics Processing Unit (GPU):
○ The GPU handles graphical computations and is responsible for rendering video and
images on the screen.
● RAM (Random Access Memory):
○ This is the memory that the Raspberry Pi uses to temporarily store data for quick access
by 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 Raspberry
Pi to connect to monitors, TVs, or displays.
● Audio Output Jack:
○ This allows the connection of speakers, headphones, or audio systems for sound output.

51
● MicroSD Card Slot:
○ The Raspberry Pi uses a microSD card as its primary storage, where the operating
system and user data are stored.
● Ethernet Port:
○ Some models include an Ethernet port for a wired network connection, enabling internet
access 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.
● Camera and Display Ports:
○ Some models feature ports for connecting the Raspberry Pi Camera Module and official
Display Module, enabling camera and display functionalities.
● Power Port:
○ The power port supplies the Raspberry Pi with the necessary electrical power, often
through 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 Pi Imager
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.

52
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 connected
micros 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.

53
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

STEP 10: The colored window of Raspberry Pi. You will see a colored window like shown here. This
indicates 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.

54
STEP 13: Reboot the Raspberry Pi. Upon the completion of the set up process, system will ask to
reboot 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, you
will be greeted with this desktop screen.

RESULT:

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

55
Ex No:22
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.

56
PROGRAM:

import RPi.GPIO as GPIO


import time
sensor=3
GPIO.setmode(GPIO.BOARD)
GPIO.setup(sensor,GPIO.PIN)
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.

57
COMMUNICATE ARDUINO AND RASPBERRY PI
Ex No:23

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

58
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 command
ls /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 sent
from Arduino to Raspberry Pi using serial communication.

59
Ex No:24
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_PASSWORD"
#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() {
Serial.begin(115200);
dht.begin();
60
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 seconds
retries--;
if (retries == 0) {
// basically die and wait for WDT to reset me
while (1);
}
}
Serial.println("MQTT Connected!");
}

61
REG

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

Create Account using sign Up

OUTPUTS:

62
RESULT:
The ESP 32 successfully interfaces Adafruit io with Wi-Fi as programed.

63
CONTENT BEYOND

THE SYLLABUS

64
EX.NO.1 ARITHMETIC OPERATION USING 8051

Aim:

To perform 8-bit arithmetic operations by using 8051 micro controller.

Apparatus Required:

1. Microcontroller 8051 kit

PROGRAM:

Addition:

CLR C
MOV B, # 00H
MOV A, #FFH
ADDC A, # FEH
JNC LOOP
INC B
LOOP: MOV DPTR, # 4500H
MOVX @ DPTR, A
INC DPTR
MOV A, B
MOVX @ DPTR, A
HERE: SJMP HERE

ADDERS OPCODE LABL MNEMONICS COMMENTS


E
4100 C3 CLR C
4101 75,F0,00 MOV B#00H
4104 74,FF MOV A #FFH
4106 34,FE ADDC A # FEH
4108 50,02 JNC LOOP
410A 05,F0 INC B
410C 90,45,00 LOOP MOVDPTR,# 4500H
410F F0 MOVX @ DPTR, A
4110 A3 INC DPTR
4111 E5,F0 MOV A, B
4113 F0 MOVX @ DPTR, A
4114 80,FE HERE SJMP HERE

65
Subtraction:

CLR C
MOV B# 00H
MOV A #FFH
SUBB A # FEH
JNC LOOP
INC B
LOOP: MOV DPTR # 4500H
MOVX @ DPTR, A
INC DPTR
MOV A, B
MOVX @ DPTR, A
HERE: SJMP HERE

Procedure: -

 Move the data to the accumulator


 Get another 8 bit data subtract it with the accumulator content.
 Store the result in particular location.

ADDERS OPCODE LABL MNEMONICS COMMENTS


E
4100 C3 CLR C
4101 75,F0,00 MOV B#00H
4104 74,FF MOV A #FFH
4106 94,FE SUBB A # FEH
4108 50,02 JNC LOOP
410A 05,F0 INC B
410C 90,45,00 LOOP MOVDPTR# 4500H
410F F0 MOVX @ DPTR, A
4110 A3 INC DPTR
4111 E5,F0 MOV A, B
4113 F0 MOVX @ DPTR, A
4114 80,FE HERE SJMP HERE

66
Multiplication

MOV A, # 03H
MOV B, # 02H
MUL AB
MOV DPTR, # 4500H
MOV X @ DPTR, A
INC DPTR
MOV A, B
MOV X @ DPTR, A
HERE: SJMP HERE

Procedure: -

 Move the data 03H to accumulator.


 Move the data 02H to register B.
 Perform multiplication for both the data’s.
 Store the result in location.

Address Op-Code Label Mnemonics Comments


4100 74, 03 MOV A, # 03H Move 03H to A.
4102 75, F0,02 MOV B, # 02H Move 02H to B
4105 A4 MUL AB Multiply A and B
4106 90, 45,00 MOV DPTR #4500 Data pointer is given to location 4500H
4109 F0 MOV X @ DPTR,A The content of A to 4500H
410A A3 INC DPTR Increment the data pointer
410B E5, F0 MOV A, B Move B to A
410D F0 MOV X @ DPTR,A Move A to DPTR
410E 80, FE HERE SJMP HERE Jump to 410E.

Division:

MOV A, # 65H
MOV B, # 08H
DIV AB
MOV DPTR, # 4500
MOV X @ DPTR, A
INC DPTR
MOV A, B
MOV X @ DPTR, A
HERE: SJMP HERE

67
Procedure: -
 Move data 65H immediate to register A.
 Move data 08 immediately to register B.
 Perform division to both operands A and B.
 Store the result.
 Then increment the address and then store remainder in increment address.

Address Op-Code Label Mnemonics Comments


4100 74, 65 MOV A, # 65H Move 65H to A.
4102 75, F0,08 MOV B, # 08H Move 08H to B
4105 84 DIV AB Divide A and B
4106 90, 45,00 MOV DPTR #4500 Data pointer is given to location 4500H
4109 F0 MOV X @ DPTR, The content of A to 4500H
410A A3 INC DPTR Increment the data pointer
410B E5, F0 MOV A, B Move B to A
410D F0 MOV X @ DPTR,A Move A to DPTR
410E 80, FE HERE SJMP HERE Jump to 410E.

S.NO Operation Address Input Output


4100 20H
1 Addition 4102 10H
4500 30H
4100 44H
2 Subtraction 4102 22H
4500 22H
4100 03H
3 Multiplication 4102 02H
4500 06H
4 4100 65H
Division 4102 08H
4500 0CH

68
S.NO Operation Address Input Output
4100
1 Addition 4102
4500
4100
2 Subtraction 4102
4500
4100
3 Multiplication 4102
4500
4 4100
Division 4102
4500

Result:

Thus arithmetic operations are performed using 8051 micro controller.

69
EX NO 2 LARGEST NUMBER IN ARRAY OF NUMBER

AIM
To find the largest number of the given number using 8051 micro controller assembly Language
program.

ALGORTHIM: -

• Set the data pointer.

• Outer the number of data

• Move the number of data first data to accumulator

• Compare and jump on not equal to loop1

• Move the first de greater number to YY (loop)

Increment the data pointer

Move the next data to accumulator

Compare the data with YY

• Repeat the step 5 to 8 until all digits are compared

Program: -

MOV DPTR # 4500H

MOV40H, #00 MOV R5, #0A

LOOP2 MOVX A, @DPTR


CJNE A, 40H LOOP1

LOOP3 INC DPTR


DJNZ R5, LOOP2
MOV A, 40H

70
MOVX @ DPTR, A

HLT: SJMP HLT

LOOP1 JC LOOP3

MOV40H, A
SJMP LOOP3

Procedure: -

 The micro controller is connected to the keyboard and power supply.


 The mnemonics are entered in the assembler mode into the kit.
 The program is then executed.
 The result is then viewed in the external data memory.

Largest of 'N' number:-

Address Op-Code Label Mnemonics Comments


4100 90,45,00 MOV DPTR #9500H Initialize data pointer
4103 75,40,00 MOV 40H, # 00 Store 00in44 address
4106 7D,0A MOV R5, #0A Initialize counter
4108 E0 LOOP2 MOV A, @ DPTR Move the first data to Acc.
4109 B5,40,08 CJNE A, 40H LP1 Move the first data Acc
410C A3 LOOP3 INC DPTR Increment data pointer
410D DD,F9 DJNZ R5, LOOP2
410F E5,40 MOV A, 40H Store the result
4111 F0 MOV X @ DPTR, A
4112 80,FE HLT SJMP HLT Terminate program
4114 40,F6 LOOP1 JC LOOP 3 Jump on carry to loop3
4116 F5,40 MOV 40H, A
4118 80,F2 SJMP LOOP3

71
RESULT:

INPUT OUTPUT

Address DATA Address DATA


4500 11
4501 22
4502 33
4503 44 450 A 99
4504 55
4505 66
4506 77
4507 88
4508 99
4509 00

Thus the largest of N number is found using the 8051 micro controller.

72
Ex.No: 3

ASCENDING ORDER USING 8086 KIT

Aim:
To sort the number in ascending and descending order by using 8086 Microprocessor kit.

Apparatus Required:

1. One 8086-microprocessor kit


2. PC with MASM & DATACOM software
3. RS 232 cable

Procedure:

 Connect the RS 232-cable b/w microprocessor kit & PC


 Enter the programs
 Copy the program code from the PC to microprocessor kit
 Compile the program
 Verify the result

Program for ascending order:

ASSUME CS: CODE, DS: DATA


DATA SEGMENT
LIST DB 53H, 25H, 19H, 22H
COUNT EQU 04
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV DX, COUNT – 1
LP0: MOV CX, DX
MOV SI, OFFSET LIST
LP1: MOV AL [SI]
CMP AL [SI+1]
JL PRI
XCHG [SI + 1], AL
XCHG [SI], AL
PRI: ADD SI 01
LOOP LP1
DEC DX
JNZ LP0
MOV AH, 4CH
INT 21H
CODE ENDS
END

Result:

The 8086 program to sort the numbers in ascending and descending order was written, entered, executed and
verifi
73
Ex.No 4 DESCENDING ORDER USING 8086 KIT

Aim:
To sort the number in ascending and descending order by using 8086 Microprocessor kit.

Apparatus Required:

4. One 8086-microprocessor kit


5. PC with MASM & DATACOM software
6. RS 232 cable

Procedure:

 Connect the RS 232-cable b/w microprocessor kit & PC


 Enter the programs
 Copy the program code from the PC to microprocessor kit
 Compile the program
 Verify the result

Program for descending order:

ASSUME CS: CODE, DS: DATA


DATA SEGMENT
LIST DB 13H, 55H, 98H, 42H
COUNT EQU 04
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV DX, COUNT – 1
LP0: MOV CX, DX
MOV SI, OFFSET LIST
LP1: MOV AL [SI]
CMP AL [SI+1]
JG PRI
XCHG [SI + 1], AL
XCHG [SI], AL
PRI: ADD SI 01
LOOP LP1
DEC DX
JNZ LP0
MOV AH, 4CH
INT 21H
CODE ENDS
END

Result:

The 8086 program to sort the numbers in descending order was written, entered, executed and verified.

74
Ex.No: 5 ONE’S &TWO’S COMPLEMENT:-USING 8051

Aim:

To perform One’s &Two’s Complement:-


operations by using 8051 micro controller.

Apparatus Required:

1. Microcontroller 8051 kit

One’s &Two’s Complement:-


Program:
MOV A, #DATA
CPL, A
MOV DPTR, #4200
MOVX @DPTR, A
INC A
INC DPTR
MOVX @DPTR, A
HERE: SJMP HERE

ADDERSS OPCODE LABLE MNEMONICS COMMENTS

4100 74,CC MOV A, #DATA


4102 F4 CPL, A
4103 90,42,00 MOV DPTR, #4200

4106 F0 MOVX @DPTR, A


4107 04 INC A
4108 A3 INC DPTR
4109 F0 MOVX @DPTR, A
410A 80,FE HERE SJMP HERE

Sample data: DATA = CC


Result: - [4200] = 33 – one’s complement
[4201] = 34 – Two’s complement

Result:

Thus One’s &Two’s Complement operations are performed using 8051 micro controller.

75
VIVA VOCE QUESTIONS

76
8051

1. What is the basic difference between a microcontroller and a microprocessor?


A microprocessor consists of only a processor, whereas a microcontroller
consists of several components such as a processor, memory, serial bus interface, and
so on.

2. What distinguishes assembly-level programming from programming in C for


microcontrollers?
One can discuss the benefits and drawbacks of each option as well as how an
assembly line of codes can also be called in a microcontroller C program to answer this
question. The only advantage of assembly language is smaller, faster code, but memory
is now inexpensive; a microcontroller with 16 KB of program memory costs little more
than one with 8 KB; and C compilers have improved in their ability to produce smaller
code, albeit free ones aren't as good.

3. What are registers in Microcontroller?

Register provides a fast way to collect and store data using microcontrollers
and processors. If we want to manipulate data with a controller or processor by
performing tasks like addition, subtraction, and so on, we cannot do that directly in the
memory, in order to perform these tasks we need registers to process and store the data.
Microcontrollers contain several types of registers that can be classified according to
their content or instructions that operate on them.

The 8051 microcontroller contains mainly two types of registers:

 General purpose registers (Byte addressable registers)


 Special function registers (Bit addressable registers)

4. How are timers and counters different in a microcontroller?


The timer is used to measure internal clock cycles, whereas the counter
counts external events.

5. Have you studied buses? What types?

There are three types of buses. Address bus: This is used to carry the Address
to the memory to fetch either Instruction or Data. Data bus : This is used to carry the
Data from the memory. Control bus : This is used to carry the Control signals like
RD/WR, Select etc

77
6. What is an Opcode?
The part of the instruction that specifies the operation to be performed is
called the Operation code or Op code.

7. What is an Operand?
The data on which the operation is to be performed is called as an Operand.

8. Explain the difference between a JMP and CALL instruction?


A JMP instruction permantely changes the program counter. A CALL
instruction leaves information on the stack so that the original program execution
sequence can be resumed.

9. What is meant by Interrupt?


Interrupt is an external signal that causes a microcontroller to jump to a specific
subroutine.

10. What is Assembler?


The assembler translates the assembly language program text which is given as
input to the assembler to their binary equivalents known as object code. The time
required to translate the assembly code to object code is called access time. The
assembler checks for syntax errors & displays them before giving the object code.

11. What is assembly language?

The language in which the mnemonics (short -hand form of instructions) are
used to write a program is called assembly language. The manufacturers of
microprocessor give the mnemonics.

12. What are machine language and assembly language programs?


The software developed using 1's and 0's are called machine language,
programs. The software developed using mnemonics are called assembly language
programs.

13. What is the drawback in machine language and assembly language, programs?
The machine language and assembly language programs are machine dependent.
The programs developed using these languages for a particular machine cannot be
directly run on another machine .

Basic Embedded C

78
1. What is Embedded C? How does it differ from standard C?

Embedded C is a set of language extensions to the standard C programming language,


specifically designed for programming embedded systems. It includes additional features, such as
support for hardware-specific functionalities and optimizations, that are not available in standard C.
The main differences between Embedded C and standard C are:

o Embedded C targets microcontrollers and embedded systems, while standard C is


for general-purpose programming.
o Embedded C has additional support for handling hardware-specific tasks, such as
direct memory access, interrupts, and registers.
o In Embedded C, memory and resource management are more critical than in
standard C, as embedded systems typically have limited resources.

2. Explain the role of the volatile keyword in Embedded C.

The volatile keyword in Embedded C is used to inform the compiler that a variable may
be changed unexpectedly by external factors, such as hardware events or interrupts. This
prevents the compiler from optimizing the code in a way that might assume the variable
remains constant, ensuring that the variable is always read from memory instead of being
cached in a register. This is particularly important in embedded systems where memory-
mapped registers and hardware peripherals are often accessed through pointers or global
variables.

3. How do you declare an array in Embedded C?

In Embedded C, an array can be declared using the following syntax:

datatype array_name[array_size];

For example, to declare an integer array of size 10:

int my_array[10];

4. Explain the use of static and extern keywords in Embedded C.

The static and extern keywords are used to control the visibility and storage duration of
variables and functions in Embedded C.

5. What is Void Pointer in Embedded C and why is it used?

Void pointers are those pointers that point to a variable of any type. It is a generic pointer as
it is not dependent on any of the inbuilt or user-defined data types while referencing. During

79
dereferencing of the pointer, we require the correct data type to which the data needs to be
dereferenced.

IOT, Arduino and Raspberry Pi, Zigbee, Bluetooth, GSM


1. What is an Arduino microcontroller?
An Arduino microcontroller is a small, programmable device that can be used to control
electronic devices. It is based on a simple hardware platform that is easy to learn and use, and it
comes with a software development environment (IDE) that makes it easy to write code for the
device.

2. Can you explain the difference between Arduino and Raspberry Pi, and when you would prefer one
over the other in a project?

Arduino is a microcontroller-based platform, while Raspberry Pi is a single-board computer. Arduino


excels in real-time tasks and simple input/output operations, whereas Raspberry Pi provides more processing
power and runs an operating system. Choose Arduino for projects requiring sensor interfacing, motor control,
or low-power consumption.

For Raspberry Pi when needing complex software, internet connectivity, or multimedia capabilities.

3. What is the Internet Of Things (IoT)?


Internet of Things (IoT) is a network of physical objects or people called “things” that are embedded with
software, electronics, network, and sensors that allow these objects to collect and exchange data. The goal of
IoT is to extend to internet connectivity from standard devices like computer, mobile, tablet to relatively dumb
devices like a toaster.

4. Explain Raspberry Pi?


Raspberry Pi is a computer which is capable of doing all the operations like a conventional computer. It has
other features such as onboard WiFi, GPIO pins, and Bluetooth in order to communicate with external things.

5. What are the fundamental components of IoT?


The four fundamental components of an IoT system are:
Sensors/Devices: Sensors or devices are a key component that helps you to collect live data from the
surrounding environment. All this data may have various levels of complexities. It could be a simple
temperature monitoring sensor, or it may be in the form of the video feed.
Connectivity: All the collected data is sent to a cloud infrastructure. The sensors should be connected to the
cloud using various mediums of communications. These communication mediums include mobile or satellite
networks, Bluetooth, WI-FI, WAN, etc.
Data Processing: Once that data is collected, and it gets to the cloud, the software product performs processing
on the gathered data. This process can be just checking the temperature, reading on devices like AC or heaters.
However, it can sometimes also be very complex, like identifying objects, using computer vision on video.
User Interface: The information needs to be available to the end-user in some way, which can be achieved by
80
triggering alarms on their phones or sending them notification through email or text message. The user
sometimes might need an interface which actively checks their IoT system.

6. What are the popular software IDEs are using in IoT?


Each prototype system family has its production IDE, such as the Arduino IDE, Keil IDE, GCC
compilers, and so on
7. What are the popular hardware prototypes are using in IOT?
More hardware prototype modules, such as Arduino, Raspberry Pi, and ARM Cortex Family, are being used
in IOT implementation.

8. What are the Key Differences Between ZigBee and Other Wireless Protocols like Wi-Fi and Bluetooth?
Primary Use Cases:

 ZigBee: Low-power, low-data-rate applications like home automation and sensor networks.
 Wi-Fi: High-speed internet access and data transfer.
 Bluetooth: Short-range communication between devices like smartphones and headphones.

Power Consumption:

 ZigBee: Very low, suitable for long-lasting battery-operated devices.


 Wi-Fi: Higher, suitable for devices with constant power sources.
 Bluetooth: Moderate, with BLE designed for low-power applications.

Data Transfer Rates:

 ZigBee: Low, around 250 kbps.


 Wi-Fi: High, from 54 Mbps to several Gbps.
 Bluetooth: Moderate, up to 2 Mbps with Bluetooth 5.0.

Network Topology:

 ZigBee: Mesh networking for enhanced range and reliability.


 Wi-Fi: Star topology with a central access point.
 Bluetooth: Star topology for classic Bluetooth, mesh for Bluetooth Mesh networking.

9. What is Bluetooth?
Bluetooth is a wireless technology standard used for exchanging data over short distances from fixed

and mobile devices, creating personal area networks with high levels of security.

10. How does Bluetooth work?


Bluetooth works by using short-range radio waves to connect devices to each other. It operates in the

81
2.4 GHz frequency band and can connect up to eight devices simultaneously.

11. Can Bluetooth interfere with Wi-Fi?


Yes, Bluetooth and Wi-Fi both operate in the 2.4 GHz frequency band, so they can potentially
interfere with each other. However, modern devices have techniques to minimize this interference.

12. Can Bluetooth connect to Wi-Fi?


Bluetooth and Wi-Fi are separate technologies and don’t connect directly to each other.
However, some devices have both Bluetooth and Wi-Fi capabilities, and a device with an internet
connection can share it with a connected Bluetooth device.

13. What is GSM?


 Short form of Global System for Mobile Communications, is a wireless network system
 A standard for digital cellular mobile communications
 International roaming arrangements are enabled among mobile network operators, by
providing the subscribers to use their personal mobile phones anywhere in the world.

14. What is the maximum data rate supported by a GSM system?


 However, there are extensions to GSM standard to improve throughput.
 GPRS is one of the extended GSM service.
 The extended standards of GSM allow theoretical data rates on the order of 114 Kbit/s, but with
throughput closer to 40Kbit/s in practice
 The maximum data rate supported by a GSM system is 9.6 kbps.

82

You might also like