Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
10 views101 pages

Microcontroller

8051 Microcontroller

Uploaded by

ibm.da2024
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)
10 views101 pages

Microcontroller

8051 Microcontroller

Uploaded by

ibm.da2024
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/ 101

Ex No: 1a

STUDY OF 8051 MICROCONTROLLER


Date:

Aim:

To study the 8051 microcontroller, its architecture, instruction set, and addressing
modes.

8051 Microcontroller:

The Intel 8051 is an 8-bit microcontroller that became the foundation for many
embedded systems due to its simplicity and versatility. Various manufacturers, including
Atmel, NXP, and Microchip, have developed their own versions of the 8051.

Key Features:
 CPU: 8-bit processor

 Clock Speed: Typically runs at 12MHz but varies by implementation.

 Memory:

o 4KB ROM (Internal program memory)

o 128 bytes RAM (Internal data memory)

 I/O Ports: 4 general-purpose 8-bit I/O ports

 Serial Communication: Built-in UART for serial data communication

 Interrupts: 5 interrupt sources (2 external, 3 internal)


8051 MicroController :
Pin Number Description

Pin 1 (P1.0) Port 1, Pin 0. General-purpose input/output pin.

Pin 2 (P1.1) Port 1, Pin 1. General-purpose input/output pin.

Pin 3 (P1.2) Port 1, Pin 2. General-purpose input/output pin.

Pin 4 (P1.3) Port 1, Pin 3. General-purpose input/output pin.

Pin 5 (P1.4) Port 1, Pin 4. General-purpose input/output pin.

Pin 6 (P1.5) Port 1, Pin 5. General-purpose input/output pin.

Pin 7 (P1.6) Port 1, Pin 6. General-purpose input/output pin.

Pin 8 (P1.7) Port 1, Pin 7. General-purpose input/output pin.

Reset pin. A high pulse on this pin resets the


Pin 9 (RST)
microcontroller.

Port 3, Pin 0. Serial data receive input or general-


Pin 10 (P3.0 / RXD)
purpose I/O.
Port 3, Pin 1. Serial data transmit output or general-
Pin 11 (P3.1 / TXD)
purpose I/O.

Port 3, Pin 2. External interrupt 0 input or general-


Pin 12 (P3.2 / INT0)
purpose I/O.

Port 3, Pin 3. External interrupt 1 input or general-


Pin 13 (P3.3 / INT1)
purpose I/O.

Port 3, Pin 4. Timer 0 external input or general-


Pin 14 (P3.4 / T0)
purpose I/O.

Port 3, Pin 5. Timer 1 external input or general-


Pin 15 (P3.5 / T1)
purpose I/O.

Port 3, Pin 6. External memory write signal or general-


Pin 16 (P3.6 / WR)
purpose I/O.

Port 3, Pin 7. External memory read signal or general-


Pin 17 (P3.7 / RD)
purpose I/O.

Pin 18 (XTAL2) Crystal oscillator output. Connects to external crystal.

Pin 19 (XTAL1) Crystal oscillator input. Connects to external crystal.

Pin 20 (GND) Ground reference pin. Connect to 0V.

Pin 21 (P2.0 / A8) Port 2, Pin 0. General-purpose I/O or address bit A8.

Pin 22 (P2.1 / A9) Port 2, Pin 1. General-purpose I/O or address bit A9.
Pin 23 (P2.2 / A10) Port 2, Pin 2. General-purpose I/O or address bit A10.

Pin 24 (P2.3 / A11) Port 2, Pin 3. General-purpose I/O or address bit A11.

Pin 25 (P2.4 / A12) Port 2, Pin 4. General-purpose I/O or address bit A12.

Pin 26 (P2.5 / A13) Port 2, Pin 5. General-purpose I/O or address bit A13.

Pin 27 (P2.6 / A14) Port 2, Pin 6. General-purpose I/O or address bit A14.

Pin 28 (P2.7 / A15) Port 2, Pin 7. General-purpose I/O or address bit A15.

Program Store Enable. Used to read external program


Pin 29 (PSEN)
memory.

Address Latch Enable for demultiplexing address/data


Pin 30 (ALE/PROG)
signals. Used in programming mode too.

External Access Enable. Connect to GND for external


Pin 31 (EA/VPP)
memory, high for internal memory.

Port 0, Pin 7. General-purpose I/O or multiplexed


Pin 32 (P0.7 / AD7)
address/data line AD7.

Port 0, Pin 6. General-purpose I/O or multiplexed


Pin 33 (P0.6 / AD6)
address/data line AD6.
Port 0, Pin 5. General-purpose I/O or multiplexed
Pin 34 (P0.5 / AD5)
address/data line AD5.

Port 0, Pin 4. General-purpose I/O or multiplexed


Pin 35 (P0.4 / AD4)
address/data line AD4.

Port 0, Pin 3. General-purpose I/O or multiplexed


Pin 36 (P0.3 / AD3)
address/data line AD3.

Port 0, Pin 2. General-purpose I/O or multiplexed


Pin 37 (P0.2 / AD2)
address/data line AD2.

Port 0, Pin 1. General-purpose I/O or multiplexed


Pin 38 (P0.1 / AD1)
address/data line AD1.

Port 0, Pin 0. General-purpose I/O or multiplexed


Pin 39 (P0.0 / AD0)
address/data line AD0.

Pin 40 (Vcc) Power supply pin. Connect to +5V DC.


Instruction Set:
The 8051 instruction set consists of 2 instructions categorized into
different types based on their functionality. These instructions operate on 8-bit
registers and memory.
Arithmetic Instructions
Mnemonic Explanation
ADD A, Rn Add register to Accumulator
ADD A, direct Add direct byte to Accumulator
ADD A, @Ri Add indirect RAM to Accumulator
ADD A, #data Add immediate data to Accumulator
ADDC A, direct Add direct byte with carry
SUBB A, Rn Subtract register with borrow
MUL A, B Multiply A and B
DIV A, B Divide A by B
INC A Increment Accumulator
DEC A Decrement Accumulator

Logic Operations
Mnemonic Explanation
ANL A, Rn AND register with Accumulator
ORL A, Rn OR register with Accumulator
XRL A, Rn XOR register with Accumulator
CLR A Clear Accumulator
CPL A Complement Accumulator
RL A Rotate left
RLC A Rotate left through carry
RR A Rotate right
RRC A Rotate right through carry
SWAP A Swap nibbles in Accumulator

Data Transfer Instructions


Mnemonic Explanation
MOV A, Rn Move register to Accumulator
MOV A, direct Move direct byte to Accumulator
MOV Rn, A Move Accumulator to register
MOV direct, A Move Accumulator to direct byte
PUSH direct Push direct byte to stack
POP direct Pop direct byte from stack
XCH A, Rn Exchange register with Accumulator
Boolean Variable Manipulation
Mnemonic Explanation
CLR C Clear Carry
SETB C Set Carry
CPL C Complement Carry
ANL C, bit AND bit with Carry
ORL C, bit OR bit with Carry
MOV C, bit Move bit to Carry
MOV bit, C Move Carry to bit

Program Branching Instructions


Mnemonic Explanation
ACALL addr11 Absolute subroutine call
LCALL addr16 Long subroutine call
RET Return from subroutine
RETI Return from interrupt
AJMP addr11 Absolute jump
LJMP addr16 Long jump
SJMP rel Short jump
JZ rel Jump if zero
JNZ rel Jump if not zero

Addressing Modes in 8051:


The 8051 microcontroller supports multiple addressing mode.

 Immediate Addressing
Operand is a constant value. Example: MOV A, #25H (Move 25H to A)
 Register Addressing
Operand is a Register. Example: MOV A, R2 (Move content of R2 to A)
 Direct Addressing
Operand is a direct memory address.Example: MOV A, 30H (Move content of
address 30H to A)
 Register Indirect Addressing
Address of the operand is given in a Register. Example: MOV A, @R0
 Indexed Based Addressing
Used for accessing lookup tables in ROM. Example: MOVC A, @A+DPTR
(Move data from ROM using A + DPTR as address).

Result:
Thus the 8051 microcontroller, its architecture, instruction set and addressing modes
were studied.
Ex No: 1b 8 BIT ADDITION USING 8051
Date:
MICROCONTROLLER

Aim:
To perform 8-bit Addition using the 8051 Microcontroller.

Algorithm:
1. Initialize the microcontroller and set up registers.
2. Load the first 8-bit number into the accumulator.
3. Load the second 8-bit number into a general-purpose register.
4. Perform the addition using the `ADD` instruction.
5. Store the sum result in a memory location.
6. End the program or repeat the process for a new set of numbers.

Flowchart:
Program:
ORG 0000H

MOV A, #25H

MOV R0, #34H

ADD A, R0

MOV 30H, A

JMP $

END

Output:

Result:

Thus the 8-bit Addition using 8051 Microcontroller was written, executed, and the output was

verified successfully
Ex No:1c 16-BIT ADDITION USING
Date: 8051 MICROCONTROLLER

Aim:
To perform 16-bit addition using the 8051 microcontroller.

Algorithm:

1. Initialize the microcontroller and registers.

2. Load two 16-bit numbers into registers (R0-R1 and R2-R3).

3. Add the lower bytes

3.1 : Store the sum in memory (30H)

3.2 : If carry occurs, increment the higher byte (MSB)

4. Add the higher bytes with carry

4.1 : Store the sum in memory

5. Store the final 16-bit result in memory.

6. End the program or repeat for new numbers.

Flowchart:
Program:

ORG 0000H

MOV R0, #34H

MOV R1, #12H

MOV R2, #78H

MOV R3, #56H

MOV A, R0 ADD

A, R2 MOV 30H,

A JNC

NO_CARRY INC

R1

NO_CARRY:

MOV A, R1 ADD

A, R3

MO V 31H, A

JMP $

END
Output:

Result:

Thus the 16-bit addition using 8051 microcontroller was written, executed and output
was verified successfully.
Ex No: 1d 16 BIT SUBTRACTION USING 8051
Date: MICROCONTROLLER

Aim:
To perform 16-bit subtraction of two numbers using 8051 microcontroller.

Algorithm:

1. Clear accumulator and carry

2. Load the lower byte of the first number into A

3. Subtract the lower byte of the second number with SUBB

4. Store the result in a register

5. Load the higher byte of the first number into A

6. Subtract the higher byte of the second number with SUBB

7. Store the result in another register

Flowchart:

START

LOAD A WITH LSB1

SUBB A, LSB2

STORE RESULT IN R7

LOAD A WITH MSB1

SUBB A, MSB2

STORE RESULT IN R1

STOP
Program:

ORG 00H
CLR A
CLR C
MOV A, #62H
SUBB A, #96H
MOV R7, A
MOV A, #27H
SUBB A, #12H
MOV R1, A
END

Output:

Result:

Thus the 16 bit Subtraction using 8051 microcontroller was written, executed and the output was
verified successfully.
Ex No:1e 16 BIT MULTIPLICATION USING 8051
Date: MICROCONTROLLER

Aim:
To perform multiplication of two 16-bit numbers and store the 32-bit result in memory.

Algorithm:

1. Load the 1st 16-bit number from memory

2. Load the 2nd 16-bit number from memory

3. Multiply Low1 × Low2 → Result1

4. Multiply High1 × Low2 and Low1 × High2 → Result2, Result3

5. Add Result2 and Result3, add to Result1 upper byte

6. Multiply High1 × High2 → Result4

7. Add Result4 to the previous result to form final 32-bit result

8. Store result in memory


Flowchart:

Start

Load 16 bit Num1 (Low & High)

Load 16 bit Num2 (Low & High)

Multiply Low1 x Low2 → Store LSB (Result1)

Multiply High1 x Low2 → Result2

Multiply Low1 x High2 → Result3

Add Result2 + Result3 → Add to Result1 High Byte

Multiply High1 x High2 → Result4

Add Result4 to previous Result → 32 bit final result

Store 32 bit result in memory

Stop

Program:

ORG 00H

; Load first 16-bit number from memory [30H, 31H]

MOV R0, #30H

MOV A, @R0 ; Load Low byte of 1st number

MOV R2, A
INC R0

MOV A, @R0 ; Load High byte of 1st number

MOV R3, A

; Load second 16-bit number from memory [32H, 33H]

INC R0

MOV A, @R0 ; Load Low byte of 2nd number

MOV R4, A

INC R0

MOV A, @R0 ; Load High byte of 2nd number

MOV R5, A

; Step 1: Multiply Low1 (R2) × Low2 (R4) → Result1 (A=LSB, B=MSB)

MOV A, R2

MOV B, R4

MUL AB

MOV 40H, A ; Store LSB of result

MOV 41H, B ; Store MSB of result

; Step 2: Multiply High1 (R3) × Low2 (R4) → Result2

MOV A, R3

MOV B, R4

MUL AB

MOV R6, A

MOV R7, B

; Step 3: Multiply Low1 (R2) × High2 (R5) → Result3

MOV A, R2
MOV B, R5

MUL AB

ADD A, R6

MOV R6, A

ADDC B, R7

MOV R7, B

; Add Result2 + Result3 to the previous result's MSB (41H)

MOV A, 41H

ADD A, R6

MOV 42H, A

MOV A, R7

ADDC A, #00H

MOV 43H, A

; Step 4: Multiply High1 (R3) × High2 (R5) → Result4

MOV A, R3

MOV B, R5

MUL AB

MOV 44H, A

MOV 45H, B
Output:

Result:
Then the 16-bit multiplication was executed successfully.
Ex No:1f 16 BIT DIVISION USING 8051
Date: MICROCONTROLLER

Aim:

To divide a 16-bit number by an 8-bit number and store the 16-bit quotient and 8-bit
remainder.

Algorithm:

1. Load 16-bit dividend

2. Load 8-bit divisor

3. Divide high byte by divisor → partial quotient, remainder

4. Combine remainder with low byte → new 16-bit number

5. Divide new number by divisor → final quotient and remainder

6. Store 16-bit quotient and remainder in memory

Flowchart:

Start

Load 16 bit Dividend

Load 8 bit Divisor

Divide High Byte of Dividend by Divisor → Partial Quotient & Remainder

Combine Remainder with Low Byte → New 16 bit Number

Divide New 16 bit Number by Divisor → Final Quotient Low & Remainder

Store 16 bit Quotient and 8 bit Remainder

Stop
Program:

ORG 00H

MOV R0, #30H

MOV A, @R0

MOV R2, A

INC R0

MOV A, @R0

MOV R3, A

INC R0

MOV A, @R0

MOV R4, A

; Step 1: Divide high byte of Dividend by Divisor

MOV A, R3

MOV B, R4

DIV AB

MOV R5, A

MOV R6, B

; Combine R6 (remainder) and R2 (low byte) to form new dividend

MOV A, R6

MOV B, #0FFH

MUL AB

MOV R7, A

MOV A, R2

MOV B, R4
DIV AB

MOV 41H, R5 ; High byte of quotient

MOV 40H, A ; Low byte of quotient

MOV 42H, B ; Final remainder

SJMP $

Output :

Result:

Thus, the 16-bit division was written, executed, and output was verified successfully.
Ex No: 1g LOGICAL OPERATIONS USING 8051
Date: MICROCONTROLLER

Aim:

To perform logical operations using 8051 microcontroller.

AND Operation

Algorithm:

1. Load first number into accumulator

2. Perform AND operation with second number using ANL instruction

3. Store the result in a register

Flowchart:
start

Load A

AND A with 0F0H

Result in A

stop

Program:

ORG 00H

MOV A, #55H

ANL A, #0F0H

MOV R0, A

HLT
Output :

OR Operation

Algorithm:

1. Load first number into accumulator

2. Perform OR operation with second number using ORL instruction

3. Store the result

Flowchart:

start

Load A

OR A with 0F0H

Result in A

stop
Program:

ORG 00H

MOV A, #55H

ORL A,

#0F0H MOV

R1, A HLT

Output:

XOR Operation

Algorithm:

1. Load first number into accumulator

2. Perform XOR operation with second number using XRL instruction

3. Store the result


Flowchart:
start

Load A,B

xOR A,B

Result in A

stop

Program:

ORG 00H

MOV A, #55H

XRL A,

#0F0H MOV

R3, A HLT

Output:
NOT Operation

Algorithm:

1. Load number into accumulator

2. Perform NOT operation using CPL A

3. Store the result

Flowchart:

start

Load A

CPL A

Result in A

stop

Program:

ORG 00H

MOV A,

#55H CPL A

MOV R3, A

HLT
Output:

XNOR Operation

Algorithm:

1. Load first number into accumulator

2. Perform XOR with second number

3. Complement the result to get XNOR

4. Store the result

Flowchart:
start

Load A,B

XOR A,B

CPL A

Result in A

stop
Program:

ORG 00H

MOV A, #55H

XRL A,

#0F0H CPL A

MOV R4, A

HLT

Output:

Result:

Thus, the logical operations using 8051 microcontroller were written, executed, and
output was verified successfully.
Ex No: 2 DATA TRANSFER BETWEEN REGISTERS AND
Date: MEMORY

Aim:

To perform data transfer between registers and memory using 8051 micro controller.

Algorithm:

1. Load counter with number of bytes to transfer.

2. Load source start address into R1.

3. Load destination start address into R1.

4. Repeat the following until counter becomes zero.

4.1 : Move data from source to A.

4.2 : Move data from A to destination.

4.3 : Increment both R0 and R1.

4.4 : Decrement counter.

Flowchart:
Program:

ORG 000H

MOV R2,#05H

MOV R0,#40H

MOV R1,#50H

LOOP:

MOV A,@R0

MOV @R1,A

INC R0

INC R1

DJNZ

R2,LOOP END

Output:

Result:

Thus, the data transfer between registers and memory using 8051 microcontroller was
written, executed and the output was verified successfully.
ALU OPERATIONS
Ex No:3a GREATEST NUMBER USING COMPARISON
Date: OPERATION

Aim:
To find the greatest of two numbers using comparison operator in 8051 micro-controller

Algorithm:

1: load the first number to the BX


2: load the second number into BX
3: compare the AX with BX using the CMP instruction

4: If AX is greater than or equal to the BX, store AX in memory


5: else, store BX in memory

Program:

ADDRESS OPCODE LABEL MNEMONIC COMMENTS

1000 BB0500 MOV AX,0005H Load first number into AX

1003 BB0300 MOV BX,0003H Load second number into BX

1006 3BC3 CMP AX, BX Compare AX with BX

1008 7D02 JGE GREATER Jump if AX is greater than or equal to BX

100A 89D8 MOV AX, BX Move BX to AX if BX is greater

100C GREATER Label for greater number

100C A31000 MOV [0010H], AX Store greater number in memory

100F F4 HLT Halt the program


Output:

INPUT OUTPUT

Address Data Address Data

1100 05 (AX = 0005H) 0010 05 (greater)

1101 03 (BX = 0003H)

Result:

Thus the program for greater number using 8051 microcontroller was written , executed
and the output was verified successfully
Ex No :3b SMALLEST NUMBER USING COMPARISON
Date: OPERATION

Aim:
To find the smallest of two numbers using comparison operation in 8051 micro-controller.

Algorithm:

1: Load the first number into AX


2: Load the second number into BX
3: Compare AX with Bx using the CMP instruction.
4: If AX is smaller than or equal to BX, store AX in memory.
5: Else store BX in memory.
6: Halt the program

Program:

ADDRESS OPCODE LABEL MNEMONIC COMMENTS


1000 BB0500 MOV AX, 0005H Load first
number into
AX
1003 BB0300 MOV BX, 0003H Load second
number into
BX
1006 3BC3 CMP AX,BX Compare AX
with BX
1008 7E02 JLE SMALLER Jump if
AX<=BX
100A 89DB MOV AX,BX Move BX to
AX
If BX is
smaller
100C SMALLER Label for
smaller
Number
100C A31000 MOV[0010H],AX Store the
smaller
number at
memory
100F FA HLT Halt the prog-
ram

Output:

INPUT OUTPUT

Address Data Address Data

1100 05 (AX = 0005H) 0010 03 (smaller)

1101 03 (BX = 0003H)

Result:
Thus the program for smallest number using 8051 microcontroller was written,executed and output
was verified successfully
Ex No: 3c
RIGHT SHIFT USING SHIFT OPERATION
Date:

Aim:
To perform right shift operation on a number using 8051 micro-controller.

Algorithm:
1. Load the number into AX.
2. Perform right shift operation using SHR.
3. Store the result in memory.
4. Halt the program.

Program:

ADDRESS OPCODE LABEL MNEMONIC COMMENTS

1000 BB1000 Load number


MOV AX, 0010H
into AX

1003 D1E8 SHR AX, 1 Shift AX right


by 1

MOV Store result at


1005 A31000
[0010H], AX memory location

1008 FA HLT Halt the program


Output:

INPUT OUTPUT

Address Data Address Data

1100 10 (AX = 0010H) 0010 08

Result:
Thus the program for right shift operation using 8051 microcontroller was written, executed
successfully.
Ex No:3d
LEFT SHIFT USING SHIFT OPERATION
Date:

Aim:

To perform left shift operation on a number using 8051 micro-controller

Algorithm:

1: Load the number into AX


2: Perform left shift operation using SHL
3: Store the result in memory
4: Halt the program

Program:

ADDRESS OPCODE LABEL MNEMONIC COMMENTS

1000 BB1000 MOV AX, Load number

0004H into AX

1003 D1E0 SHL AX, 1 Shift AX left


by 1 bit

1005 A3 1000 MOV [0010H], Store result at


AX memory
location

1008 FA HLT Halt the

Program
Output:

INPUT OUTPUT

ADDRESS DATA ADDRESS DATA

1100 04 (AX = 0004H) 0010 08

Result:
Thus the program for left shift using 8051 microcontroller was executed
successfully.
Ex No : 4
ARITHMETIC PROGRAMS USING EMBEDDED C
Date:

Aim:

To write and perform arithmetic operations Using Embedded C.

Algorithm:

1. Start the program.


2. Initialize variables:
a. Set x = 0x12 (18 in decimal).
b. Set y = 0x34 (52 in decimal).
3. Clear output ports:
a. Set ports P0, P1, P2, and P3 to 0x00 to remove any previous data.
4. Addition:
a. Calculate z = x + y.
b. Send result z to Port P0.
5. Subtraction:
a. Calculate a = y - x.
b. Send result a to Port P1.
6. Multiplication:
a. Calculate b = x * y.
b. Send result b to Port P2.
7. Division:
a. Calculate c = y / x.
b. Send result c to Port P3.
8. Infinite loop:
a. Keep the program running using while(1) to retain the outputs on ports.
9. End the algorithm.
Program:

#include<reg51.h>

Void main (void)

Unsigned char x,y,z,a,b,c;

X=0x12;

Y=0x34;

P0=0x00;

P1=0x00;

P2=0x00;

P3=0x00;

Z=x+y;

P0=z;

A=y-x;

P1=a;

B=x*y;

P2=b;

C=y/x;

P3=c;

While(1);

}
Output:

Result:

Thus the arithmetic programs using Embedded C was written, executed and output was
verified successfully.
Ex No: 5
INTRODUCTION TO ARDUINO PLATFORM
Date:

Aim:

To study the basics of the Arduino platform including its hardware, software, working,
applications, and types.

Introduction:
Arduino is an open-source electronics platform based on easy-to-use hardware and software.
It was initially developed at the Interaction Design Institute Ivrea (IDII) in Ivrea, Italy, with the
goal of providing affordable tools for non-engineers to create interactive digital projects. Over
time, Arduino has grown into a global community of hobbyists, students, and professionals
working on innovative projects in embedded systems and IoT.

Key Components Of Arduino:


1. Arduino Board (Hardware)
Arduino boards are open-source and consist of a microcontroller and essential circuits needed
to run and program the controller. The design is accessible to all, encouraging replication and
customization for varied applications. Boards like the Arduino Uno, Nano, Mega, and Due serve
different needs, from simple to complex embedded systems tasks.

Features of Arduino Boards:


 Open-source hardware
 Variety of models suited for different applications
 Wide community support
 Affordable and accessible worldwide

2. Arduino IDE (Software)


The Arduino IDE (Integrated Development Environment) is the primary platform used for
writing, compiling, and uploading programs (called sketches) to the Arduino boards. It provides a
simple user interface with features such as code verification, debugging, uploading, and example
libraries for beginners.
Main Functions of Arduino IDE:
 Writing and editing programs (Sketches)
 Compiling code and debugging
 Uploading code to Arduino boards
 Access to inbuilt libraries and examples

Working Of Arduino:
Arduino boards are programmed using the Arduino IDE. Once a program (sketch) is
uploaded, the microcontroller on the Arduino board executes the instructions continuously. It
interacts with sensors, actuators, and other electronic components through its input and output
pins. The Arduino platform allows real-world signals to be read (analog/digital) and responses to
be generated accordingly, making it highly suitable for embedded systems and IoT applications.

Application Of Arduino:
Arduino boards have become a key tool in modern electronics due to their versatility and
ease of use. They are widely applied across various fields, enabling automation, control, and smart
system development.

Arduino boards are widely used in various fields such as:


 Home automation systems
 Robotics
 Internet of Things (IoT) applications
 Sensor data collection and monitoring
 Educational projects
 Industrial control systems
 Healthcare devices
 Wearable technology
Types Of Arduino Boards:

1. Arduino Mega 256

The Arduino Mega 2560 is designed for advanced and complex projects that require a large
number of input/output pins and greater memory capacity. It is ideal for projects like 3D printers,
robotics, and data-intensive applications.

Features:

 54 digital I/O pins – For reading sensors, controlling LEDs, motors, etc.
 16 analog inputs – For reading analog sensors like temperature or potentiometers.
 256 KB flash memory – For storing larger programs and data.

2. Arduino Nano

The Arduino Nano is a compact, breadboard-friendly microcontroller board suitable for


small-scale or space-constrained projects. Despite its size, it offers similar functionality to the
Arduino UNO.

Features:

 22 digital I/O pins – Great for small but feature-rich projects.


 8 analog inputs – Allows interfacing with multiple analog sensors.
 USB mini-B connection – Used for programming and serial communication.

3. Arduino Due

The Arduino Due is the first Arduino board that features a 32-bit ARM Cortex-M3 core
microcontroller. It offers improved performance and higher clock speeds, making it ideal for
applications that require fast computation or processing.

Features:

 54 digital I/O pins – Supports complex interfacing.


 12 analog inputs – For high-resolution analog sensor reading.
 Higher clock speed (84 MHz) – Enables faster data processing and execution.

4. Arduino UNO

The Arduino UNO is the most widely used board, perfect for beginners. It's known for its
ease of use and wide community support.

Features:

 Microcontroller: ATmega328P
 Operating Voltage: 5V
 Digital I/O Pins: 14 (6 with PWM capability)
 Analog Input Pins: 6
 Clock Speed: 16 MHz

5. Arduino UNO Pinout Definitions

a) Power Pins:

 Vin – Voltage input when using an external power supply (7–12V).


 5V – Regulated 5V output to power other components.
 3.3V – Regulated 3.3V output for low-voltage components.
 GND – Ground connection; reference point for all voltages in the circuit.

b) Analog Pins:

 A0 to A5 – Used for reading analog inputs (0–5V). Commonly used with sensors like
temperature, light, or potentiometers.

c) Digital Pins:

 D0 to D13 – General-purpose digital input/output pins used to control or read digital


devices like LEDs, buttons, or relays.
d) PWM-enabled Pins:

 D3, D5, D6, D9, D10, D11 – These pins support Pulse Width Modulation (PWM), which
allows analog-like output using digital signals. Useful for dimming LEDs or controlling
motor speeds.

e) ICSP Header:

 In-Circuit Serial Programming (ICSP) – A set of pins used for programming the
microcontroller directly using SPI protocol. Helpful when bootloader reprogramming is
needed.

f) ATmega328 (Microcontroller):

The heart of the Arduino UNO board, this chip handles all processing tasks. It executes
code uploaded via the Arduino IDE and controls all I/O operations.

g) ATMega1602 (Display Interface – Optional):

Not part of the Arduino UNO board itself, but often referred to in Arduino projects using
1602 LCD displays. It’s a common alphanumeric display interface that connects to the
UNO for showing data.

h) USB-B Port:

Used to connect the Arduino UNO to a computer. It serves both as a power source and
communication channel for uploading code and monitoring output through the serial
monitor.

i) Voltage Regulator:

Ensures a stable supply voltage (5V or 3.3V) to the microcontroller and connected
components, regardless of input fluctuations.
Pin Diagram:

Arduino Board:
Result:
The study of the Arduino platform provided knowledge about its origin, hardware
components, software environment (IDE), working mechanism, applications, and various types of
boards. Understanding Arduino lays the foundation for embedded systems and IoT projects.
Ex No: 5b
Date: LED BLINK

Aim:

To write a program to make the led blink using Arduino.

Algorithm:

1. Start
2. Initialize the led pin
3. Turn on the led x wait for a second
4. Turn off led x wait for a second
5. Stop

Program:

const int ledPin = 13;

void setup() {

pinMode(ledPin, OUTPUT);

void loop() {

digitalWrite(ledPin, HIGH);

delay(1000);

digitalWrite(ledPin, LOW);

delay(1000);

}
Output:

Result:

Thus, the program to make the led blink using Arduino was developed successfully.
Ex No: 5c
Date: LIGHT SENSOR

Aim:
To write a program to detect light using light sensor and Arduino.

Algorithm:
1. Start.
2. Initialize the digital pin.
3. Read the analog value to the sensor.
4. Display the amount of brightness based on the analog value.
5. Stop.

Program:

void setup()
{
Serial.begin(9600);
}
Void loop()
{
Int analogvalue = analogread(a0);
Serial.print("analog reading = ");
Serial.print(analogvalue);
If (analogvalue < 100)
{
Serial.println(" - very bright");
}
Else if (analogvalue < 200)
{
Serial.println(" - bright");
}
Else if (analogvalue < 500)
{
Serial.println(" - light");
}
Else if (analogvalue < 800)
{
Serial.println(" - dim");
}
Else
{
Serial.println(" - dark");
}
Delay(500);
}
Output:
Result:

Thus the program detect light using LDR sensor and arduino was developed successfully.
Ex No:5d TEMPERATURE SENSOR
Date:

Aim:
To write a program to detect temperature using temperature sensor and

Arduino.

Algorithm:
Step 1: Start.

Step 2: Initialize the digital pin.

Step 3: Read the analog value to the sensor.

Step 4: Read the temperature.


Step 5: Display the temperature using serial monitor.

Step 6: Stop.

Program:
int val;

int tempPin = 2;

void setup() {

Serial.begin(9600);
}

void loop() {

val = analogRead(tempPin);

float mv = (val / 1024.0) * 5000;

float cel = mv / 10;

Serial.print("Temperature = ");
Serial.print(cel);

Serial.print("*C");

Serial.println();

delay(1000);

Output:

Result:
Thus the program to detect temperature using temperature sensor and Arduino

was developed successfully.


Ex No: 5e
LED FADE
Date:

Aim:

To write a program to make the led fade using Arduino.

Algorithm:

Step 1: Start
Step 2: Initialize variables: led = 9, brightness = 0, fadeamount = 5
Step 3: Set up pin 9 as output to control the led brightness.
Step 4: Enter the loop routine.
Step 5: Set the brightness of pin 9 using analogwrite(led, brightness).
Step 6: Increment the brightness by fadeamount.
Step 7: Check if brightness is at its minimum (0) or maximum (255).
Step 8: If so, reverse the direction of fading by changing the sign of fadeamount

Step 9: Wait for 30 milliseconds to observe the dimming effect using delay(30).

Step 10: Repeat from step 5 until the program stops.


Step 11: Stop

Program:

Int led = 9;

brightness = 0;

Int fadeamount = 5;

void setup()

pinmode(led, output);

}
void loop() {

analogwrite(led, brightness);

Brightness = brightness + fadeamount;

if (brightness <= 0 || brightness >= 255)

Fadeamount = -fadeamount;

delay(30);

Output:

Result:

Thus, the program to make the led blink using Arduino was developed successfully.
Ex No :6 EXPLORE DIFFERENT COMMUNICATION
Date: METHODS WITH IOT DEVICES (GSM, BLUETOOTH)

Aim :

To explore different communication methods with IoT devices using GSM and
Bluetooth.

1. Bluetooth

Algorithm :

1. Start program and initialize Serial & Bluetooth at 9600 baud.

2. Set pin modes for Bluetooth TX/RX, power, and buttons.

3. Power ON the Bluetooth module via pin 4.

4. Clear serial buffer to avoid junk data.

5. Print startup info from Bluetooth (if any).

6. On button press, send command :P, print name, and control LED.

7. Send user input (from Serial) to Bluetooth after converting to uppercase.

8. Respond to commands like AT, AT+NAME, etc., with fixed messages.

9. Receive and show Bluetooth responses on Serial Monitor.

10. On "BYE" command, reset Bluetooth by toggling power.

11. Repeat loop to maintain continuous communication.

Program:

#include <SoftwareSerial.h>

#define led 3

const byte bt_RX = 2, bt_TX = 3, bt_Vin = 4;

const byte button_Vin = 9, button_Vout = 11;


SoftwareSerial BTSerial(bt_RX, bt_TX);

void setup() {

Serial.begin(9600);

BTSerial.begin(9600);

delay(1000);

pinMode(bt_RX, INPUT);

pinMode(bt_TX, OUTPUT);

pinMode(bt_Vin, OUTPUT);

pinMode(button_Vin, OUTPUT);

pinMode(button_Vout, INPUT_PULLUP);

delay(100);

digitalWrite(bt_Vin, HIGH);

delay(500);

if(BTSerial.available())

BTSerial.read(); //clears mysterious byte from bluetooth serial buffer

for (int i = 0; i < 32; i++ ) {

if (BTSerial.available()) Serial.write((char)BTSerial.read());

Serial.println("");

void loop() {

static String msg_to_bt = "";

static String msg_from_bt = "";


static String atm = "";

static byte dByte = "";

if(digitalRead(button_Vout) == 0) { //press

Serial.println("AT");

BTSerial.write(":P\n");

Serial.println("Noman 12084");

digitalWrite(led, LOW);

delay(100);

else if(digitalRead(button_Vout) == 1){

digitalWrite(led,HIGH);

msg_to_bt = "";

while(Serial.available()){

dByte = Serial.read();

if (dByte >= 97 && dByte <= 122) dByte -= 32;

Serial.print((char)dByte);

if (dByte > 31 && dByte < 127) msg_to_bt += (char)dByte;

if (msg_to_bt != "") BTSerial.println(msg_to_bt);

if(msg_to_bt == "AT") BTSerial.write(" OK\n");

if(msg_to_bt == "AT+NAME") BTSerial.write(" Backseat Guardian\n");

if(msg_to_bt == "AT+VERSION") BTSerial.write(" LINVORV1.8\n");


if(msg_to_bt == "AT+BAUD") BTSerial.write(" 9600\n");

msg_from_bt = "";

while(BTSerial.available()){

dByte = BTSerial.read();

if (dByte >= 97 && dByte <=122) dByte -= 32; //capitalizes message

Serial.print((char)dByte);

if (dByte > 31 && dByte < 127) msg_from_bt += (char)dByte;

atm = "";

delay(100);

atm += msg_from_bt[0];

atm += msg_from_bt[1];

atm += msg_from_bt[2];

if (msg_from_bt != "") {

if (atm == "AT+") {

if(msg_from_bt == "AT+NAME") BTSerial.write("+NAME:Backseat Guardian\n");

if(msg_from_bt == "AT+VERSION") BTSerial.write("LINVORV1.8\n");

if(msg_from_bt == "AT+BAUD") BTSerial.write("9600\n");

Serial.print(".");

if(msg_from_bt == "AT") BTSerial.write("OK\n");

if(msg_from_bt == "HELLO") BTSerial.write("Welcome!\n");

if(msg_from_bt == "LOCATION") BTSerial.write("I'm right here: \n");


if(msg_from_bt == "BYE") {

digitalWrite(bt_Vin, LOW); //disconnects bluetooth

delay(1000);

BTSerial.read();

digitalWrite(bt_Vin, HIGH);

delay(1000);

Output :
2. GSM :

Algorithm :

1. Start

2. Init serials, modules, pins.

3. Begin serials at 9600.

4. Loop for data handling

5. Read sensor data.

6. Handle GSM communication.

7. Handle GPS communication.

8. Stop

Program :

#include SoftwareSerial sim800L(2, 3);

SoftwareSerial neo6m(6, 7);

const uint8_t buzzPin = 12;

const uint8_t motionPin = 13;

const uint8_t button_VIN = 9;

const uint8_t button_VOUT = 11;

void setup() {

Serial.begin(9600);

sim800L.begin(9600);

neo6m.begin(9600);

}
void loop() { }

Output :

Result :
Thus, the exploration of communication between different IoT devices using Bluetooth and
GSM was verified Successfully.
Aim :

To study and understand the features, architecture, and programming capabilities of the
Raspberry Pi Pico W microcontroller platform.

Introduction to Raspberry Pi Pico W:

The Raspberry Pi Pico W is a compact and affordable microcontroller board developed by


the Raspberry Pi Foundation. Building upon the success of the Raspberry Pi Pico, the Pico W
variant brings wireless connectivity to the table, making it an even more versatile platform for
embedded projects. In this article, we will provide a comprehensive overview of the Raspberry
Pi Pico W, highlighting its key features and capabilities.

Features:

● RP2040 microcontroller with 2MB of flash memory


● On-board single-band 2.4GHz wireless interfaces (802.11n)
● Micro USB B port for power and data (and for reprogramming the flash)
● 40 pins 21mm x 51mm 'DIP' style 1mm thick PCB with 0.1" through-hole pins also with
edge castellations
● Exposes 26 multi-function 3.3V general purpose I/O (GPIO)
● 23 GPIO are digital-only, with three also being ADC-capable
● Can be surface mounted as a module
● 3-pin ARM serial wire debug (SWD) port
● Simple yet highly flexible power supply architecture
● Various options for easily powering the unit from micro-USB, external supplies, or
batteries
● High quality, low cost, high availability
● Comprehensive SDK, software examples, and documentation
● Dual-core Cortex M0+ at up to 133MHz
● On-chip PLL allows variable core frequency
● 264kByte multi-bank high-performance SRAM

Raspberry Pi Pico W:

The Raspberry Pi Pico W is based on the RP2040 microcontroller, which was designed by
Raspberry Pi in-house. It combines a powerful ARM Cortex-M0+ processor with built-in Wi-Fi
connectivity, opening up a range of possibilities for IoT projects, remote monitoring, and
wireless communication. The Pico W retains the same form factor as the original Pico, making it
compatible with existing Pico accessories and add-ons.

RP2040 Microcontroller:

At the core of the Raspberry Pi Pico W is the RP2040 microcontroller. It features a dual-core
ARM Cortex-M0+ processor running at 133MHz, providing ample processing power for a wide
range of applications. The microcontroller also includes 264KB of SRAM, which is essential for
storing and manipulating data during runtime. Additionally, the RP2040 incorporates 2MB of
onboard flash memory for program storage, ensuring sufficient space for your code and
firmware.

Wireless Connectivity:

The standout feature of the Raspberry Pi Pico W is its built-in wireless connectivity. It
includes an onboard Cypress CYW43455 Wi-Fi chip, which supports dual-band (2.4GHz and
5GHz) Wi- Fi 802.11b/g/n/ac. This allows the Pico W to seamlessly connect to wireless
networks, communicate with other devices, and access online services. The wireless capability
opens up new avenues for IoT projects, remote monitoring and control, and real-time data
exchange.

GPIO and Peripherals:

Similar to the Raspberry Pi Pico, the Pico W offers a generous number of GPIO pins,
providing flexibility for interfacing with external components and peripherals. It features 26
GPIO pins, of which 3 are analog inputs, and supports various protocols such as UART, SPI, I2C,
and PWM. The Pico W also includes onboard LED indicators and a micro-USB port for power
and data connectivity.

MicroPython and C/C++ Programming:

The Raspberry Pi Pico W can be programmed using MicroPython, a beginner-friendly


programming language that allows for rapid prototyping and development. MicroPython
provides a simplified syntax and high-level abstractions, making it easy for newcomers to get
started. Additionally, the Pico W is compatible with C/C++ programming, allowing experienced
developers to leverage the rich ecosystem of libraries and frameworks available.

Programmable Input/Output (PIO) State Machines:

One of the unique features of the RP2040 microcontroller is the inclusion of Programmable
Input/Output (PIO) state machines. These state machines provide additional processing power
and flexibility for handling real-time data and timing-critical applications. The PIO state
machines can be programmed to interface with custom protocols, generate precise waveforms,
and offload tasks from the main processor, enhancing the overall performance of the system.

Open-Source and Community Support:

As with all Raspberry Pi products, the Pico W benefits from the vibrant and supportive
Raspberry Pi community. Raspberry Pi provides extensive documentation, including datasheets,
pinout diagrams, and programming guides, to assist developers in understanding the board's
capabilities. The community offers forums, online tutorials, and project repositories, allowing
users to seek help, share knowledge, and collaborate on innovative projects.

Result:

Thus, the study of the Raspberry Pi Pico W microcontroller platform was completed, and the
key features, wireless capabilities, GPIO options, and programming methods were successfully
understood.
Aim :
To Write a program for blink an LED connected to a microcontroller using Python
programming with the machine and utime modules.

Algorithm :

1. Start
2. Import the pin class from the machine module and the sleep function from the utime
module.

3. Initialise a new pin object named led with pin number 11 and set it as an output pin.

4. Enter an infinite loop.


4.1 : Toggle the state of the led connected to pin 11 (if it's on, turn it off, and if It's off, it on).

4.2 : Pause the execution for 0.5 seconds using the sleep function to create a
blinking effect.
5. Stop

Program:
from machine import pin

from utime import sleep

Led = pin(11, pin.out)

While true:

Led.toggle()

Sleep(0.5)
Output:

Result :
Thus, the LED blinking program was written, executed, and the LED successfully blinked as
expected.
Aim :

To write a program for control an LED using a push button connected to a microcontroller by
writing a Python program with machine and time modules.

Algorithm :

1. Start
2. Initialize LED connected to pin 15 and set it as an output.
3. Initialise the push button connected to pin 16 and set it as an input.

4. : If the button is pressed (HIGH),then turn the LED on.


5. Wait for a short duration (0.1 seconds).
6. Otherwise,turn the LED off.
7. Stop

Program:

from machine import Pin


from time import sleep
LED = Pin(15, Pin.OUT)
BUTTON = Pin(16, Pin.IN)
while True:
if BUTTON.value() == 1:
LED.on()
sleep(0.1)
else:
LED.off()
Output:

Result :
Thus, the push button and LED control program was written, executed, and the LED
responded to the button press successfully.
Aim :
To Write a program for blink multiple LEDs connected to GPIO pins of a microcontroller
simultaneously using Python programming with machine and time modules.

Algorithm :

1. Start
2. Import the Pin class from the machine module and the sleep function
from the time module.
3. Define four LED objects (LED1, LED2, LED3, LED4) each connected to GPIO
pins 6, 7, 8, and 9 respectively, all set as output pins.
4. Turn all LEDs on simultaneously.
5. Wait for 1 second.
6. Turn all LEDs off simultaneously.
7. Wait for 1 second.
8. Stop.

Program:

from machine import Pin


from time import sleep
LED1 = Pin(5, Pin.OUT)
LED2 = Pin(9, Pin.OUT)
LED3 = Pin(13, Pin.OUT)
LED4 = Pin(15, Pin.OUT)
while True:
LED1.on()
LED2.on()
LED3.on()
LED4.on()
sleep(1)
LED1.off()
LED2.off()
LED3.off()
LED4.off()
sleep(1)

Output:

Result :
Thus, the program for blinking multiple LEDs was written, executed, and the LEDs blinked
simultaneously as intended.
Ex No:8
Date: INTERFACING SENSORS WITH RASPBERRY PI PICO

Aim:

To interface an ultrasonic sensor (HC-SR04) with a Raspberry Pi Pico and measure the
distance of an object using MicroPython.

Algorithm :

1. Start the program and print a welcome message.

2. Initialize GPIO pin 3 as trigger (output) and pin 2 as echo (input).

3. Send a 5µs trigger pulse to initiate measurement.

4. Record the time when echo pin goes HIGH and then LOW.

5. Calculate the time difference and convert it to distance.

6. Display the measured distance on the serial monitor.

7. Repeat the measurement continuously with a 1-second delay.

Program:

From machine import Pin

Import utime

Print(“Hello, P1 Pico!”)

Trigger = Pin(3, Pin.OUT)

Echo = Pin(2, Pin.IN)

Def ultra():

Trigger.low()
Utime.sleep_us(2)

Trigger.high()

Utime.sleep_us(5)

Trigger.low()

While echo.value() == 0:

Signaloff = utime.ticks_us()

While echo.value() == 1:

Signalon = utime.ticks_us()

Timepassed = signalon – signaloff

Distance = (timepassed * 0.0343) / 2

Print(“The distance from object is”, distance, “cm”)

While True:

Ultra()

Utime.sleep(1)
Output:

Result:

The program successfully interfaces the ultrasonic sensor with the Raspberry Pi Pico and
continuously measures the distance from an object. The output is displayed in centimeters on the
serial monitor.
Ex No: 9 COMMUNICATE BETWEEN ARDUINO AND
RASPBERRY PI USING ANY WIRELESS
Date:
MEDIUM

Aim:
To enable communication between Arduino and Raspberry Pi using any wireless medium

Introduction:

Raspberry Pi Pico:

The Raspberry Pi Pico is a microcontroller development board featuring the RP2040


microcontroller chip developed by the Raspberry Pi Foundation. It's designed for embedded
applications and projects, offering a compact form factor and GPIO pins for interfacing with
various sensors, actuators, and peripherals.

Arduino:

Arduino is an open-source electronics platform based on easy-to-use hardware and software. It


consists of a physical programmable circuit board (often referred to as the Arduino board) and a
development environment (IDE) that implements the Arduino programming language. Arduino
boards are commonly used for prototyping and building interactive electronic projects.

HC-05 Bluetooth Module:

The HC-05 is a widely used Bluetooth module that enables wireless communication between
electronic devices. It operates over the Serial Port Profile (SPP) and can be configured to act as
either a master or slave device. The HC-05 module is commonly used in hobbyist projects for
establishing Bluetooth connections between microcontrollers, computers, smartphones, and other
devices.

Algorithm:

1. Initialize UART communication with the HC-05 module.


2. Continuously read data from the HC-05 module.
3. If the received data is 'on', turn on the LED.
4. If the received data is 'off', turn off the LED.
5. Initialize serial communication.
6. Continuously listen for incoming data from the HC-05 module.
7. If the received data is 'on', turn on the LED.
8. If the received data is 'off', turn off the LED.

Hardware Connections:

1. Raspberry Pi Pico and HC-05 Connection:

1. HC-05 VCC pin to Raspberry Pi Pico 3.3V pin.


2. HC-05 GND pin to Raspberry Pi Pico GND pin.
3. HC-05 TX pin to Raspberry Pi Pico RX pin (GPIO pin that receives data).
4. HC-05 RX pin to Raspberry Pi Pico TX pin (GPIO pin that transmits data).

2. Arduino and HC-05 Connection:

1. HC-05 VCC pin to Arduino 5V pin.


2. HC-05 GND pin to Arduino GND pin.
3. HC-05 TX pin to Arduino digital pin (e.g., Pin 2).
4. HC-05 RX pin to Arduino digital pin (e.g., Pin 3).

3. Entering AT Mode on HC-05:

1. Power off the HC-05 module.


2. Press and hold the small button on the HC-05 module.
3. While holding the button, power on the HC-05 module.
4. Keep holding the button for a few seconds until the LED on the HC-05 module
starts blinking slowly, indicating it's in AT mode.

4. Pairing HC-05 Modules:


1. Ensure AT Mode
2. Set Bluetooth address of the slave HC-05 module by sending
"AT+BIND=<slave_address>" command, where <slave_address> is the
Bluetooth address of the slave module.
3. Exit AT command mode by sending "AT+EXIT" command or by power cycling
the module.
5. Set Slave HC-05 Module:

1. Send AT commands to set the other HC-05 module as the slave.


2. Enter AT command mode by sending "AT" command.
3. Set slave mode by sending "AT+ROLE=0" command.
4. Set the slave HC-05 module to accept connections from the master module by
sending "AT+CMODE=0" command.
5. Exit AT command mode by sending "AT+EXIT" command or by power cycling
the module.

6. Verify Pairing:

1. Power cycle both HC-05 modules to exit AT mode.


2. Once out of AT mode, the master HC-05 module should automatically connect to
the slave HC-05 module.

Program:

Raspberry Pi Pico (Using MicroPython):


import machine
import time
# Define UART pins (TX, RX)
uart = machine.UART(0, baudrate=9600, tx=machine.Pin(0), rx=machine.Pin(1))
# LED pin
led_pin = machine.Pin(2, machine.Pin.OUT)
while True:
# Check if data is available
if uart.any():
# Read data from HC-05
data = uart.read().decode().strip()
print("Received:", data)
# Check if received command is 'on'
if data == 'on':
# Turn on LED
led_pin.value(1)
elif data == 'off':
# Turn off LED
led_pin.value(0)

Arduino (Using Arduino IDE):

const int ledPin = 4; // Pin connected to LED


void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
// Read data from HC-05
String data = Serial.readStringUntil('\n');
Serial.println("Received: " + data);
// Check if received command is 'on'
if (data == "on") {
// Turn on LED
digitalWrite(ledPin, HIGH);
} else if (data == "off") {
// Turn off LED
digitalWrite(ledPin, LOW);

}
}
}

Running the Programs:

1. Upload the Arduino code to your Arduino board using the Arduino IDE.
2. Copy the MicroPython code to your Raspberry Pi Pico and run it using a text
editor like Thonny or a similar MicroPython IDE.

Testing:

1. Power on both the Raspberry Pi Pico and the Arduino.


2. Connect to the Raspberry Pi Pico using a serial terminal (e.g., Thonny).
3. Send the command 'on' over Bluetooth using the serial terminal connected to the
Raspberry Pi Pico.
4. The LED connected to both the Raspberry Pi Pico and the Arduino should turn
on.
5. Send the command 'off' to turn off the LED.
6. This setup should allow you to remotely control an LED connected to both the
Raspberry Pi Pico and the Arduino using HC-05 Bluetooth modules. Adjust the
pin numbers and baud rates in the code according to your specific setup.
Circuit Diagram:
Result:
Thus, simple Iot project to communicate between Arduino and Raspberry PI using any
wireless medium was implemented successful.
Aim:

To setup a cloud platform to log the data from IOT devices.

Hardware/Software Requirements:

S. No Software Quantity

1 Blynk Cloud 1

Cloud Platform:

Blynk:

Blynk is a smart platform that allows users to create their Internet of Things applications without the

need for coding or electronics knowledge. It is based on the idea of physical programming & provides
a platform to create and control devices where users can connect physical devices to the Internet and

control them using a mobile app.

Procedure:

Step 1: Visit blynk.cloud and create a Blynk account on the Blynk website. Or you can simply sign in using

the registered Email ID.

Step 2: Click on +New Template


Step 3: Give any name to the Template such as Raspberry Pi Pico W. Select ‘Hardware Type’

as other and ‘Connection Type’ as WiFi. So a template will be created now.

Step 4: Now we need to add a ‘New Device’ now. Select a New Device from ‘Template’.
Step 5: Select the device from a template that you created earlier and also give any name to the

device. Click on Create.A new device will be created. You will find the Blynk Authentication

Token Here. Copy it as it is necessary for the code.


Step 6: Now go to the dashboard and select ‘Web Dashboard’.From the widget box drag a switch

and place it on the dashboard screen.


Step 7: On the switch board click on Settings and here you need to set up the Switch. Give any

title to it and Create Datastream as Virtual Pin Configure the switch settings as per the image

below and click on create.


Step 8: Configure the final steps again.

Result:

Thus the setup of a cloud platform to log the data from IOT devices was created and implemented

successfully.
AIM :

To test the log data using raspberry pi and upload to the cloud platform.

PROCEDURE:

1. Connect the IR sensor to the Arduino.


2. The connections may vary based on your specific IR sensor model, but typically, it
involves connecting the sensor's signal pin to a digital pin on the Arduino and
power/ground pins appropriately.
3. Install the necessary libraries for the IR sensor.
4. For example, if you are using a common IR sensor like the TSOP382, you might need
the "IRremote" library.

PROGRAM:

import machine

import utime

import

urequests

import network

# Constants

IR_SENSOR_PIN = 2 # GPIO pin for the IR sensor

API_KEY = "ZSX5SRTSRJ61XVU6"

THINGSPEAK_URL = "https://api.thingspeak.com/update?api_key={}".format(API_KEY)
WIFI_SSID = "@ms.Balaji"

WIFI_PASSWORD = "@msbalaji"

# Initialize IR sensor and WLAN

ir_sensor = machine.Pin(IR_SENSOR_PIN, machine.Pin.IN)

wlan = network.WLAN(network.STA_IF)

# Function to connect to Wi-Fi

def connect_to_wifi():

wlan.active(True)

if not wlan.isconnected():

print("Connecting to WiFi...")

wlan.connect(WIFI_SSID, WIFI_PASSWORD)

retry = 0

while not wlan.isconnected() and retry < 10:

utime.sleep(1)

retry += 1

if wlan.isconnected():

print("Connected to WiFi")

else:

print("Failed to connect to WiFi")


else:

print("Already connected to WiFi")

# Function to read from IR sensor

def read_ir_sensor():

return ir_sensor.value()

# Function to send data to ThingSpeak

def send_to_thingspeak(data):

try:

url = "{}&field1={}".format(THINGSPEAK_URL, data)

response = urequests.get(url)

print("ThingSpeak response:", response.text)

response.close()

except Exception as e:

print("Failed to send data:", e)

# Main loop

connect_to_wifi()

while True:

ir_data = read_ir_sensor()
print("IR Sensor Data:", ir_data)

send_to_thingspeak(ir_data)

utime.sleep(15) # Wait for 15 seconds

OUTPUT:

RESULT:

Thus, to test the log data using raspberry pi and upload to the cloud platform is done
successfully and the output has been verified.
Ex no:12
DESIGN AN IOT BASED SYSTEM
Date:

Aim:

To design an IOT-driven system that autonomously modulates LED luminance based on real- time
ambient light intensity measurements acquired through a Light Dependent Resistor (LDR)

Algorithm:

1. Start the system.


2. Set A0 as input pin.
3. Set pin 6 as output pin.
4. Read the analog value from LDR at pin A0.
5. Map the LDR value from range 0–1023 to 0–255.
6. Write the mapped value to pin 6 to control LED brightness.
7. Repeat steps 4–6 continuously.

Program:

void setup() {

pinMode(A0,INPUT); // Set A0 as input pinMode(6,

OUTPUT);

void loop() {

int ldr = analogRead(A0); // Read the value from LDR (Light Dependent Resistor)
int bri = map(ldr, 0, 1023, 0, 255); // Map the LDR value to brightness range (0 -255)

analogWrite(6, bri); // Write the brightness value to pin 6

Output:
Result:

Thus, the experiment to design an IOT-based system that automatically adjusts LED
brightness according to ambient light intensity sensed by an LDR (Light Dependent Resistor) has
been successfully written, executed, and the output has been verified.

You might also like