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

Embedded Lab Manual

The document provides an introduction to the 8051 microcontroller, detailing its architecture, features, and various applications. It explains the differences between microcontrollers and microprocessors, highlighting the advantages of using microcontrollers for compact and cost-effective designs. Additionally, it includes practical experiments demonstrating arithmetic operations using the 8051 microcontroller, complete with algorithms and sample programs.

Uploaded by

9922008379
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Embedded Lab Manual

The document provides an introduction to the 8051 microcontroller, detailing its architecture, features, and various applications. It explains the differences between microcontrollers and microprocessors, highlighting the advantages of using microcontrollers for compact and cost-effective designs. Additionally, it includes practical experiments demonstrating arithmetic operations using the 8051 microcontroller, complete with algorithms and sample programs.

Uploaded by

9922008379
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 72

Introduction about 8051 Microcontroller

A Microcontroller consists of a powerful CPU tightly coupled with memory (RAM, ROM or
EPROM), various I/O features such as Serial port(s), Parallel port(s), Timer/Counter(s),
Interrupt Controller, Data Acquisition Interfaces - Analog to Digital Converter(ADC), Digital
to Analog Converter(DAC), everything integrated onto a single Silicon chip.

It does not mean that any microcontroller should have all the above said features on chip.
Depending on the need and area of application for which it is designed, the on chip features
present in it may or may not include all the individual sections said above.

Any microcomputer system requires memory to store a sequence of instructions making up a


program, parallel port or serial port for communicating with an external system, timer/counter
for control purposes like generating time delays, baud rate for the serial port, apart from the
controlling unit called the Central Processing Unit.

If a system is developed with a microprocessor, the designer has to go for external memory
such as RAM, ROM or EPROM and peripherals and hence the size of the PCB (Printed
Circuit Board) will be large enough to hold all the required peripherals. But, the
microcontroller has got all these peripheral facilities on a single chip. So, development of a
similar system with a microcontroller reduces PCB size and cost of the design.

One of the major differences between a microcontroller and a microprocessor is that a


controller often deals with bits, not bytes as in the real world applications. For example,
switch contacts can only be open or close, indicators should be lit or dark and motors can be
either turned on or off and so forth.

INTEL MCS-51 FAMILY

Intel has introduced a family of Microcontrollers called the MCS-51. This family comprises
the 8031, 8051, 8052, 8751 and 8752 Microcontrollers. Our trainer kit supports all these
microcontrollers. 8051, an 8-bit Single chip Microcontroller has got a powerful CPU
optimised for control applications, 64K Program Memory address space, 64K Data Memory
address space, 4K bytes of on-chip ROM (Read Only Memory), 128 bytes of on-chip RAM
(Read/Write Memory), Four 8-bit bidirectional Parallel ports, one full-duplex (it can transmit
and receive simultaneously) Serial port, two 16-bit timer/counters and an extensive interrupt
structure. 8031 is the ROM less version of 8051 whereas 8751 is the EPROM version of
8051. This is the main difference between 8031, 8051 and 8751. Since we have not used the

1
On-chip ROM or EPROM in Micro-51, Micro-51 EB and Micropower-i based 8031/51 Piggy
board, any of these three Microcontrollers can be used. For individual line and control
applications, 8051 is best suited as it incorporates a special set of instruction which are
capable of bit addressing the onchip I/O features of 8051.

The Major Features of 8051 Are:

* 8-bit CPU optimised for control applications.

* Extensive Boolean processing (single-bit logic) capabilities.

* 64K Program Memory address space.

* 64K Data Memory address space.

* 4K bytes of on-chip Program Memory (in 8051 and 8751 only).

* 128 bytes of on-chip Data RAM.

* 32 bi-directional and individually addressable I/O lines.

* Two 16-bit Timer / Counters.

* Full Duplex UART (Universal Asynchronous Receiver / Transmitter).

* 6-source / 5-vector interrupt structure with two priority levels.

* On-chip Oscillator and Clock circuitry.

APPLICATIONS OF MICROCONTROLLERS

Microcontrollers are designed for use in sophisticated real-time applications such as


industrial control, instrumentation and intelligent computer peripherals. Microcontrollers with
ADC finds usage in data acquisition systems and closed-loop analog controllers. It permits
considerable system integration by combining analog and digital I/O processing in the single
chip. They are used in industrial applications to control Motor, Robotics, discrete and
continuous process control, in missile guidance and control, in medical instrumentation,
oscilloscopes, Telecommunications, Automobiles, for scanning a keyboard, driving an LCD
(Liquid Crystal Display), for frequency measurements, period measurements, pulse width
measurements and so on.

2
THE 8051 MICROCONTROLLER ARCHITECTURE

The architecture of the 8051 family of microcontrollers is referred to as the MCS-51


architecture (Micro Controller Series-51), or sometimes simply as MCS-51. The
microcontrollers have an 8- bit data bus. They are capable of addressing 64K of program
memory and a separate 64K of data memory. The block diagram of 8051 microcontroller is
shown below.

The 8051 have 4K of code memory implemented as on-chip Read Only Memory (ROM). The
8051 have 128 bytes of internal Random Access Memory (RAM). The 8051 has two
timer/counters, a serial port, 4 general purpose parallel input/output ports, and interrupt
control logic with five sources of interrupts. Besides internal RAM, the 8051 have various
Special Function Registers (SFR), which are the control and data registers for on-chip
facilities. The SFRs also include the accumulator, the B register, and the Program Status
Word (PSW), which contains the CPU flags. Programming the various internal hardware
facilities of the 8051 is achieved by placing the appropriate control words into the
corresponding SFRs. The 8031 are similar to the 8051, except it lacks the on-chip ROM.

3
VARIOUS 8051 MICROCONTROLLERS

The 8051 is available in different memory types, such as UV-EPROM, flash, and NV-RAM,
all of which have different part numbers. The UV-EPROM version of the 8051 is the 8751.
Many companies including Philips, Atmel, Analog Devices & Cygnal manufactures the flash
ROM version. The Atmel flash 8051 is called AT89C51 & the Analog Devices version is
ADuC812. The NV-RAM version of the 8051 made by Dallas semiconductor is called
DS5000. There is also the OTP (One time programmable) version of the 8051 made by
various manufacturers. All these versions of 8051 (MCS-51 series) are called as ‘8051
Derivatives’. MCS 51 Series of Microcontrollers are

INTEL – 805X, 803X, 875X, 835X, 8X152, 8X251

ATMEL – 835X, 875X, 895X, T8X251, AT205X

PHILIPS – 805X, 835X, 875X, 895X

CYGNAL – 8051FXXX TI – MSC121X

ANALOG DEVICES – ADuC812, 814, 816, 824, 831, 834, 844,848

PIN DESCRIPTION OF THE 8051

Although 8051 family members (e.g. 8751, 89C51) come in different packages, such as DIP
(dual in-line package), QFP (quad flat package), and LLC (Leadless chip carrier), they all
have 40 pins that are dedicated for various function such as I/O, RD, WR, address, data and
interrupts. It must be noted that some companies provide a less pin version of the 8051 with a
reduced number of I/O ports for less demanding applications & user flexibility. ATMEL
892051 is the 20 pin 8051 derivative IC with less digital I/O lines & reduced flash memory
compared to its 40 pin AT89C51 series. However, since the vast majority of developers use
the 40-pin DIP package chip. And now RISC versions of 8051 ICs are also available with
ATMEL & they called it as AVR microcontrollers & available size from 8-pin package.
Examining the following figure, note that of the 40 pins a total of 32 pins are set aside for the
four ports P0, P1, P2 and P3, where each ports takes 8 pins. The rest of the pins are
designated as Vcc, GND, XTAL1, XTAL2, RST, EA, ALE, and PSEN. Of these 8 pins, all
members of the 8051 and 8031 families use six of them. In other words, they must be
connected in order for the system to work, regardless of whether the microcontroller is of the

4
8051 or 8031 family. The other two pins PSEN- and ALE are used mainly in 8031 based
systems.

1–8: Port 1: Each of these pins can be used as either input or output according to your needs.
Also, pins 1 and 2 (P1.0 and P1.1) have special functions associated with Timer 2.

9: Reset Signal: High logical state on this input halts the MCU and clears all the registers.
Bringing this pin back to logical state zero starts the program a new as if the power had just
been turned on. In another words, positive voltage impulse on this pin resets the MCU.
Depending on the device's purpose and environs, this pin is usually connected to the push-
button, reset-upon-start circuit or a brown out reset circuit.

10-17: Port 3:as with Port 1, each of these pins can be used as universal input or output.
However, each pin of Port 3 has an alternative function:

Pin 10: RXD - serial input for asynchronous communication or serial output for synchronous
communication.

5
Pin 11: TXD - serial output for asynchronous communication or clock output for synchronous
communication

Pin 12: INT0 - input for interrupt 0

Pin 13: INT1 - input for interrupt 1

Pin 14: T0 - clock input of counter 0

Pin 15: T1 - clock input of counter 1

Pin 16: WR - signal for writing to external (add-on) RAM memory.

Pin 17: RD - signal for reading from external RAM memory

18-19: X2 and X1: Input and output of internal oscillator. Quartz crystal controlling the
frequency commonly connects to these pins. Capacitances within the oscillator mechanism
optimal voltage

20: GND: Ground

21- 28: Port 2: if external memory is not present, pins of Port 2 act as universal input/output.
If external memory is present, this is the location of the higher address byte, i.e. addresses A8
– A15. It is important to note that in cases when not all the 8 bits are used for addressing the
memory (i.e. memory is smaller than 64kB), the rest of the unused bits are not available as
input/output.

29: PSEN: MCU activates this bit (brings to low state) upon each reading of byte instruction)
from program memory. If external ROM is used for storing the program, PSEN- is directly
connected to its control pins.

30: ALE: before each reading of the external memory, MCU sends the lower byte of the
address register (addresses A0 – A7) to port P0 and activates the output ALE. External Chip
(eg: 74HC373), memorizes the state of port P0 upon receiving a signal from ALE pin, and
uses it as part of the address for memory chip. During the second part of the MCU cycle,
signal on ALE is off, and port P0 is used as Data Bus. In this way, by adding only one
integrated circuit, data from port can be multiplexed and the port simultaneously used for
transferring both addresses and data.

31: EA: Bringing this pin to the logical state zero designates the ports P2 and P3 for
transferring addresses regardless of the presence of the internal memory. This means that

6
even if there is a program loaded in the MCU it will not be executed, but the one from the
external ROM will be used instead. Conversely, bringing the pin to the high logical state
causes the controller to use both memories, first the internal, and then the external (if
present).

32-39: Port 0: Similar to Port 2, pins of Port 0 can be used as universal input/output, if
external memory is not used. If external memory is used, P0 behaves as address output (A0 –
A7) when ALE pin is at high logical level, or as data output (Data Bus) when ALE pin is at
low logical level.

40: VCC: Power +5V

7
Experiment No 1 Date:

ARITHMETIC OPERATIONS IN 8051

1A. ADDITION OF TWO 8 BIT NUMBERS USING 8051 MICROCONTROLLER

Aim:

To perform addition of two 8 bit data using immediate addressing mode and
store the result in memory.

Apparatus Required:

1)8051 Microcontroller

2)Keyboard

Algorithm:

1. Start the Program

2. Load accumulator A with any desired 8-bit data.

3. Add any desired 8 bit data with accumulator data.

4. Initialize the memory location and store the result in memory.

5. Stop the program.

8
Program:

MOV A, #15H

ADD A, #10H

MOV DPTR, #4500

MOVX @DPTR,A

HERE: SJMP HERE

9
Flowchart:

10
Assessment for Experiment

Aim and Algorithm(10)

Program (10)

Output (20)

Viva (10)

Total (50)

Result:

Thus the program to add two 8 bit numbers using 8051 microcontroller was
written and executed successfully.

11
1B. SUBTRACTION OF TWO 8 BIT NUMBERS USING 8051 MICROCONTROLLER

Aim:

To perform subtraction of two 8 bit data using immediate addressing mode and
store the result in memory.

Apparatus Required:

1)8051 Microcontroller

2)Keyboard

Algorithm:

1. Start the Program

2. Clear the carry flag.

3. Initialize the register for borrow.

4. Get the first operand into the accumulator.

5. Subtract the second operand from the accumulator.

6. If a borrow results, increment the carry register.

7. Initialize the memory location and store the result in memory.

8. Stop the Program.

12
Program:

CLR C

MOV A,#DATA1

SUBB A,#DATA2

MOV DPTR,#4500

MOVX @DPTR,A

HERE: SJMP HERE

13
Flowchart:

14
Assessment for Experiment

Aim and Algorithm(10)

Program (10)

Output (20)

Viva (10)

Total (50)

Result:

Thus the program to subtract two 8 bit numbers using 8051 microcontroller
was written and executed successfully.

15
1C. MULTIPLICATION OF TWO 8 BIT NUMBERS USING 8051 MICROCONTROLLER

Aim:

To perform multiplication of two 8 bit data using immediate addressing mode


and store the result in memory.

Apparatus Required:

1)8051 Microcontroller

2)Keyboard

Algorithm:

1. Start the Program.

2. Get the multiplier in the accumulator.

3. Get the multiplicand in the B register.

4. Multiply A with B.

5. Initialize the memory location and store the lower order byte in memory.

6. Go to next memory Location and store the higher order byte.

7. Stop the Program.

16
Program:

MOV A, #DATA1

MOV B, #DATA2

MUL AB

MOV DPTR, #4500

MOVX @DPTR, A

INC DPTR

MOV A,B

MOVX @DPTR,A

HERE: SJMP HERE

17
Flowchart:

18
Assessment for Experiment

Aim and Algorithm(10)

Program (10)

Output (20)

Viva (10)

Total (50)

Result:

Thus the program to multiply two 8 bit numbers using 8051 microcontroller
was written and executed successfully.

19
1D. DIVISION OF TWO 8 BIT NUMBERS USING 8051 MICROCONTROLLER

Aim:

To perform division of two 8 bit data using immediate addressing mode and
store the result in memory.

Apparatus Required:

1)8051 Microcontroller

2)Keyboard

Algorithm:

1. Start the Program.

2. Get the Dividend in the accumulator.

3. Get the Divisor in the B register.

4. Divide A by B.

5. Initialize the memory location and store the remainder in memory.

6. Go to next memory Location and store the quotient.

7. Stop the Program.

20
Program:

MOV A, #DATA1

MOV B, #DATA2

DIV AB

MOV DPTR, #4500

MOVX @DPTR, A

INC DPTR

MOV A,B

MOVX @DPTR,A

HERE: SJMP HERE

21
Flowchart:

22
Assessment for Experiment

Aim and Algorithm(10)

Program (10)

Output (20)

Viva (10)

Total (50)

Result:

Thus the program to divide two 8 bit numbers using 8051 microcontroller was
written and executed successfully.

23
Experiment No 2 Date:

SUM OF N ELEMENTS IN AN ARRAY USING 8051 MICROCONTROLLER

Aim:

To add N numbers of an 8 bit array and store the result in memory.

Apparatus Required:

1)8051 Microcontroller

2)Keyboard

Algorithm:

1.Start the Program.

2.Load the array in the consecutive memory location and initialize the memory pointer

with the starting address.

3.Load the total number of elements in a separate register as a counter.

4.Clear the Accumulator.

5.Load the other register with the value of the memory pointer.

6.Add the register with the accumulator.

7.Check for carry, if exist, increment the carry register by 1, otherwise continue.

8.Decrement the counter, if it reaches 0, stop. Otherwise, increment the memory

pointer by 1and go to step 4.

9.Stop the Program.

24
Program:

MOV DPTR, #4200

MOVX A, @DPTR

MOV R0, A

MOV B, #00

MOV R1, B

ADD: CLR C

INC DPTR

MOVX A, @DPTR

ADD A, B

MOV B, A

JNC NC

INC R1

NC: DJ NZ R0,ADD

MOV DPTR, #4500

MOV A, R1

MOVX @DPTR, A

INC DPTR

MOV A, B

MOVX @DPTR, A

HLT: SJMP HLT

25
Flowchart:

26
Assessment for Experiment

Aim and Algorithm (10)

Program (10)

Output (20)

Viva (10)

Total (50)

Result:

Thus the program to add N numbers of an 8 bit array using 8051


microcontroller was written and executed successfully.

27
Experiment No 3 Date:

ONE’S AND TWO’S COMPLEMENT USING 8051 MICROCONTROLLER

Aim:

To obtain the one's and two's complement of an 8-bit number using 8051
Microcontroller.

Apparatus Required:

1)8051 Microcontroller

2)Keyboard

Algorithm:

1.Start the program.

2.Load the data into A (accumulator).

3.Complement the content of Accumulator.

4.Initialize the memory location and store the content of accumulator in it.

5.Add 01 to accumulator content.

6.Store the content of accumulator in next memory location.

7.Stop the program.

28
Program:

MOV A, #DATA

CPL A

MOV DPTR, #4200

MOVX @DPTR, A

INC A

INC DPTR

MOVX @DPTR,A

HERE: SJMP HERE

29
Flowchart:

30
Assessment for Experiment

Aim and Algorithm(10)

Program (10)

Output (20)

Viva (10)

Total (50)

Result:

Thus an assembly language program to obtain the one's and two's complement
of an 8-bit number was written and output was verified successfully using 8051
Microcontroller.

31
Experiment No 4 Date:

LARGEST ELEMENT IN AN ARRAY USING 8051 MICROCONTROLLER

Aim:

To write an assembly language program to find the largest element in an array


using 8051.

Apparatus Required:

1)8051 Microcontroller

2)Keyboard

Algorithm:

1.Start the Program.

2.Load internal memory location with number zero.

3.Load array count in a register.

4. Compare the first number with internal memory location. If it is greater, move it to internal

memory location.

5. Further comparison is with this number and this comparison is done till the end of the

array.

6. Now the biggest number in internal memory location is stored in memory as the result.

7.Stop the Program.

32
Program:

MOV DPTR, #4200

MOV 40H, #00

MOV R5, #0A

LOOP2: MOVX A, @DPTR

CJNE A,40H, LOOP1

LOOP3: INC DPTR

DJNZ R5, LOOP2

MOV A,40H

MOVX @DPTR, A

HLT: SJMP HLT

LOOP1: JC LOOP3

MOV 40H, A

SJMP LOOP3

33
Flowchart:

34
Assessment for Experiment

Aim and Algorithm(10)

Program (10)

Output (20)

Viva (10)

Total (50)

Result:

Thus an assembly language program to find the largest element in an array was
written and was successfully executed using 8051 microcontroller.

35
Experiment No 5 Date:

SMALLEST ELEMENT IN AN ARRAY USING 8051 MICROCONTROLLER

Aim:

To write an assembly language program to find the smallest element in an array


using 8051.

Apparatus Required:

1)8051 Microcontroller

2)Keyboard

Algorithm:

1.Start the Program.

2.Load internal memory location with number FF.

3.Load array count in a register.

4. Compare the first number with internal memory location. If it is lesser, move it to internal

memory location.

5. Further comparison is with this number and this comparison is done till the end of the

array.

6. Now the biggest number in internal memory location is stored in memory as the result.

7.Stop the Program.

36
Program:

MOV DPTR,#4200

MOV 40H,#FF

MOV R5,#0A

LOOP2 MOVX A,@DPTR

CJNE A,40H, LOOP1

LOOP3 INC DPTR

DJNZ R5, LOOP2

MOV A,40H

MOVX @DPTR, A

HLT: SJMP HLT

LOOP1: JNC LOOP3

MOV 40H,A

SJMP LOOP3

37
Flowchart:

38
Assessment for Experiment

Aim and Algorithm(10)

Program (10)

Output (20)

Viva (10)

Total (50)

Result:

Thus an assembly language program to find the smallest element in an array


was written and was successfully executed using 8051 microcontroller.

39
Experiment No 6 Date:

ASCENDING ORDER OF AN ARRAY USING 8051 MICROCONTROLLER

Aim:

To arrange an array of 8-bit numbers of known length in ascending order using


8051 Microcontroller.

Apparatus Required:

1)8051 Microcontroller

2)Keyboard

Algorithm:

1. Start the Program.

2. First consider the first two numbers of the array. See if this pair of numbers is out of

order.

3. Similarly examine successively each pair of numbers in the array.

4. If any pair is out of order, interchange the numbers in the pair.

5. Perform this step for count times, count being one less than array length.

40
Program:

MOV R3,#4

MOV R4,#4

MOV DPTR,#4500

REPT1: MOV R5,DPL

MOV R6, DPH

MOVX A, @DPTR

MOV B, A

REPT: INC DPTR

MOVX A, @DPTR

MOV R0, A

CLR C

SUBB A, B

JNC CHKNXT

EXCH: PUSH DPL

PUSH DPH

MOV DPL,R5

MOV DPH, R6

MOV A, R0

MOVX @DPTR, A

POP DPH

POP DPL

MOV A, B

41
MOVX @DPTR, A

MOV B, R0

CHKNXT: DJNZ R3, REPT

DEC R4

MOV A, R4

MOV R3, A

INC R4

MOV DPL, R5

MOV DPH, R6

INC DPTR

DJNZ R4, REPT1

HLT: SJMP HLT

42
Flowchart:

43
Assessment for Experiment

Aim and Algorithm(10)

Program (10)

Output (20)

Viva (10)

Total (50)

Result:

Thus the assembly language program to arrange an array of 8-bit numbers of


known length in ascending order was written and output was verified successfully
using 8051 Microcontroller.

44
Experiment No 7 Date:

DESCENDING ORDER OF AN ARRAY USING 8051 MICROCONTROLLER

Aim:

To arrange an array of 8-bit numbers of known length in descending order


using 8051 Microcontroller.

Apparatus Required:

1)8051 Microcontroller

2)Keyboard

Algorithm:

1. Start the Program.

2. First consider the first two numbers of the array. See if this pair of numbers is out of

order.

3. Similarly examine successively each pair of numbers in the array.

4. If any pair is out of order, interchange the numbers in the pair.

5. Perform this step for count times, count being one less than array length.

45
Program:

MOV R3, #4

MOV R4, #4

MOV DPTR, #4500

REPT1: MOV R5,DPL

MOV R6, DPH

MOVX A, @DPTR

MOV B, A

REPT: INC DPTR

MOVX A, @DPTR

MOV R0, A

CLR C

SUBB A, B

JC CHKNXT

EXCH: PUSH DPL

PUSH DPH

MOV DPL, R5

MOV DPH, R6

MOV A, R0

MOVX @DPTR, A

POP DPH

POP DPL

MOV A, B

46
MOVX @DPTR, A

MOV B, R0

CHKNXT: DJNZ R3,REPT

DEC R4

MOV A, R4

MOV R3, A

INC R4

MOV DPL, R5

MOV DPH, R6

INC DPTR

DJNZ R4, REPT1

HLT: SJMP HLT

47
Flowchart:

48
Assessment for Experiment

Aim and Algorithm(10)

Program (10)

Output (20)

Viva (10)

Total (50)

Result:

Thus the assembly language program to arrange an array of 8-bit numbers of


known length in descending order was written and output was verified successfully
using 8051 Microcontroller.

49
Introduction about Arduino UNO

Is an open source platform consist of both a physical programmable circuit board


(microcontroller) and a piece of software or IDE (Integrated Development
Environment).

Microcontroller-Is a small and low-cost microcomputer, which is designed to perform


the specific tasks of embedded systems.General microcontroller consists of the
processor, the memory (RAM, ROM, EPROM), Serial Ports, Peripherals (timers,
counters), etc.

Types of Microcontrollers

Microcontrollers are divided into various categories based on memory, bits and
instruction sets.Based on Bit, three microcontrollers are there,

 8-bit Microcontroller − Used to execute arithmetic and logical operations.

 16-bit Microcontroller −Used to perform arithmetic and logical operations


where higher accuracy and performance is required.

 32-bit Microcontroller −Used in automatically controlled appliances like


automatic operational machines, medical appliances, etc.

Based on Memory,two types are there,

• External Memory Microcontroller − Do not have a program memory on the


chip.

• Embedded Memory Microcontroller − Has all programs and data memory,


counters and timers, interrupts, I/O ports are embedded on the chip.

Based on Instruction Set, two types are there,

• CISC − Contains a large set of computer instructions that range from very
simple to very complex.

50
• RISC − Is designed to perform a smaller number of types of computer
instructions.

Integrated Development Environment

• Is an environment mainly used to write code and upload computer code to the
physical device.Arduino IDE uses a simplified version of C++

Types of Arduino Board

1)ATMEGA 328 Microcontroller (ARDUINO UNO)

1) Processor-16Mhz
2) Memory-2 Kb SRAM and 32Kb Flash Memory
3) Digital I/O-14
4) Analog I/O-6
2)ATMEGA 32U4 Microcontroller(ARDUINO LEONARDO)

1) Processor-16Mhz

2) Memory-2.5 Kb SRAM and 32Kb Flash Memory

3)Digital I/O-20
4)Analog I/O-12
3)ATMEGA 2560 Microcontroller(ARDUINO MEGA)

1)Processor-16Mhz

2)Memory-8 Kb SRAM and 256 Kb Flash Memory

3)Digital I/O-54
4)Analog I/O-16 Input and 0 Output
4)AT91sam3X8E Microcontroller(ARDUINO DUE)

1)Processor-84 Mhz

2)Memory-96 Kb SRAM and 512 Kb Flash Memory

3)Digital I/O-54
4)Analog I/O-16 Input and 2 Output

51
Arduino Board Details

1-Power USB

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

2-Power (Barrel Jack)

Arduino boards can be powered directly from the AC mains power supply by
connecting it to the Barrel Jack.

3-Voltage Regulator

The function of the voltage regulator is to control the voltage given to the
Arduino board and stabilize the DC voltages used by the processor and other
elements.There are two types of voltage regulators

Fixed voltage regulator

Adjustable voltage regulator

52
A fixed voltage regulator produces a fixed DC output voltage, which is either
positive or negative.An adjustable voltage regulator produces a DC output
voltage, which can be adjusted to any other value of certain voltage range.
Hence, adjustable voltage regulator is also called as a variable voltage
regulator.

4-Crystal Oscillator

Crystal Oscillator is an electronics Oscillator circuit which generates an


electrical signal with an accurate frequency.The number printed on top of the
Arduino crystal is 16.000H9H. It tells us that the frequency is 16,000,000 Hertz
or 16 MHz.

5,17-Arduino Reset

You can reset our Arduino board, (i.e., start our program from the beginning)

in two ways.

1) First, by using the reset button (17) on the board.

2) Second, you can connect an external reset button to the Arduino pin labelled
RESET (5)

6,7,8,9-3.3v,5v,GND,Vin

3.3V (6) − Supply 3.3 output volt

5V (7) − Supply 5 output volt

Most of the components used with Arduino board works fine with 3.3 volt and
5 volt.

GND (8)(Ground) − There are several GND pins on the Arduino, any of which
can be used to ground your circuit.

Vin (9) − This pin also can be used to power the Arduino board from an
external power source, like AC mains power supply.

53
10-Analog Pins

The Arduino UNO board has six analog input pins A0 through A5. These pins
can read the signal from an analog sensor and convert it into a digital value that
can be read by the microprocessor.

11-Main Microcontroller

Is the brain of your board.The microcontrollers are usually of the ATMEL


Company.

12-ICSP Pin

Is a form of programming in which microcontroller is programmed serially.Is a


tiny programming header for the arduino consist of six pins

1)MOSI(Master Out Slave In)-Supply output data from slave to the input of

the master

2)MISO(Master In Slave out)- Supply output data from master to the input of

the slave

3)SCK(Serial Clock)-is the line that carries clock signal

4)RESET

5)VCC

6)GND

13-Power LED Indicator

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

14-TX and RX LED’s

Appear in two places on the Arduino UNO board. First, at the digital pins 0 and
1, to indicate the pins responsible for serial communication.

Second, the TX and RX led (13). The TX led flashes with different speed
while sending the serial data. RX flashes during the receiving process.

15-Digital I/O

The Arduino UNO board has 14 digital I/O pins (of which 6 provide PWM
(Pulse Width Modulation) output. The pins labeled “~” can be used to generate
PWM.These pins can be configured to work as input digital pins to read logic
values(0 or 1) or as digital output pins to drive different modules like
LED’s,Relay etc.

16-AREF

Used to set an external reference voltage (between 0 and 5 Volts) as the upper
limit for the analog input pins.

55
Tutorial on Arduino IDE Software

The Arduino IDE is the interface where you will write the program that tell the board
what to do. You can find the latest version of this software on the link:
https://www.arduino.cc/en/software

To install the software, you will need to click on the link that corresponds with your
computer’s operating system. Once the software has been installed on your computer,
go ahead, and open it up. This is the Arduino IDE and is the place where all the
programming will happen.

56
1. Menu Bar: Gives you access to the tools needed for creating and saving
Arduino sketches.

2. Verify Button: Compiles your code and checks for errors in spelling or

syntax.

3. Upload Button: Sends the code to the board that’s connected such as
Arduino

UNO in this case. Lights on the board will blink rapidly when uploading.

4. New Sketch: Opens a new window containing a blank sketch.

5. Sketch Name: When the sketch is saved, the name of the sketch is displayed

here.

6. Open Existing Sketch: Allows you to open a saved sketch or one from the
stored examples.

7. Save Sketch: This saves the sketch you currently have open.

8. Serial Monitor: When the board is connected, this will display the serial

information of your Arduino.

57
9. Code Area: This area is where you compose the code of the sketch that tells

the board what to do.

10.Message Area: This area tells you about the status on saving, code
compiling,

errors and more.

11.Text Console: Shows the details of an error messages, size of the program

that was compiled and additional info.

12.Board and Serial Port: Tells you what board is being used and what serial

port it’s connected to.

At this point you are ready to connect your Arduino to your computer. Plug one end of
the USB cable to the Arduino Uno and then the other end of the USB to your
computer’s USB port. Once the board is connected, you will need to go to Tools then
Board then finally select Arduino Uno.

Next, you have to tell the Arduino which port you are using on your computer. To
select the port, go to Tools then Port then select the port that says Arduino.

58
Introduction about Tinkercad

TinkerCad offers many benefits:

1- Online: No need to install any Software or Application on PC / Mobile.

2- OpenSoure: Free, no license needed, for everyone.

3- Simulator: They offer a good interface for designing and simulating projects.

Creating an Account: Go to the website, https://www.tinkercad.com

59
On the top right corner, SIGN IN option is there. Click it. You can SIGN IN with your
klu mail ID.

Click on Circuits to switch from 3D Designs to “Circuits” mode, and then click on
Create new Circuit.

On the right side of the screen, the components are available. These components
include basics electronic components, Microcontrollers and their Interfacing Sensors
and Devices. Drag and drop the components of interest to the Main Window.

After the Connections are made, click the Code Option on the top menu bar. This is to
be done if you are having a Microcontroller in your circuit.

60
After completion of the above step, Click the Start Simulation option available beside
it. If there are no errors in the circuit and / or Program, the output can be visible on the
screen. If the output is on the Serial Monitor of Arduino, you need to click the “Serial
Monitor” option available below the Code option.

61
Experiment No 8 Date:

INTERFACING TRAFFIC LIGHT CONTROLLER WITH ARDUINO

Aim:

To build a circuit using Arduino UNO through which a traffic light is turned ON and
OFF automatically.

Apparatus Required:

1.Seven Segment Display

2.Arduino UNO

3.Resistors

4.Jumping Wires

Program:

void setup()
{
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
}

void loop()
{
for (int i = 0 ; i < 10 ; i +=1)
{
digitalWrite(11,HIGH);
delay(100);
digitalWrite(11,LOW);
delay(100);
}
digitalWrite(11,HIGH);

62
delay(5000);
digitalWrite(11,LOW);
delay(1000);
digitalWrite(12,HIGH);
delay(1000);
digitalWrite(12,LOW);
delay(1000);
digitalWrite(13,HIGH);
delay(5000);
digitalWrite(13,LOW);
delay(1000);

Circuit Diagram:

63
Connections:

1. Login to TinkerCAD.com using your klu mail id.


2. After logging in, go to the domain Design in TinkerCAD and create a New Project.
3. All the components will be available on the right side of the window.
4. Pick, place and connect the components as per the diagram.
5. Connect red, blue and green pin to the Arduino pin 13,12 and 11 respectively.
6. Connect the cathode pin to ground.
7. After the connections are made, click the Start Simulation button.

64
Assessment for Experiment

Aim and Algorithm(10)

Program (10)

Output (20)

Viva (10)

Total (50)

Result:

Thus, with the help of knowledge of traffic light control, circuits have been
constructed and implemented successfully.

65
Experiment No 9 Date:

INTERFACING TEMPERATURE SENSOR WITH ARDUINO

Aim:

To build a circuit that use the temperature sensor to detect the temperature value
continuously using Arduino and Tinkercad Software Tool.

Apparatus Required:

1.Arduino UNO

2)Temperature Sensor(TMP36)

3)Jumping Wires

Program:

#define analogPin A0

#define aref_voltage 3.3

void setup()
{
Serial.begin(9600);

analogReference(EXTERNAL);
}

void loop() {

int sensorRead = analogRead(analogPin);

float voltageOut = sensorRead * (aref_voltage / 1024.0);

float tempInC = (voltageOut - 0.5) * 100;

Serial.print("Temperature: ");
Serial.print(tempInC);
Serial.print("\xB0");
Serial.print("C");
Serial.print("\n");
66
delay(2000);
}

Circuit Diagram:

Connections:

1. Login to TinkerCAD.com using your klu mail id.


2. After logging in, go to the domain Design in TinkerCAD and create a New Project.
3. All the components will be available on the right side of the window.
4. Pick, place and connect the components as per the diagram.

5. The red wire is connected from 5V power from Arduino to TMP36’s power(Vs+).

6. The black wire is connected from TMP36’s Vout to Arduino’s A0(Analog) pin.

7. Green wire is connected from the ground(GND) of Arduino to the ground of the
TMP36 sensor.

8. The yellow wire is connected from the 3.3V of Arduino to the reference
voltage(AREF) pin in Arduino.
9. After the connections are made, click the Start Simulation button.

67
Assessment for Experiment

Aim and Algorithm(10)

Program (10)

Output (20)

Viva (10)

Total (50)

Result:

Thus, with the help of knowledge of working of a temperature sensor in


Arduino, circuits have been constructed and implemented successfully.

68
Experiment No 10 Date:

INTERFACING ULTRASONIC SENSOR WITH ARDUINO

Aim:

To build a circuit that use the ultrasonic sensor to detect the distance between
sensor and object continuously using Arduino and Tinkercad Software Tool.

Apparatus Required:

1)Arduino UNO

2)Ultrasonic Sensor

3)Jumper Wires

Program:

#define echoPin \
#define trigPin \
long duration;
int distance;
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
Serial.println("Distance measurement using Arduino Uno.");
delay(500);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite( trigPin,HIGH);
delayMicroseconds(10);

69
digitalWrite(trigPin,LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration * 0.0344 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(100);
}

Circuit Diagram:

70
Connections:

1. Login to TinkerCAD.com using your klu mail id.


2. After logging in, go to the domain Design in TinkerCAD and create a New
Project.
3. All the components will be available on the right side of the window.
4. Pick, place and connect the components as per the diagram.
5. Connect the Echo pin of the sensor to the D2 pin of the Arduino.
6. Connect the Trig pin of the sensor to the D3 pin of the Arduino.
7. Navigate to Tools and select board and port.
8. Verify and compile the code, then upload the code to the Arduino Uno R3
board.
9. After the connections are made, click the Start Simulation button.
10. Monitor the output in the Serial monitor (Set the baud rate as 9600). To open
Serial monitor Tools>Serial Monitor or (Ctrl+Shift+M).

71
Assessment for Experiment

Aim and Algorithm(10)

Program (10)

Output (20)

Viva (10)

Total (50)

Result:

Thus, with the help of knowledge of working of a ultrasonic sensor in Arduino,


circuits have been constructed and implemented successfully.

72

You might also like