1 8051 Assembly Language Experiments Using Simulator

Download as pdf or txt
Download as pdf or txt
You are on page 1of 67

EX NO:1 8051 assembly Language experiments using simulator

AIM:
To write 8051 assembly language program for arithmetic operations like
(addition,subtraction,multiplication and division) and verify the output of the experiment
using simulator.
Apparatus required:
1.computer
2.keil vision 5 simulator
Procedure:
1.Double click the keil icon on the desktop.
2. Close any previous projects that were opened using – Project -> Close.
3.Go to project ->New μ vision project.
4.Name the file and save.
5.Search and select AT89C51 and then click ok.
6.Copy’startup,A51’ to project folder and add file to project will be displayed.click No.
7.Create a source file using File->New and type the program and save as (filename.asm).
8.Set the target option by clicking the + symbol in target1.
9.Right click on the source file and add existing file to group ‘source group 1’.
10.Select file.asm and add,close.
11.Build the project using project->Build target.
12. Any errors in the code are indicated by – “Target not created” in the Build window, along
with the error line. Correct the errors and save it.
13. Go to Debug->Start/Stop debug session.
14.Then running with code size limit 2k will be displayed.Click OK.
15. The program is run using the Debug->Run command.

PROGRAM:
org 0000h
mov a,#02h
add a,#03h
mov r1,a
clr a
clr c
mov a,#05h
subb a,#02h
mov r2,a
mov a,#03h
mov b,#04h
mul ab
mov r3,a
mov r4,b
clr a
mov a,#95h
mov b,#10h
div ab
mov r5,a
mov r6,b
end
ALGORITHM :

1. Move value 02H in accumulator


2. Add 03H to the number stored in accumulator (02H)
3. Move contents of accumulator to R1 register
4. Clear accumulator
5. Move number 05H in accumulator.
6. Subtract value stored in accumulator (05H) with 02H.
7. Move contents of accumulator to register R2.
8. Clear accumulator and carry flag.
9. Move 03H in accumulator. 02H in register B.
10. Multiply the two numbers.
11. Store product in R3 and R4.
12. Clear accumulator.
13. Move 95H and 10H in registers A and B.
14. Divide the two numbers.
15. Move the result in R5 and R6.
16. Stop

CALCULATION:
OUTPUT:

Addition
r1=

Subtraction
r2=
Multiplication
r3=
r4=
Division
r5=
r6=

Result:Thus the 8051 assembly language program for arithmetic operations like
(addition,subtraction,multiplication and division) was written and verified using Keil
simulator.
EX No:2 TEST DATA TRANSFER BETWEEN REGISTER AND MEMORY

Aim:

To test the data transfer between register and memory using simulator.

Apparatus required:
1.computer
2.keil vision 5 simulator
Procedure:
1.Double click the keil icon on the desktop.
2. Close any previous projects that were opened using – Project -> Close.
3.Go to project ->New μ vision project.
4.Name the file and save.
5.Search and select AT89C51 and then click ok.
6.Copy’startup,A51’ to project folder and add file to project will be displayed.click No.
7.Create a source file using File->New and type the program and save as (filename.asm).
8.Set the target option by clicking the + symbol in target1.
9.Right click on the source file and add existing file to group ‘source group 1’.
10.Select file.asm and add,close
11.Build the project using project->Build target.
12. Any errors in the code are indicated by – “Target not created” in the Build window, along
with the error line. Correct the errors and save it.
13. Go to Debug->Start/Stop debug session.
14.Then running with code size limit 2k will be displayed.Click OK.
15.Go to view -> Memory windows ->select the memory 2 (or)any memory.
16.Type the memory address as Memory 2 I:0x20 and then press enter.

17.Right click on the first memory data 00 and click modify memory.

18.Give the seven datas as 20,30,40,6, 5,8,50.Then click Ok.

19.Click F11 to increase the address in the keyboard or in the system.

20.To see the output in the memory address change as Memory 2 I:0x40 and then press
enter.

21.Click F11 to increase the address and see the output.

PROGRAM:
mov r0,#20h //source address

mov r1,#40h //destination address

mov r3,#07h //Number of bytes


BACK: MOV a,@r0
mov@r1,a
inc r0
inc r1
djnz r3,back
end
ALGORITHM:
1.Move 20h to r0 register.
2.Move 40h to r1 register.
3.Move the number of data 07 to r3.
4.move r0 to A register.
5.Move the A register to r1.
6.Increment r0.
7.Increment r1.
8.Decrement jump not zero . Repeat till all data
transferred ( r3=0).
9.stop
INPUT:
I:0X20 20,30,40,6, 5,8,50

OUTPUT:
I:0X40 20,30,40,6, 5,8,50

RESULT:

Thus the data is transferred from register to memory.


EX NO:3 Basic and arithmetic programs using Embedded C
Aim:

To write the program for arithmetic operations like (addition,subtraction,multiplication and


division) and logical operations like(AND,OR,EX-OR,NOT) using embedded C.

Apparatus required:
1.computer
2.keil vision 5 simulator
Procedure:
1.Double click the keil icon on the desktop.
2. Close any previous projects that were opened using – Project -> Close.
3.Go to project ->New μ vision project.
4.Name the file and save.
5.Search and select AT89C51 and then click ok.
6.Copy’startup,A51’ to project folder and add file to project will be displayed.click No.
7.Create a source file using File->New and type the program and save as (filename.C).
8.Set the target option by clicking the + symbol in target1.
9.Right click on the source file and add existing file to group ‘source group 1’.
10.Select file.C and add ,close.
11.Build the project using project->Build target.
12. Any errors in the code are indicated by – “Target not created” in the Build window, along
with the error line. Correct the errors and save it.
13. Go to Debug->Start/Stop debug session.
14.Then running with code size limit 2k will be displayed.Click OK.
15.Go to peripherals->select the corresponding I/O ports and perform the arithmetic and
logical operations.
16.Press F11 to see the output.
PROGRAM:
Addition:
#include<reg51.h>
Void main(Void)
{
Unsigned char a,b,c;
While(1)
{
P1=0xff; // declare as input port
P2=0xff; //declare as input port
a=P1;
b=P2;
c=a+b;
P3=c;
}
}
Subtraction:
#include<reg51.h>
Void main(Void)
{
Unsigned char a,b,c;
While(1)
{
P1=0xff;
P2=0xff;
a=P1;
b=P2;
c=a-b;
P3=c;
}
}
Multiplication:
#include<reg51.h>
Void main(Void)
{
Unsigned char a,b,c;
While(1)
{
P1=0xff;
P2=0xff;
a=P1;
b=P2;
c=a*b;
P3=c;
}
}
Division:
#include<reg51.h>
Void main(Void)
{
Unsigned char a,b,c;
While(1)
{
P1=0xff; // declare as input port
P2=0xff; //declare as input port
a=P1;
b=P2;
c=a/b;
P3=c;
}
}
Logical operations Program:
#include<reg51.h>
Void main(Void)
{
P0=0x35&0x0F;
P1=0x04|0x68;
P2=0x54^0x78;
P3=~0x55;
}

ALGORITHM :(Arithmetic Operation)


1.Build header file for 8051 is included.
2.Void main is a program syntax representing it will not return anything to the operating
system.
3.unsigned characters a,b,c are declared.
4While(1) represents a continuous operation.
3.Port P1 and P2 are assigned as input port by writing all 1’s.
4.Port P1 is assigned as input a.
5.Port P2 is assigned as input b.
6.Output c is input (a +b) for addition, Output c is input (a -b) for subtraction, Output c is
input (a *b) for multiplication , Output c is input (a /b) for division.
6.Port P3 is assigned as output c.
ALGORITHM :(Logical Operation)
1.Build header file for 8051 is included.
2.Void main is a program syntax representing it will not return anything to the operating
system.
3.P0 is assigned as output port for AND operation.
4.P1 is assigned as output port for OR operation.
5.P2 is assigned as output port for XOR operation.
6.P3 is assigned as output port for NOT operation.

Manual calculations:
OUTPUT:(Arithmetic operation)
P0=
P1=
P2=
P3=

OUTPUT:(Logical operation)
P0=
P1=
P2=
P3=

RESULT:
Thus the program for arithmetic operations like (addition,subtraction,multiplication and
division) and logical operations like(AND,OR,EX-OR,NOT) using embedded C was written and
the output is executed.
ADDITION(FLOWCHART)

Start

Clear R0 for carry

Load address of data


in DPTR

Get first data in A and


move to R1

Increment DPTR

Get second data in A

Add the content of R1


with A-register

Check
Yes Increment R0-
whether CF =0 register

No
Increment DPTR and
store the sum
(A-register) in
memory

Increment DPTR and


store the carry (R0-
register) in memory

Stop
Expt. No. 4 a)
PERFORM ALU OPERATIONS USING 8051
ADDITION OF TWO 8 BIT NUMBERS

AIM:
To write an assembly language program to perform addition of two 8-bit numbers with and
without carry using 8051 Microcontroller.

APPARATUS REQUIRED:

1.8051 Microcontroller Kit.

2. Keyboard.

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMME


NTS
4100 MOV R0,#00H CLEAR R0 FOR CARRY
MOV MOVE THE ADDRESS OF DATA
DPTR,#4500H TO DPTR
MOVX A,@DPTR MOVE THE DATA FROM
MEMORY TO A
MOV R1,A MOVE THE DATA FROM A TO R1
INC DPTR INCREMENT DPTR
MOVX A,@DPTR MOVE THE DATA FROM
MEMORY TO A
ADD A,R1 ADD THE DATA IN A AND R1
JNC L1 CHECK CF=0 IF YES JUMP TO L1
INC R0 INCREMENT R0 (CARRY)
L1: INC DPTR INCREMENT DPTR
MOVX @DPTR,A MOVE THE DATA FROM A TO
MEMORY
INC DPTR INCREMENT DPTR
MOV A,R0 MOVE THE DATA FROM R0 TO A
MOVX @DPTR,A MOVE THE DATA FROM A TO
MEMORY
L2: SJMP L2 SHORT JUMP TO L2
ADDITION OF TWO 8-BIT NUMBERS (WITH CARRY)

INPUT OUTPUT

ADDRESS DATA ADDRESS DATA


4500 4502
4501 4503

CALCULATION:

WITHOUT CARRY
INPUT OUTPUT
ADDRE DATA ADDRE DATA
SS
4500
SS
4502
4501
4503
9001
CALCULATION:
RESULT:
Thus the assembly language program to perform addition of two 8-bit numbers with and without carry using
8051 Microcontroller was executed successfully and output verified.
SUBTRACTION OF TWO 8 BIT NUMBERS(FLOW CHART)

Start

Clear R0 for
carry

Load address of
data
in DPTR

Get first data in A and


move to R1

Increment DPTR

Get second data in A

Subtract the content


of R1 from A-
register

Yes Increment
Check R0-register
whether CF =0

No
Increment DPTR
and store the sum
(A-register) in
memory

Increment DPTR
and
store the
carry (R0-
register) in

Stop
Expt. No. 4 b)
SUBTRACTION OF TWO 8 BIT NUMBERS

AIM:
To write an assembly language program to perform subtraction of
two 8-bit numbers with and without borrow using 8051 Microcontroller.

APPARATUS REQUIRED:

1.8051 Microcontroller Kit.

2. Keyboard.

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


4100 MOV R0,#00H CLEAR R0 FOR CARRY
MOV DPTR,#4500H MOVE THE ADDRESS OF
DATA TO DPTR
MOVX A,@DPTR MOVE THE DATA FROM
MEMORY TO A
MOV R1,A MOVE THE DATA FROM A
TO R1
INC DPTR INCREMENT DPTR
MOVX A,@DPTR MOVE THE DATA FROM
MEMORY TO A
SUBB A,R1 SUBTRACT THE DATA IN
R1 FROM A
JNC L1 CHECK CF=0 IF YES JUMP
TO L1
INC R0 INCREMENT R0 (CARRY)
CPL A COMPLEMENT THE DATA
IN A
INC A INCREMENT THE DATA IN
A
L1: INC DPTR INCREMENT DPTR
MOVX @DPTR,A MOVE THE DATA FROM A
TO MEMORY
INC DPTR INCREMENT DPTR
MOV A,R0 MOVE THE DATA FROM
R0 TO A
MOVX @DPTR,A MOVE THE DATA FROM A
TO MEMORY
L2: SJMP L2 SHORT JUMP TO L2
SUBTRACTION OF TWO 8-BIT NUMBERS (WITH CARRY)

INPUT OUTPUT

ADDRESS DATA ADDRESS DATA


4500 4502
4501 4503

CALCULATION:
RESULT:

Thus the assembly language program to perform Subtraction of two 8-bit numbers with and without carry
using 8051 Microcontroller was executed successfully and output verified
MULTIPLICATION OF TW0 8 BIT NUMBERS(FLOW CHART)

Start

Load address of data


in DPTR

Get first data in A and


move to B

Increment DPTR

Get second data in A

Multiply the content


of A and B reg.

Increment DPTR and


store the value in A into
memory

Increment DPTR and


store the value in B into
memory

Stop
Expt. No. 4 c)

MULTIPLICATION OF TW0 8 BIT NUMBERS

AIM:
To write an assembly language program to perform multiplication of
two 8-bit numbers using 8051 Microcontroller.

APPARATUS REQUIRED:

1.8051 Microcontroller Kit.

2. Keyboard.

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


4100 MOV DPTR,#4500H MOVE THE ADDRESS OF
DATA TO DPTR
MOVX A,@DPTR MOVE THE DATA FROM
MEMORY TO A
MOV B,A MOVE THE DATA FROM A TO
B
INC DPTR INCREMENT DPTR
MOVX A,@DPTR MOVE THE DATA FROM
MEMORY TO A
MUL AB MULTIPLY THE DATA FROM
A AND B
INC DPTR INCREMENT DPTR
MOVX @DPTR,A MOVE THE DATA FROM A TO
MEMORY
MOV A,B MOVE THE DATA FROM B TO
A
INC DPTR INCREMENT DPTR
MOVX @DPTR,A MOVE THE DATA FROM A TO
MEMORY
L1: SJMP L1 SHORT JUMP TO L1
INPUT OUTPUT
ADDRESS DATA
4500
ADDRESS DATA
4502
4501
4503

CALCULATION:

RESULT:

Thus the assembly language program to perform multiplications of two 8-bit numbers with and without
carry using 8051 Microcontroller was executed successfully and output verified
DIVISION OF TW0 8 BIT NUMBER(FLOW CHART)

Start

Load address of data


in DPTR

Get first data in A and


move to B

Increment DPTR

Get second data in A

Divide the Data in B


by A reg.

Increment DPTR and


store the value in A
into memory

Increment DPTR and


store the value in B into
memory

Stop
Expt. No. 4 d)
DIVISION OF TW0 8 BIT NUMBERS

AIM:
To write an assembly language program to perform division of two 8-
bit numbers using 8051 Microcontroller.

APPARATUS REQUIRED:

1.8051 Microcontroller Kit.

2. Keyboard.

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


4100 MOV DPTR,#4500 MOVE THE ADDRESS OF DATA
TO DPTR
MOVX A,@DPTR MOVE THE DATA FROM
MEMORY TO A
MOV B,A MOVE THE DATA FROM A TO B
INC DPTR INCREMENT DPTR
MOVX A,@DPTR MOVE THE DATA FROM
MEMORY TO A
DIV AB DIVIDE THE DATA IN A BY B
INC DPTR INCREMENT DPTR
MOVX @DPTR,A MOVE THE DATA FROM A TO
MEMORY
MOV A,B MOVE THE DATA FROM B TO A
INC DPTR INCREMENT DPTR
MOVX @DPTR,A MOVE THE DATA FROM A TO
MEMORY
L1: SJMP L1 SHORT JUMP TO L1
INPUT OUTPUT

ADDRESS DATA
ADDRESS DATA
4500
4502
4501
4503

CALCULATION

RESULT:
Thus the assembly language program to perform division of two 8-bit numbers with and without carry using
8051 Microcontroller was executed successfully and output verified.
LOGICAL OPERATIONS(FLOW CHART)

Start

Load address of data in DPTR

Get the two 8-bit data

Perform AND
Operation

Store the result of AND


operation in DPTR

Perform OR
Operation

Store the result of OR


operation in DPTR

Perform XOR
Operation

Store the result of XOR


operation in DPTR

Perform NOT
Operation

Store the result of NOT


operation in DPTR

Stop
Expt. No. 4 e)

LOGICAL OPERATIONS
AIM:
To write an assembly language program to perform logical operations of two 8-bit
numbers using 8051 Microcontroller.

APPARATUS REQUIRED:

1.8051 Microcontroller Kit.

2. Keyboard.

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


4100 MOV DPTR,#4500 MOVE THE ADDRESS OF DATA
TO DPTR
MOVX A,@DPTR MOVE THE DATA FROM
MEMORY TO A
MOV R0,A MOVE THE DATA FROM R0 TO
A
INC DPTR INCREMENT DPTR
MOVX A,@DPTR MOVE THE DATA FROM
MEMORY TO A
MOV R1,A MOVE THE DATA FROM R1 TO
A
ANL A, R0 PERFORM AND OPERATION
INC DPTR INCREMENT DPTR
MOVX A,@DPTR MOVE THE DATA FROM
MEMORY TO A
MOV A, R1 MOVE THE DATA FROM R1 TO
A
ORL A, R0 PERFORM OR OPERATION
INC DPTR INCREMENT DPTR
MOVX A,@DPTR MOVE THE DATA FROM
MEMORY TO A
MOV A, R1 MOVE THE DATA FROM R1 TO
A
XRL A, R0 PERFORM XOR OPERATION
INC DPTR INCREMENT DPTR
MOVX A,@DPTR MOVE THE DATA FROM
MEMORY TO A
MOV A, R0 MOVE THE DATA FROM R0 TO
A
CPL A TAKE 1’S COMPLEMENT
INC DPTR INCREMENT DPTR
MOVX A,@DPTR MOVE THE DATA FROM
MEMORY TO A
L1: SJMP L1 SHORT JUMP TO L1

INPUT OUTPUT

ADDRESS DATA
ADDRESS DATA
4500
4502
4501
4503
4504
4505

CALCULATION:
RESULT:
Thus the assembly language program to perform logical operations like (AND,OR,XOR,NOT)operations
using 8051 Microcontroller was executed successfully and output verified.
TWO’S COMPLEMENT OF A NUMBER(FLOWCHART)

Start

Load address of data in DPTR

Get the 8-bit data

Take one’s complement of a


number

Add one to take 2’s


complement

Store the result of two’s


complement result in
DPTR

Stop
Expt. No. 4 f)
TWO’S COMPLEMENT OF A NUMBER

AIM:
To write an assembly language program to find the 2’s complement
of an 8-bit number using 8051 Microcontroller.

APPARATUS REQUIRED:

1.8051 Microcontroller Kit.

2. Keyboard.

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


4100 MOV DPTR,#4500 MOVE THE ADDRESS OF DATA
TO DPTR
MOVX A,@DPTR MOVE THE DATA FROM
MEMORY TO A
CPL A TAKE ONE’S COMPLEMENT
OF A NO
INC A INCREMENT A TO TAKE 2’S
COMPLEMENT
INC DPTR INCREMENT DPTR
MOVX @DPTR,A MOVE THE DATA FROM A TO
MEMORY
L1: SJMP L1 SHORT JUMP TO L1
INPUT OUTPUT

ADDRESS DATA ADDRESS DATA


4500 4502

CALCULATION:

RESULT:
Thus the assembly language program to perform two’s complement of a number using 8051
microcontroller was executed successfully and output verified.
SQUARE OF A NUMBER(FLOW CHART)

Start

Load address of data in DPTR

Get the 8-bit data and


move to B register

Multiply two numbers to find


square of a no

Increment DPTR

Store the result of lower


byte in DPTR

Increment DPTR

Move the higher byte from B


register to A register

Store the result of higher


byte in DPTR

Stop
Expt. No. 4 g)

SQUARE OF A NUMBER
AIM:
To write an assembly language program to find the square of a given
8-bit number using 8051 Microcontroller.

APPARATUS REQUIRED:

1.8051 Microcontroller Kit.

2. Keyboard.

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


4100 MOV DPTR,#4500 MOVE THE ADDRESS OF
DATA TO DPTR
MOVX A,@DPTR MOVE THE DATA FROM
MEMORY TO A
MOV B,A MOVE THE DATA FROM A
TO B
MUL AB MULTIPLY THE DATA
FROM A AND B
INC DPTR INCREMENT DPTR
MOVX @DPTR,A MOVE THE DATA FROM A
TO MEMORY
MOV A,B MOVE THE DATA FROM B
TO A
INC DPTR INCREMENT DPTR
MOVX @DPTR,A MOVE THE DATA FROM A
TO MEMORY
L1: SJMP L1 SHORT JUMP TO L1
INPUT OUTPUT

ADDRESS DATA
ADDRESS DATA 4502
4500 4503

CALCULATION:

RESULT:
Thus the assembly language program to perform square of a number using 8051 microcontroller was
executed successfully and output verified.
Ex.No.5
INTRODUCTION TO ARDUINO PLATFORM AND PROGRAMMING

AIM :

To give an introduction to Arduino platform , learn the ports and program using Arduino IDE .

THEORY:

THEORY:
Arduino is an open-source prototyping platform in electronics based on easy-to-use hardware and
software. Arduino is a microcontroller based prototyping board which can be used in developing
digital devices that can read inputs like finger on a button, touch on a screen, light on a sensor
etc. and turning it in to output like switching on an LED, rotating a motor, playing songs through
a speaker etc.The Arduino board can be programmed to do anything by simply programming
the microcontroller on board using a set of instructions for which, the Arduino board consists of a
USB plug to communicate with your computer and a bunch of connection sockets that can be
wired to external devices like motors, LEDs etc.Arduino is based on open source electronics
project i.e. all the design specifications, schematics, software are available openly to all the users.
Hence, Arduino boards can bought from vendors as they are commercially available or else you
can make your own board by if you wish i.e. you can download the schematic from Arduino’s
official website, buy all the components as per the design specification, assemble all the
components, and make your own board.

Hardware and Software

Arduino boards are generally based on microcontrollers from Atmel Corporation like 8, 16 or 32
bit AVR architecture based microcontrollers.The important feature of the Arduino boards is the
standard connectors. Using these connectors, we can connect the Arduino board to other devices
like LEDs or add-on modules called Shields.The Arduino boards also consists of on board
voltage regulator and crystal oscillator. They also consist of USB to serial adapter using which
the Arduino board can be programmed using USB connection.In order to program the Arduino
board, we need to use IDE provided by Arduino. The Arduino IDE is based on Processing
programming language and supports C and C++.

Types of Arduino Boards

There are many types of Arduino boards available in the market but all the boards have one thing
in common: they can be programmed using the Arduino IDE. The reasons for different types of
boards are different power supply requirements, connectivity options, their applications
etc.Arduino boards are available in different sizes, form factors, different no. of I/O pins etc.
Some of the commonly known and frequently used Arduino boards are Arduino UNO, here are
many types of Arduino boards available in the market but all the boards have one thing in
common: they can be programmed using the Arduino IDE. The reasons for different types of
boards are different power supply requirements, connectivity options, their applications
etc.Arduino boards are available in different sizes, form factors, different no. of I/O pins etc.
Some of the commonly known and frequently used Arduino boards are Arduino UNO, Arduino
Mega, Arduino Nano, Arduino Micro and Arduino Lilypad.
Arduino Shields:

Shields are boards that can be plugged on top of the Arduino PCB extending its capabilities. The
different shields follow the same philosophy as the original toolkit: They are easy to mount and
cheap to produce.

🞂 Arduino Wi-Fi Shield - This is the Arduino Ethernet Shield sans wires.This
shield can get your Arduino connected to a WiFi router, so it can host
webpages and scour the Internet.
🞂 Cellular Shield w/ SM5100B - Turn your Arduino into a cellular
phone! Send SMS text messages, or hook up a microphone and
speaker and use it to replace your iPhone.
🞂 GPS Shield - GPS isn’t as complicated as you might think. With a GPS
Shield, your Arduino will always know where it is.

Arduino UNO

Arduino UNO is a basic and inexpensive Arduino board and is the most popular of all the
Arduino boards with a market share of over 50%. Arduino UNO is considered to be the best
prototyping board for beginners in electronics and coding. UNO is based on ATmega328P
microcontroller. There are two variants of the Arduino UNO: one which consists of through –
hole microcontroller connection and other with surface mount type. Through-hole model will be
beneficial as we can take the chip out in case of any problem and swap in with a new one.

Arduino UNO comes with different features and capabilities. The microcontroller used in UNO is
ATmega328P, which is an 8-bit microcontroller based on the AVR architecture.UNO has 14
digital input – output (I/O) pins which can be used as either input or output by connecting them
with different external devices and components. Out of these 14 pins, 6 pins are capable of
producing PWM signal. All the digital pins operate at 5V and can output a current of 20mA.

Some of the digital I/O pins have special functions which are describe below.

 Pins 0 and 1 are used for serial communication. They are used to receive and transmit
serial data which can be used in several ways like programming the Arduino board and
communicating with the user through serial monitor.
 Pins 2 and 3 are used for external interrupts. An external event can be triggered using
these pins by detecting low value, change in value or falling or rising edge on a signal.
 As mentioned earlier, 6 of the 14 digital I/O Pins i.e. 3, 5, 6, 9, 10, and 11 can provide 8-
bit PWM output.
 Pins 10, 11, 12 and 13 (SS, MOSI, MISO AND SCK respectively) are used for SPI
communication.
 Pin 13 has a built-in LED connected to it. When the pin is HIGH, the LED is turned on
and when the pin is LOW, it is turned off.

Arduino Uno has 6 analog input pins which can provide 10 bits of resolution i.e. 1024 different
values. The analog pins on the Arduino UNO are labelled A0 to A5.By default, all the analog
pins can measure from ground to 5V. Arduino UNO has a feature, where it is possible to change
the upper end of the range by using the AREF pin but the value should be less than 5V. There are
different ways in which we can power the Arduino UNO board. The USB cable, which is used to
program the microcontroller, can be used as a source of power.There is a power jack, using
which an external regulated power supply in the range of 7V – 12V can be supplied.
Additionally, the power can also be supplied from a battery through the VIN pin.The UNO board
has on-board voltage regulators for 5V and 3.3V, which can be used as power supply for small
external devices like LEDs.

The features of Arduino

o Arduino programming is a simplified version of C++, which makes the learning process
easy.
o The Arduino IDE is used to control the functions of boards. It further sends the set of
specifications to the microcontroller.
o Arduino does not need an extra board or piece to load new code.
o Arduino can read analog and digital input signals.
o The hardware and software platform is easy to use and implement.

Introduction to the Arduino Programming Language

Arduino, natively, supports a language that we call the Arduino Programming Language, or Arduino Language.
When we work with Arduino we commonly use the Arduino IDE (Integrated Development Environment), a
software available for all the major desktop platforms (macOS, Linux, Windows), which gives us 2 things: a
programming editor with integrated libraries support, and a way to easily compile and load our Arduino
programs to a board connected to the computer. The Arduino Programming Language is basically a framework
built on top of C++. A program written in the Arduino Programming Language is called sketch. A sketch is
normally saved with the .ino extension (from Arduino).

The main difference from “normal” C or C++ is that you wrap all your code into 2 main functions. You can
have more than 2, of course, but any Arduino program must provide at least those 2.

One is called setup( ), the other is called loop( ). The first is called once, when the program starts, the second is
repeatedly called while your program is running. Once you compile your sketch, the IDE will make sure the end
result is a correct C++ program and will basically add the missing glue by preprocessing it. art of the Arduino
Programming Language is the built-in libraries that allow you to easily integrate with the functionality provided
by the Arduino board.

Your first Arduino program will surely involve making a led turn on the light, and then turn off. To do so, you
will use the pinMode( ), delay( ) and digitalWrite( ) functions, along with some constants
like HIGH, LOW, OUTPUT.

The Arduino Programming Language Built-in constants

Arduino sets two constants we can use to HIGH equates to a high level of voltage, which can differ depending
on the hardware (>2V on 3.3V boards like Arduino Nano, >3V on 5V boards like Arduino Uno) LOW equates
to a low level of voltage. Again, the exact value depends on the board used

Then we have 3 constants we can use in combination with the pinMode( ) function:
 INPUT sets the pin as an input pin
 OUTPUT sets the pin as an output pin
 INPUT_PULLUP sets the pin as an internal pull-up resistor

The other constant we have is LED_BUILTIN, which points to the number of the on-board pin, which usually
equates to the number 13.

In addition to this, we have the C/C++ constants true and false.

Arduino Math Constants


 M_PI the constant pi (3.14159265358979323846)
 M_E the constant e
 M_LN10 the natural logarithm of the number 10.
 M_LN2 the natural logarithm of the number 2.
 M_LOG10E the logarithm of the e to base 10.
 M_LOG2E the logarithm of the e to base 2.
 M_SQRT2 the square root of 2.
 NAN the NAN (not a number) constant.

Program lifecycle
 setup( ) this function is called once, when the program starts, and when the Arduino is shut down and restarted.
 loop( ) this function is repeatedly called while the Arduino program is running.

Handling I/O
The following functions help with handling input and output from your Arduino device.

Digital I/O
 digitalRead( ) reads the value from a digital pin. Accepts a pin number as a parameter, and returns
the HIGH or LOW constant.
 digitalWrite( ) writes a HIGH or LOW value to a digital output pin. You pass the pin number
and HIGH or LOW as parameters.
 pinMode ( ) sets a pin to be an input, or an output. You pass the pin number and
the INPUT or OUTPUT value as parameters.
 pulseIn( ) reads a digital pulse from LOW to HIGH and then to LOW again, or from HIGH to LOW and
to HIGH again on a pin. The program will block until the pulse is detected. You specify the pin number and the
kind of pulse you want to detect (LHL or HLH). You can specify an optional timeout to stop waiting for that
pulse.
 pulseInLong( ) is same as pulseIn( ), except it is implemented differently and it can’t be used if interrupts are
turned off. Interrupts are commonly turned off to get a more accurate result.
 shiftIn( ) reads a byte of data one bit at a time from a pin.
 shiftOut( ) writes a byte of data one bit at a time to a pin.
 tone( ) sends a square wave on a pin, used for buzzers/speakers to play tones. You can specify the pin, and the
frequency. It works on both digital and analog pins.
 noTone( ) stops the tone( ) generated wave on a pin.

Analog I/O

 analogRead ( ) reads the value from an analog pin.


 analogReference( ) configures the value used for the top input range in the analog input, by default 5V in 5V
boards and 3.3V in 3.3V boards.
 analogWrite( ) writes an analog value to a pin
 analogReadResolution( ) lets you change the default analog bits resolution for analogRead(), by default 10
bits. Only works on specific devices (Arduino Due, Zero and MKR)
 analogWriteResolution( ) lets you change the default analog bits resolution for analogWrite(), by default 10
bits. Only works on specific devices (Arduino Due, Zero and MKR)

Time functions
 delay( ) pauses the program for a number of milliseconds specified as parameter
 delayMicroseconds( ) pauses the program for a number of microseconds specified as parameter
 micros( ) the number of microseconds since the start of the program. Resets after ~70 minutes due to overflow
 millis( ) the number of milliseconds since the start of the program. Resets after ~50 days due to overflow

Math functions
 abs( ) the absolute value of a number
 constrain( ) constrains a number to be within a range
 map( ) re-maps a number from one range to another
 max( ) the maximum of two numbers
 min( ) the minimum of two numbers
 pow( ) the value of a number raised to a power
 sq( ) the square of a number
 sqrt( ) the square root of a number
 cos( ) the cosine of an angle
 sin( ) the sine of an angle
 tan( ) the tangent of an angle

Working with alphanumeric characters


 isAlpha( ) checks if a char is alpha (a letter)
 isAlphaNumeric( ) checks if a char is alphanumeric (a letter or number)
 isAscii( ) checks if a char is an ASCII character
 isControl( ) checks if a char is a control character.
 isDigit( ) checks if a char is a number
 isGraph( ) checks if a char is a printable ASCII character, and contains content (it is not a space, for example)
 isHexadecimal Digit( ) checks if a char is an hexadecimal digit (A-F 0-9)
 isLowerCase( ) checks if a char is a letter in lower case
 isPrintable( ) checks if a char is a printable ASCII character
 isPunct( ) checks if a char is a punctuation (a comma, a semicolon, an exclamation mark etc)
 isSpace( ) checks if a char is a space, form feed \f, newline \n, carriage return \r, horizontal tab \t, or vertical
tab \v.
 isUpperCase ( ) checks if a char is a letter in upper case
 isWhitespace ( ) checks if a char is a space character or an horizontal tab \t

Random numbers generation


 random( ) generate a pseudo-random number
 randomSeed( ) initialize the pseudo-random number generator with an arbitrary initial number

Working with bits and bytes


 bit( ) computes the value of a bit (0 = 1, 1 = 2, 2 = 4, 3 = 8…)
 bitClear( ) clear (sets to 0) a bit of a numeric variable. Accepts a number, and the number of the bit starting from
the right
 bitRead( ) read a bit of a number. Accepts a number, and the number of the bit starting from the right
 bitSet( ) sets to 1 a bit of a number. Accepts a number, and the number of the bit starting from the right
 bitWrite( ) write 1 or 0 to a specific bit of a number Accepts a number, the number of the bit starting from the
right, and the value to write (0 or 1)
 highByte( ) get the high-order (leftmost) byte of a word variable (which has 2 bytes)
 lowByte( ) get the low-order (rightmost) byte of a word variable (which has 2 bytes)

Interrupts

 noInterrupts( ) disables interrupts


 interrupts( ) re-enables interrupts after they’ve been disabled
 attachInterrupt( ) allow a digital input pin to be an interrupt. Different boards have different allowed pins,
 detachInterrupt( ) disables an interrupt enabled using attachInterrupt( )

RESULT:
Thus the introduction of Arduino platform and programming was studied.
EX NO:5b Introduction to Arduino platform and programming
AIM:
To learn the ports and write a program to blink the builtin LED in the Arduino Uno board using
Arduino IDE.

APPARATUS REQUIRED:

S.No APPARATUS QUANTITY

1 ARDUINO UNO 1
BOARD
2 USB CABLE 1

PROCEDURE:
1.Connect the USB Cable from computer to Arduino USB port.
2. Go to device manager and view the Arduino Uno port COM.
3.Go to tools and then select Arduino Uno and Arduino COM port .
4. Click the Arduino IDE in the desktop to open.
5. Go to File and then to new Sketch.
6. Type the program and save.
7. Compile the program and check the error.If error occurs correct it.
8. Upload the program
9. See the output ON/OFF (builtin LED) in Arduino UNO board .

PROGRAM:
//Set up function runs once when you press reset or power the board.
Void setup( ) {
PinMode(LED_ BUILTIN,HIGH);
}
//The loop function runs over and over again forever
Void loop( ) {
digitalWrite(LED_BUILTIN,HIGH);
delay(1000);
digitalWrite(LED_BUILTIN,LOW);
delay(1000);
}
ALGORITHM:
1.Intialize digital pin LED_BUILDIN as an output.
2.Turn the LED on(High is the voltage level)
3.Wait for 1000 seconds.
4.Turn the LED off by making the voltage low.
5.Wait for 1000 seconds.

RESULT:
Thus the blink of builtin LED in the Arduino Uno board is performed using Arduino IDE platform.
EX NO:6 EXPLORE DIFFERENT COMMUNICATION METHODS
WITH IOT DEVICES(BLUETOOTH)
AIM:
To interface the bluetooth HC-05 terminal with arduino uno and switch ON/OFF LED
using the wireless communication protocol Bluetooth.

APPARATUS REQUIRED:

S.No APPARATUS RANGE QUANTITY


1 Arduino uno 1
board
2 LED - 1
3 Resistor 1k 1
4 USB cable 1
5 Bluetooth
module HC -05 1
6 Bread board - 1
7 Jumper Wires Male and As required
female
connector

PROCEDURE:
 .Connect the USB Cable from computer to Arduino USB port.
 Go to device manager and view the Arduino Uno port COM.
 Connect the VCC of Bluetooth module with +5v in Arduino Uno board using male
and female connector.
 Connect the GND pin of Bluetooth module with GND pin of Arduino Uno board
using male and female connector.
 Connect the TXD pin of Bluetooth module with RX(0th pin) of Arduino Uno board
using male and female connector.
 Connect the RXD pin of Bluetooth module with TX(1st pin ) of Arduino Uno Board
using male and female connector.
 .Download the HC-05 bluetooth app from playstore to your mobile phone.
 Click the Arduino IDE in the desktop to open it.
 Go to File and then to new Sketch.
 Type the program and save.
 Go to tools and then select Arduino Uno and Arduino COM port
 Compile the program and check the error.If error occurs correct it.
 Upload the program.
 If error occurs in uploading disconnect the TX and RX connection to the Arduino
Uno board and upload the program .After uploading connect the RX and TX pin in
the Arduino Uno board.
 Connect directly LED pin positive to 13th pin of Arduino Uno board and negative
of LED pin to ground of Arduino Uno board
(or)
 Fix the LED in bread board.Connect the positive of LED with a resistor of 1K ohms
and then connect from resistor to 13th pin of Arduino using male and female
connector.Connect the negative of LED to the GND pin of Arduino Uno board using
male and female connector.
 Pair the HC-05 of the arduino board with HC-05 app in your mobile phone.
 Go to terminal and give the command 1 the LED will be giow(ON).When we give
the command as 0 the LED will be OFF.

PIN CONFIGURATION OF HC-05 BLUETOOTH MODULE

PROGRAM:
char Incoming_value= 0;
Void setup( ) {
Serial.begin(9600);
pinMode(13,OUTPUT);
}
Void loop ( ) {
if ( Serial.available( ) > 0) {
Incoming_value=Serial.read( );
Serial.print(Incoming_value);
Serial.print(“/n”);
if(Incoming_value= =’1’)
digitalWrite(13,HIGH);
else if(Incoming_value= =’0’)
digitalWrite(13,LOW);
}
}

ALGORITHM:
1. 1.Declare a character as incoming value=0
2. 2.Open serial port and set the baud rate as 9600 bps.
3. 3.Set 13th pin as output.
4. Listen for the data.
5. Read the numbers from serial port.
6. Print out the received number.
7. Print a new line character.
8. If the incoming value is greater than zero the LED will be turned ON.
9. If the incoming Value is equal to zero the LED will be turned OFF

RESULT:
Thus the Bluetooth module is interfaced with Arduino Uno board and the LED is turned ON/OFF
using Bluetooth wireless communication protocol.
EX NO:7 Introduction of RashBerry PI platform and python Programming
AIM:
To give an introduction to Rashberry Pi connections and write a program using python in
rashberry pi.
APPARATUS REQUIRED:

S.No APPARATUS/ RANGE QUANTITY


COMPONENTS
1 Raspberry Pi 4 1
module,
2 LED - 1
3 resistor 1k 1
4 USB cable - 1
5 Mouse - 1
1
6 Keyboard -
7 Bread board - 1

PROCEDURE:
Connection procedure:
1. Connect the VGA cable of CPU to rashberrypi VGA connector.
2. Connect the rashberrypi VGA connector to HDMI cable and then connect a
connector and then connect a micro HDMI cable and connect to rashberry pi.
3. Connect the USB plug mouse and keyboard to rashberry pi.
4. Connect the charge cable(C type) to rashberry pi.
5. Take a bread board and fix a LED.Use the jumper pin and connect the positive of
LED to GPIO 14(8th pin) of rashberrypi and negative of LED to GND connection (6th
pin) of rashberry pi.
Procedure to run the program:
1. Click the rashberry pi symbol →programming→Thonny
2. Select new and type the program.
3. Go to File→save as→name.py(extension)
4. Click ok.
5. Run the program.
6. In the breadboard we can see LED ON for certain seconds and OFF for certain
seconds and so on.
Pin diagram of Rashberry pi:

PROGRAM:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(14,GPIO.OUT)
while True:

GPIO.output(14,True)
time.sleep(1)
GPIO.output(14,False)
time.sleep(1)

ALGORTHM:
1. Import rashberrypi general purpose Input/Output.
2. Import time for including delay.
3. Set BCM mode for setting the pin in rashberry pi.
4. Set the GPIO 14 as output.
5. Create while loop.
6. If GPIO 14 is true means LED will glow.
7. Give a time delay of one second.
8. If GPIO 14 is False means LED will not glow.
9. Give a time delay of one second.

RESULT:
Thus the Rashberry pi connection was given and a program was written in python
to turn LED ON/OFF and the output was executed successfully.
EX NO:8 INTERFACING SENSORS WITH RASPBERRY PI

AIM :

To interface IR sensor with Raspberry pi and write a program to switch on the LED
when IR Sensor detects an object.
APPARATUS REQUIRED:

S.No APPARATUS RANGE QUANTITY


1 Raspberry Pi 4 2
module
2 LED - 1
3 resistor 1k 1
4 USB cable - 1
5 Mouse - 1
1
6 Keyboard -
7 Bread board - 1

PROCEDURE:
Connection to rashberrypi:
1. Connect the VGA cable of CPU to rashperrypi VGA connector.
2. Connect the rashperrypi VGA connector to HDMI cable and then connect a
connector and then connect a micro HDMI cable and connect to rashperry pi.
3. Connect the USB plug mouse and keyboard to rashperrypi.
4. Connect the charge cable(C type) to rashperry pi.
5. Take a bread board and fix a LED.Use the jumper pin and connect the positive of
LED to GPIO 14(8th pin) of rashperrypi and negative of LED to GND connection (6 th
pin) of rashperry pi.
Connection to IR Sensor:
1. Connect Vcc of IR Sensor to the 2nd pin of rashberrypi(Vcc)
2. Connect the GND of IR sensor to 6th pin of rashberrypi.
3. Connect the output of IR Sensor with 16th pin of rashberrypi.
4. Fix the LED in the bread board.Positive of Led is connected with resistor.The resistor is
connected with to 18th pin in Rashberrypi.The negative of LED is connected to 9 th pin
of rashberrypi.
Programming Procedure:
1. Click the rashperry pi symbol →programming→Thonny
2. Select new and type the program.
3. Go to File→save as→name.py(extension)
4. Click ok.
5. Run the program.
6. If you show your hand or any object near IR Sensor then in the breadboard we can
see LED ON and if no object is detected means LED will be OFF .

PIN DIAGRAM OF IR SENSOR:

PROGRAM:
import RPi.GPIO as GPIO
import time

sensor=16
led=18

GPIO.setmode(GPIO.BOARD)
GPIO.setup(sensor,GPIO.IN)
GPIO.setup(led,GPIO.OUT)

GPIO.output(led,False)
print ("IR sensor ready")
print (" ")

try:
while True:

if GPIO.input(sensor):
GPIO.output(led,False)
print ("object is detected")
while GPIO.input(sensor):
time.sleep(0.2)
else:
GPIO.output(led,True)

except keyboardInterrupt:
GPIO.cleanup( )

ALGORITHM:
1. Import rashberry pi general purpose input/output.
2. Import time for time sleep.
3. Set sensor output as 16 and LED output as 18.
4. Set BOARD for setting the pin in rashberry pi.
5. Set GPIO such as IR Sensor output act as inputbto rashberry pi.
6. Set LED as output.
7. Assume if GPIO output is False object is detected.
8. Create while loop.
9. If object is detected LED will be ON.
10. If object is not detected LED will be OFF.
RESULT:
Thus the IR Sensor is interfaced with Rashberry pi and the LED was switched on when object
was detected.
EX NO:9 COMMUNICATE BETWEEN ARDUINO AND RASPBERRY
PI USING ANY WIRELLESS MEDIUM(BLUETOOTH)

AIM:
To Communicate between Arduino and raspberry pi using Bluetooth(HC-05) wireless
medium and write a program to switch ON/OFF LED.
APPARATUS REQUIRED:

S.No APPARATUS RANGE QUANTITY


1 Resistor 1k 1
2 USB cable - 1
- 1
3 1
Monitor

4 Keyboard -
5 Bread board - 1

6 Arduino Uno
board
7 Mouse 1
8 LED 1
9 Bluetooth HC-05 1
module

PROCEDURE:
Connection between Bluetooth module(HC-05) with Arduino Uno:
1. Connect the USB Cable from Arduino USB port to Rashberry pi .
2. Connect the VCC of Bluetooth module with +5v in Arduino Uno board
using male and female connector.
3. Connect the GND pin of Bluetooth module with GND pin of Arduino
Uno board using male and female connector.
4. Connect the TXD pin of Bluetooth module with RX(0 th pin) of Arduino
Uno board using male and female connector.
5. Connect the RXD pin of Bluetooth module with TX(1 st pin ) of Arduino
Uno Board using male and female connector.
6. Connect directly LED pin positive to 13th pin of Arduino Uno board and
negative of LED pin to ground of Arduino Uno board
7. Download the HC-05 bluetooth app from playstore to your mobile phone.
Connection to rashberry pi:
8. Connect the VGA cable of CPU to rashberrypi VGA connector.
9. Connect the rashberrypi VGA connector to HDMI cable and then
connect a connector and then connect a micro HDMI cable and connect
to rashberry pi.
10. Connect the USB plug mouse and keyboard to rashberry pi.
11. Connect the charge cable(C type) to rashberry pi.
PROGRAMMING PROCEDURE:
1. Open the terminal >- in the rashberry pi which is on the top of the screen.
2. Copy and paste the link which is given below
wget -qO- https://raw.githubusercontent.com/Botspot/pi-apps/master/install | bash
3.press enter.
(It will automatically install Piapps)
4.Go to menu→accessaries→piapps
5.Go to All apps→arduino→install
6.start or File→programming→arduino ide
7.Type the program.
8.Go to file and save as HC-05 (or) any name.
9.Go to tools → select arduino uno board.
10.Go to tools→port→select /devtyACMO(Arduino board)
9.Then disconnect the transmitter and receiver pin from Arduino and compile and
upload the program.
10 After uploading the program connect the transmitter and receiver pin to Arduino
Uno.
11.Open the terminal >-
Type as :sudo bluetoothctl
12.press enter
Agent registered(It will be shown in the monitor)
13.Type as: agent on
14.press enter
15.Type as : scan on
16.Press enter
(It will scan all the devices near by)
17.It will show the addresses of all Bluetooth devices nearby.copy the address of HC-05 and
paste it in a text file and save it.
(Press ctrl z and type as :clear)
18.In the terminal type as :sudo rfcomm - -help
19.press enter
20.Type as: sudo rfcomm bind 7 Copy the address of Hc-05 and paste it here
21.press enter
22.Switch to regular mode.
23.Click rashberry symbol→Programming→thonny
24.Type the program.
25.save as name.py(extension)
26.In your mobile open the app Bluetooth module(HC-05) and scan
27. Then go to bluetooth which is on the top of the screen.
28.Click add device
29.click HC-05
30.Click pair.
(It will ask for code)
31.Enter as 1234 and then click ok.
32.It will show paired successfully.click ok.
33.Click the ardino on the top of the screen.
34.Go to serial monitor and open it.
35.Run the program.
36.It will show enter:- (Type as)100.The LED will glow.
37.press enter
38. It will show enter:- (Type as)200.The Led will be OFF.
39.In the serial monitor you can see 100 and 200

(or)
The command can be given using mobile phone also.In Bluetooth module go to terminal and
give command as 100 Led will be ON. When we give the command as 200 the Led will be
OFF.
40.To release the connection go to terminal and type: sudo rfcomm release 7 Copy the
address of Hc-05 and paste it here

PROGRAM FOR ARDUINO WITH HC-05:


int led =13;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()){
int a=Serial.parseInt();
Serial.println(a);
if(a==100)
{digitalWrite(led,HIGH);
}
if(a==200)
{
digitalWrite(led,LOW);
}
}
}
PROGRAM FOR RASHBERRY PI:
import serial
import time

bluetooth=serial.Serial("/dev/rfcomm7",9600)

while True:
a=input("enter:-")
string='X{0}'.format(a)
bluetooth.write(string.encode("utf-8"))

ALGORITHM FOR ARDUINO PROGRAM:


1. Set the output for LED as 13.
2. Set the serial baud rate as 9600.
3. Set the pinmode Led as output.
4. Check serial data available.
5. Mention the variable ‘a’ as integer and send integer data .
6. It will show the data in the terminal and mention the variable as ‘a’.
7. If ‘a’ is equal to 100 then LED will glow.
8. If ‘a’ is equal to 200 then LED will be turned OFF.
ALGORITHM FOR RASHBERRY PROGRAM:
1. Import serial.
2. Import time.
3. Create variable for device and mention the device and baud rate.
4. Create while loop.
5. Create the input function.
6. Create the Variable.
7. Write the data.
RESULT:
Thus the Communication between Arduino and raspberry pi using Bluetooth(HC-05) wireless
medium was done and the LED was switched ON/OFF successfully.
EX NO:10 IoT BASED SYSTEM DESIGN
AIM:
Using Cloud app (BlynK) switch on a LED ON/OFF using internet(Wi-Fi).

APPARATUS REQUIRED:
S.NO APPARATUS/COMPONENTS QUANTITY
1 Bread board 1
2 LED 1
3 Resistor 1
4 NodeMcu(ESP8266) 1
5 Charge cable(B type) 1
6 Computer with internet 1
7 Arduino Uno board 1
8 Jumper pins As required
PROCEDURE:
 In www.google.com search Blynk IoT
 Click
Blynk: a low-code IoT software platform for businesses and
 No account for blynk means create account. If you have already login account means
log in using user name and password.
 Click start free.
 Click personal project
 Create new template.
Name:control Led, Hardware:ESP 8266,Connection type:Wi-Fi
 Click done.
 Click data streams,click new data stream,options→virtual pin
Name:Led 1,pin:V0,Data type:Integer,Colour:any colour you want
 Click create
 Click web dashboard
 Click widget box
 Drag one time switch
 Click switch
 Go to settings
 Datastream choose led1(V0)
ON value OFF value
0 1
Show on/off label→enable it
 Label position
 Right
 Save
 Click save (in the top)
 Devices→new devices
 From template
Template:control led
Device name:control led
 Click create
 When creating a new device you will receive a template which contains the
authentication token .Copy and paste in word and save it.
 Go Arduino ide and click open
 Type the program.After typing Paste the authentication token.Type your
user name and password of your Wi-Fi device.
 Connect the NodeMCu (ESP8266) to the Arduino using Charge cable(B
type).
 Go tools select the board as Ardino Uno.
 Download the NodeMcu(ESP8266Wi-Fi-master) driver and blynk library
from google and then go to C drive→program
file(x86)→Arduino→libraries→paste ESP8266Wi-Fi-Master and blynk
library.
 Go sketch include→Manage library
 In Search type as Blynk simple ESP8266.h.Two files will be shown.Install
any one(Net connection needed).
 Take a bread board and fix the Led.Connect the positive of Led to D0 of
NodeMcu.Connect the negative of Led to GND of NodeMcu.
 Open the blynk app in mobile phone and connect the Wi-Fi which you have
written as username and password.
 Before uploading the program go to Tools→Board→NodeMcu1.0(ESP 12E
module).Then upload the program
 Go to setting in mobile phone and select the switch button ON and OFF.
 Then using mobile switch ON and OFF the Led will glow on ON and Led
will be turned off when the switch is OFF.
Note:If already switches are selected in blynk in your account means directly you can go to
Arduino ide and proceed the remaining steps.
PROGRAM:
//Include the library files
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

//Define the Led1 pin


#define light1 D1
#define BLYNK_AUTH_TOKEN "GWoY7E4cw8jSaBaRi08L9WhflaDds0hP" //Enter your
blynk auth token

char auth[] = BLYNK_AUTH_TOKEN;


char ssid[] = "1234";//Enter your WIFI name
char pass[] = "12345678";//Enter your WIFI password

//Get the button values


BLYNK_WRITE(V0) {
bool value1 = param.asInt();
// Check these values and turn the Led1 ON and OFF
if (value1 == 1) {
digitalWrite(light1, LOW);
} else {
digitalWrite(light1, HIGH);
}
}

void setup() {
Serial.begin(9600);
delay(100);
//Set the Led pin as output pin
pinMode(light1, OUTPUT);

// Turn OFF the Led


digitalWrite(light1, HIGH);

//Initialize the Blynk library


Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
}

void loop() {
//Run the Blynk library
Blynk.run();
}

ALGORITHM:
1. Include the library files.
2. Define the Led pin.
3. Define the blynk authentication token.
4. Enter your Wi-Fi name.
5. Enter your Wi-Fi password.
6. Get the button Values.
7. Check the button values and turn the Led On/OFF.
8. If value 1 is equal to one then Led will be OFF.
9. If Value 1 is Zero then Led will glow.
10. Set the baud rate.
11. Give the delay as 100 seconds.
12. Set the Led pin as output pin.
13. Turn off the Led.
14. Initialize the blynk library.
15. Run the blynk library.
RESULT:
Thus using the cloud app blynk the Led light 1 was switched ON/OFF using internet(Wi-Fi)
successfully.
EX NO:11 SET A CLOUD PLATFORM TO LOG ON DATA USING ARDUINO

AIM:
To set a Arduino cloud platform to log on data.

APPARATUS REQUIRED:
S.NO APPARATUS/COMPONENTS QUANTITY

1 Jumper Wires As required


2 PC with Internet 1
3 Node Mcu (ESP8266) 1
4 DHT 11 sensor 1
5 B-type Cable 1

PIN DIAGRAM OF DHT11:

PIN DIAGRAM OF NODEMCU ESP8266


Procedure:
1.Connect the VCC of DHT11 with 3.3v of NODEMCU .
2.Connect the GND of DHT11 with GND of NODEMCU.
3. Connect the output pin of DHT11 with D4 of NODEMCU.
4.Use the B-type cable and connect the Node Mcu with CPU of the Computer.
5.Go to www.google .com and go to the site Arduino IoT cloud.
6.If you don’t have signin account Sign up and create an account.If you already have an
account sign in with that account.
7.Go to Things→create things
8.Add variable →enter the name as temperature →add the variable type as temperature(eg.C
or F)→add variable.
9.add→enter the name as humidity→add the variable type as relative humidity(eg1%)→add
variable
10.Add→enter the name as Message→add the variable type as character
string(eg”hello”)→add variable.
11.Device→set up a third party device→select device
type→ESP8266→NODEMCU1.0(12E)→Continue.
12.Give your device a name:(eg.Apple)→next
13.You will get a device ID and Secret key.Download the pdf and save it.
14.Give a tick on I saved the device ID and secrek key→Continue.
15.Then click done.
16.Go to network credentials and click on configure button.
17.Enter your Wi-Fi name and Password and also enter your secret key →save
18.Go to dashboard →Build dashboard
19.Give the name (untitled) as Temperature and Humidity Monitoring and click
add→widget→gauge→give the name as temperature→ click link variable
button→ClickTemperature→Done→(untitled) Temperature and Humidity Monitor.
20.Go to dashboard and click the dashboard(Temperature and Humidity Monitoring)and then
click the edit button→edit settings→(link the variable)→Temperature→Click linkvariable
→Done
21. add→widget→gauge→give the name as Humidity→ click link variable button→Click
Humidity →Done.
22.Add→widget→chart→give the name as Temperature→Click Link variable button→click
Temperature→link variable→Done.
23. .Add→widget→chart→give the name as Humidity→Click Link variable button→click
Humidity→click link variable→Done.
24.Add→Widget→Messenger→give the name as Message→ Click Link variable
button→click Message→click link variable→Done
25.Go to Things and click (Temperature and Humidity Monitoring).
26.Click on Sketch→Then click on Open full editor
27.Click Learn more→Click install the agent→Click start→Click download for
WIN64→Click This PC→C drive→show in a folder→Double click(all his MSA) to install
Arduino agent→next→click I accept the agreement→next→(do you intend to use Arduino
agent with a browser other than google chrome or Mozilla firebox)→NO→next→finish
28.After installing the Arduino agent →→Click next→Click Go to web editor→Type the
program→Compile and save.
29.Select the board as Node Mcu(1.0)ESP826612E and Arduino port and upload the
program.
30.To see the output go to dashboard and click(Temperature and Humidity monitoring).We
can see the temperature and humidity readings in the gauge and chart.The readings vary
based on the room temperature.Also we can see the temperature and humidity reading
messages.

Program:
#include "arduino_secrets.h"
CloudRelativeHumidity humidity;
String msg;
CloudTemperatureSensor temperature;

#include "thingProperties.h"
#include "DHT.h"
#define DHTpin 2 // D4 on the nodemcu ESP8266
#define DHTTYPE DHT11
DHT dht(DHTpin,DHTTYPE);

void setup( ) {
Serial.begin(9600);
delay(1500);
initProperties( );
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo( );
}
void loop() {
ArduinoCloud.update( );
float hm= dht.readHumidity( );
Serial.print("Humidity ");
Serial.println(hm);
float temp=dht.readTemperature();
Serial.print("Temperature ");
Serial.println(temp);
humidity=hm;
temperature=temp;
message="Temperature = " + String (temperature)+" Humidity = " + String(humidity);

}
void onHumidityChange( ) {
}
void onMsgChange( ) {
}

void dht_sensor_getdata( )
{
float hm= dht.readHumidity( );
Serial.print("Humidity ");
Serial.println(hm);
float temp=dht.readTemperature( );
Serial.print("Temperature ");
Serial.println(temp);
humidity=hm;
temperature=temp;
message="Temperature = " + String (temperature)+" Humidity = " + String(humidity);
}

ALGORITHM:
1.Include Sketch generated by the Arduino IoT Cloud Thing "Temperature and Humidity
monitoring”.
2 The following variables are automatically generated and updated when changes are made to
the Thing

CloudRelativeHumidity humidity;
String msg;
CloudTemperatureSensor temperature;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard. These functions are
generated with the Thing and added at the end of this sketch.
3.Include sensor.
4.Define DHT outputpin and NodeMCu output pin.
5.Define DHT type.
6. Initialize serial and wait for port to open(This delay gives the chance to wait for a Serial
Monitor without blocking if none is found)
7. Defined in thingProperties.h
8. Connect to Arduino IoT Cloud.
9.The function allows to obtain more information related to the state of network and IoT
Cloud connection.
10.Type the code.
11. Add the code here to act upon Humidity change.
12.Since Humidity is READ_WRITE variable, onHumidityChange( ) is
executed every time a new value is received from IoT Cloud.
13. Add the code here to act upon Message change.

RESULT:
Thus the datas are logged using Arduino IoT cloud successfully.

You might also like