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

New - Lab Manual Microprocessor and Microcontroller Manual 2019

The document outlines 12 experiments using 8086 microprocessor and 8051 microcontroller to perform arithmetic operations, code conversions, and interface with devices like LCD, sensors, and motors. It includes programs for addition, subtraction, multiplication, and division using different addressing modes on 8-bit and 16-bit numbers on both the 8086 kit and emulator. Students are evaluated based on their ability to conduct the experiments and viva questions.

Uploaded by

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

New - Lab Manual Microprocessor and Microcontroller Manual 2019

The document outlines 12 experiments using 8086 microprocessor and 8051 microcontroller to perform arithmetic operations, code conversions, and interface with devices like LCD, sensors, and motors. It includes programs for addition, subtraction, multiplication, and division using different addressing modes on 8-bit and 16-bit numbers on both the 8086 kit and emulator. Students are evaluated based on their ability to conduct the experiments and viva questions.

Uploaded by

Suhas Hegde
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Microprocessors and Microcontrollers

Laboratory
B.Tech. IV Semester

Name :
Roll Number :
Department : Electronics and Communication Engineering

Faculty of Engineering & Technology


Ramaiah University of Applied Sciences
Ramaiah University of Applied Sciences
Private University Established in Karnataka State by Act No. 15 of 2013

Faculty Engineering & Technology


Department B. Tech. in ECE
Year/Semester 2018/4th Semester
Course Title Microprocessors and Microcontrollers Laboratory
Course Code 19ECL217A
List of Experiments

1. Write a program using 8086 microprocessor to perform arithmetic operations on 8 bit and
16 bit numbers using EMU 8086 software (addition, subtraction, multiplication and
division)
2. Write a program using 8086 microprocessor to perform arithmetic operations on 8 bit and
16 bit numbers using kit(addition, subtraction, multiplication and division)
3. Write a program for code conversion-Binary to Gray & Gray to Binary using 8086
microprocessor
4. Write a program for sorting a list of numbers in ascending & descending order using 8086
microprocessor
5. Write a program using 8051 microcontroller to perform arithmetic operations on 8 bit and
16 bit numbers using software (addition, subtraction, multiplication and division)
6. Write a program using 8051 microcontroller to perform arithmetic operations on 8 bit and
16 bit numbers using kit (addition, subtraction, multiplication and division)
7. Write programs for Code conversions using 8051 microcontroller (decimal to hexadecimal
and vice versa)
8. Write 8051 microcontroller programming using Timer0 to create a 10KHz square wave
9. Implement LED blinking and fading using Arduino board
10. Interface LCD with Arduino board to display message
11. Interface IR and ultrasonic sensor with Arduino board
12. Design a stepper motor and servo motor controller
Index Sheet
Name: Semester /Year:
Registration No: Staff In-charge:
Course: Microprocessors and Microcontrollers Laboratory
Experiment VIVA Total
Sl.
Name of the Experiment/Exercise Conduction
No. (10) (20)
(10)
8086 microprocessor to perform arithmetic
1 operations on 8 bit and 16 bit numbers using
EMU 8086 software
8086 microprocessor to perform arithmetic
2
operations on 8 bit and 16 bit numbers using kit
Code conversion: Binary to Gray & Gray to
3
Binary using 8086 microprocessor
Sorting a list of numbers in ascending &
4
descending order using 8086 microprocessor
8051 microcontroller to perform arithmetic
5 operations on 8 bit and 16 bit numbers using
software
8051 microcontroller to perform arithmetic
6
operations on 8 bit and 16 bit numbers using kit
Code conversions: Decimal to hexadecimal and
7
vice versa using uC
8 Create a 10KHz square wave using Timer0
Implement LED blinking and fading using
9
Arduino board
Interface LCD with Arduino board to display
10
message
Interface IR and ultrasonic sensor with Arduino
11
board
Design a stepper motor controller and traffic
12
light controller
13 Internal Test

Component 1 = Lab Internal Marks = ( ) × 𝟐𝟓 =


𝟐𝟔𝟎

Signature of the Staff In-charge


Introduction of 8086 microprocessor kit and emulator
Instruction: - An instruction is a binary pattern designed inside a microprocessor to perform a specific
function
Opcode: - It stands for operational code. It specifies the type of operation to be performed by CPU. It
is the first field in the machine language instruction format.

E.g. 08 is the opcode for instruction “MOV X, Y”

Operand: - We can also say it as data on which operation should act. Operands may be register values
or memory values. The CPU executes the instructions using information present in this field. It may be
8-bit data or 16-bit data

Assembler: - it converts the instruction into sequence of binary bits, so that this bits can be read by
the processor

Mnemonics: - these are the symbolic codes for either instructions or commands to perform a
particular function

E.g. MOV, ADD, SUB etc.

Architecture of 8086 microprocessor

The main features of the 8086 core are:

 Microprocessor 8086 is a 16-bit processor with 20 bit address bus, which can access up to
220memory locations (1 MB). Address ranges from 00000H to FFFFFH
 Memory is byte addressable - Every byte has a separate address
 It can support up to 64K I/O ports and provides 14, 16 -bit registers
 It is a 40 pin Dual Inline Package (DIP) Integrated Circuit (IC), that supports multiplexed address
and data bus AD0- AD15 and A16 – A19 to reduce the number of pins used in IC
 8086 is designed to operate in two modes, Minimum and Maximum
 It can prefetch up to 6 instruction bytes from memory and queues them in order to speed up
instruction execution (pipelining)
 It requires +5V power supply

8086 Pin Diagram

Microprocessor 8086 kit

Procedure to Communicate with 8086 microprocessor kit

 Connect the Power Supply


 Connect Keyboard to keyboard connector
 Switch on the Power Supply press Reset button
 Make sure LCD display unit Shows the Program Commanding
 Start to Assemble the Codes using Keyboard
Steps to Execute the Assembly Programs
• Following steps explains the program execution flow in 8086 trainer board kit
 A  Enter (Assembler mode)
 SG 0  Enter (segment register clear or loaded with 0)
 LC  Enter (Label Clear)---optional step
 DA Address  Enter( Disassemble, assemble / data address starting address)
 Type the Assembly Language Program(ALP)
 Press N @ INT 3  Enter
 Press N @!  Enter
 EX  Enter (Exit From DA Mode)
 Press GO a * symbol appears on display and then enter the address location from where the
program needs to start (ex:- 4000 H)
 Press R to exam the register, E to exam the byte, w to exam the word

Introduction to 8086 Emulator


• Emu8086 is an emulator or software tool to realize programs in 8086 (Intel and AMD
compatible) microprocessor that has an integrated assembler
• The emulator runs programs and emulates a microprocessor in step-by-step mode
• Registers, memory, stack, variables and flags can be viewed using the emulator

Steps to write program in emu8086


 Click on New
 Select COM template and click OK
 A new window will appears as shown
 Type the program and save
 Save the file
 Click on compile
 A new window appears click OK
 Click on RELOAD
 Click single step and verify the results or click on RUN to check final result
Laboratory 1
8086 Microprocessor to Perform Arithmetic Operations on 8 bit
and 16 bit Numbers Using EMU 8086 Software
To use various 8086 addressing modes and simple arithmetic operations

Aim

To develop assembly language program in 8086 mnemonics for performing arithmetic


operation on two 8-bit or 16-bit numbers using immediate, register and direct and indirect
addressing mode

Software: EMU 8086

Program
a. Addition

Immediate Register Direct Indirect


Addressing Mode Addressing Mode Addressing Mode Addressing Mode

b. Subtraction

Immediate Register Direct Indirect


Addressing Mode Addressing Mode Addressing Mode Addressing Mode
c. Multiplication

Immediate Register Direct Indirect


Addressing Mode Addressing Mode Addressing Mode Addressing Mode

d. Division

Immediate Register Direct Indirect


Addressing Mode Addressing Mode Addressing Mode Addressing Mode

3. Presentation of Results

4. Conclusions
Laboratory 2
8086 Microprocessor to Perform Arithmetic Operations on 8 bit
and 16 bit Numbers Using Kit
i. AIM: Arithmetic Operations (Addition, Subtraction, Multiplication and division) of two 8-bit
numbers using immediate addressing mode.

APPARATUS: 8086 Trainer kit.

Table 1: Addition Program


Offset Opcode Mnemonic Comment
Address
3+

2000 B0 05 Mov AL,05 Data 05 is stored in reg AL

2002 B3 04 Mov BL,04 Data 04 is stored in reg BL

2004 02 C3 Add AL,BL Data of AL and BL are added


and stored in AL

2006 CC Int 3 Stop

Result:

Table 2: Subtraction Program


Offset Opcode Mnemonic comment
Address

2000 B0 05 Mov AL,05 Data 05 is stored in reg AL

2002 B3 04 Mov BL,04 Data 04 is stored in reg BL

2004 2B C3 Sub AL,BL Data of BL is subtracted from


AL and stored in AL

2006 CC Int 03 Stop

Result:
Table 3: Multiplication Program
Offset Opcode Mnemonic comment
Address

2000 B0 05 Mov AL,05 Data 05 is stored in reg AL

2002 B3 04 Mov BL,04 Data 04 is stored in reg BL

2004 F7 E3 Mul BL Data of AL and BL are


multiplied and RESULT is
stored in AL

2006 CC Int 03 Stop

Result:

Table 3: Division Program


Offset Opcode Mnemonic comment
Address

2000 B0 05 Mov AL,05 Data 05 is stored in reg AL

2002 B3 04 Mov BL,04 Data 04 is stored in reg BL

2004 F6 F3 Div BL Data of AL is divided by BL


and RESULT stored in AL

2006 CC Int 03 Stop

RESULT: AL: ______ Remainder


AH: ______ Quotient

ii. AIM: Arithmetic Operations (Addition, Subtraction, Multiplication and division) of two 16-
bit numbers using direct addressing mode.

APPARATUS: 8086 Trainer kit.


Table 5: Addition Program
Offset Opcode Mnemonic Comment
Address
2000 8B060017 Mov Move contents of 1700
AX,[1700] in reg AX

2004 8B1E0217 Mov Move contents of 1702


BX,[1702] in reg BX

2008 01D8 Add AX,BX Data of AX and BX are


added and RESULT
stored in AX

200A CC Int 03 Stop

RESULT: AX=

Input:-
Location Data
1700 88
1701 00
1702 44
1703 00

Table 5: Subtraction Program


Offset Opcode Mnemonic Comment
Address
2000 8B 06 00 Mov Move contents of 1700
17 AX,[1700] in reg AX

2004 8B 1E 02 Mov Move contents of 1702


17 BX,[1702] in reg BX
2008 29 D8 Sub AX,BX Data of BX is subtracted
from AX and RESULT
stored in AX

200A CC Int 03 Stop

RESULT: AX=

Input:-
Location Data Output:
1700 88
1701 00
1702 44
1703 00

iii. AIM: Arithmetic Operations (Addition and Subtraction) of two 8- bit numbers using indirect
addressing mode.

APPARATUS: 8086 Trainer kit.

Table 6: Addition Program

Offset Opcode Mnemonic Comment


Address
2000 BE0017 Mov SI,1700 Move Data from 2000
to SI

2003 8A04 Mov AL,[SI] Move contents of SI to


reg AL

2005 46 Inc SI Incrementing SI

2006 8A1C Mov BL,[SI] Moving data from SI to


BL

2008 02C3 Add AL,BL Adding data of AL and


BL
200A 89060018 Mov [1800],AL Move contents of AL to
1800

200E CC Int 03 Stop

RESULT :
Input:-
Location Data

1700 04
1701 04

Output: - 1800 08

Table 7: Subtraction Program

Offset Address Opcode Mnemonic Comment


2000 BE0017 Mov SI,1700 Move Data from 2000 to SI

2003 8A04 Mov AL,[SI] Move contents of SI to reg AL


2005 46 Inc SI Incrementing SI
2006 8A1C Mov BL,[SI] Moving data from SI to BL
2008 2BC3 Sub AL,BL Subtract data of BL from data of AL
200A 89060018 Mov [1800],AL Move contents of AL to 1800
200E CC Int 03 Stop

RESULT:

Input:-
Location Data
1700 09
1701 04

Output:-
1800 05
Laboratory 3
Code Conversion-Binary to Gray & Gray to Binary using 8086
Microprocessor
1. Aim
To develop assembly language program in 8086 mnemonics using nested loops for code
conversion
2. Program

Binary to Gray
MOV AX, 2314H; MOVE THE BINARY DATA (11001011) INTO THE REGISTER AX
MOV BX, AX; MOVE DATA IN AX TO BX
SHR BX, 01; SHIFT THE DAT IN BX TO RIGHT BY 1 BIT
XOR AX, BX; PERFORM XOR OPERATION ON AX AND BX

Gray to Binary
MOV AL, 1110B;
MOV BL, AL;
SHR BL, 1;
XOR BL, AL;
SHR BL, 1;
XOR BL, AL;
SHR BL, 1;
XOR BL, AL;
MOV AL, BL;

3. Presentation of Results

4. Conclusions
Laboratory 4
Sorting a List of Numbers in Ascending & Descending Order Using 8086
Microprocessor
Aim

To develop assembly language program in 8086 mnemonics for sorting the numbers in
ascending & descending order

1. Program

Ascending Order
MOV SI, 4000H;
MOV BX, 03H;
MOV CX, 03H;
L1: MOV AX, [SI];
CMP AX, [SI+2];
JC GO;
XCHG AX, [SI+2];
XCHG AX, [SI];
GO: INC SI;
INC SI;
DEC CX;
JNZ L1;
MOV CX, 03H;
MOV SI, 4000H;
DEC BX;
JNZ L1;
Descending Order

MOV SI, 4000H;


MOV BX, 03H;
MOV CX, 03H;
L1: MOV AX, [SI];
CMP AX, [SI+2];
JNC GO;
XCHG AX, [SI+2];
XCHG AX, [SI];
GO: INC SI;
INC SI;
DEC CX;
JNZ L1;
MOV CX, 03H;
MOV SI, 4000H;
DEC BX;
JNZ L1;

2. Presentation of Results

3. Conclusions
Introduction of 8051 microcontroller kit and emulator
MCS 8051 is an 8-bit single chip microcontroller with many built-in functions and is the core for
all MCS-51 devices

The main features of the 8051 core are:

 Operates with single Power Supply +5V


 8-bit CPU optimized for control applications
 16-bit program counter (PC) and 16-bit data pointer (DPTR)
 8-bit program status word (PSW)
 8-bit stack pointer (SP)
 4K Bytes of On-Chip Program Memory (Internal ROM or EPROM)
 128 bytes of On-Chip Data Memory (Internal RAM):
o Four Register Banks, each containing 8 registers (R0 to R7) (Total 32 registers)
o 16 bytes of bit addressable memory
o 80 bytes of general-purpose data memory (Scratch Pad Area)
 Special Function Registers (SFR) to configure/operate microcontroller
 32 bit bi-directional I/O Lines (4 ports P0 to P3)
 Two 16-bit timers/counters (T0 and T1)
 Full duplex UART (Universal Asynchronous Receiver/Transmitter)
 5-vector interrupts (2 external and 3 internal) with two priority levels
 On-Chip oscillator and clock circuitry
8051 Pin Diagram

P1.0 1 40 Vcc
P1.1 2 39 P0.0(AD0
P1.2 3 38 )P0.1(AD1)
P1.3 4 37 P0.2(AD2
P1.4 5 8051 36 P0.3(AD3)
)
P1.5 6 35 P0.4(AD4)
P1.6 7 34 P0.5(AD5)
P1.7 8 33 P0.6(AD6)
RST 9 32 P0.7(AD7)
(RXD)P3.0 10 31 EA/VPP
(TXD)P3.1 11 30 ALE/PROG
(INT0)P3.2 12 29 PSEN
(INT1)P3.3 13 28 P2.7(A15)
(T0)P3.4 14 27 P2.6(A14
(T1)P3.5 15 26 )P2.5(A13
(WR)P3.6 16 25 P2.4(A12
)
(RD)P3.7 17 24 )P2.3(A11
XTAL2 18 23 P2.2(A10)
)
XTAL1 19 22 P2.1(A9)
GND 20 21 P2.0(A8)

Program Status Word

Program status word (PSW) at address DOH contains status bits as summarized in the following table
Keil Software Demostration:

Create New Project

Select Target Device


https://www.instructables.com/id/8051-Programming-Using-Keil-UVision-IDE/
Laboratory 5
8051 Microcontroller to Perform Arithmetic Operations on 8 bit and 16
bit Numbers using Keil u-Vision 4
Aim
To develop assembly language program in 8051 mnemonics for performing arithmetic
operation on two 8-bit or 16-bit numbers using immediate, register and direct addressing
mode

2. Program
a. Addition

b. Subtraction

c. Multiplication

d. Division
3. Results

4. Conclusions
Laboratory 6
8051 Microcontroller to Perform Arithmetic Operations on 8 bit
and 16 bit Numbers Using Kit
1. Aim

Aim

To develop assembly language program in 8051 mnemonics for performing arithmetic


operation on two 8-bit or 16-bit numbers using immediate, register and direct and indirect
addressing mode

2. Program
a. Addition

b. Subtraction

c. Multiplication
d. Division

3. Results

4. Conclusions
Laboratory 7
Code Conversion Programs in 8051
1. Aim
To develop assembly language program for code conversion in 8051
2. Program
Hexadecimal to Decimal

MOV A, 30H;
MOV B, #64H;
DIV AB;
MOV 41H, A;
MOV A, B;
MOV B, #0AH;
DIV AB;
SWAP A;
ADD A, B;
MOV 40H, A;

Decimal to Hexadecimal

MOV A, 30H;
ANL A, #0FH;
MOV R0, A;
MOV A, 30H;
ANL A, #0F0H;
SWAP A;
MOV B, #0AH
MUL AB;
ADD A, R0;
MOV 40H, A;
3. Results

4. Conclusions
Laboratory 8
Generation of 10 KHz Square Wave Using Timer in Microcontroller 8051
1. Aim
To generate 10 KHz Square Wave using 8051
2. Calculations

3. Program

MOV TMOD, #10H;


AGAIN: MOV TL1, #1AH;
MOV TH1, #0FFH;
SETB TR1;
BACK: JNB TF1, BACK;
CLR TR1;
CPL P1.3;
CLR TF1;
SJMP AGAIN

4. Presentation of Results

5. Conclusions
Arduino Introduction
Arduino is a prototype platform (open-source) based on an easy-to-use hardware and
software. It consists of a circuit board, which can be programed (referred to as a
microcontroller) and a ready-made software called Arduino IDE (Integrated Development
Environment), which is used to write and upload the computer code to the physical board.
The key features are:

 Arduino boards are able to read analog or digital input signals from different sensors
and turn it into an output such as activating a motor, turning LED on/off, connect to
the cloud and many other actions.
 You can control your board functions by sending a set of instructions to the
microcontroller on the board via Arduino IDE (referred to as uploading software).
 Unlike most previous programmable circuit boards, Arduino does not need an extra
piece of hardware (called a programmer) in order to load a new code onto the board.
You can simply use a USB cable.
 Additionally, the Arduino IDE uses a simplified version of C++, making it easier to learn
to program.
 Finally, Arduino provides a standard form factor that breaks the functions of the
micro-controller into a more accessible package.
Board Types and their specification:
BOARD DESCRIPTIONS:
USING ARDUINO IDE:
Launch Arduino IDE.

After your Arduino IDE software is downloaded, you need to unzip the folder. Inside the
folder, you can find the application icon with an infinity label (application.exe). Doubleclick
the icon to start the IDE.
Open your first project.

Once the software starts, you have two options:

Create a new project.

Open an existing project example.

To create a new project, select File --> New.

To open an existing project example, select File -> Example -> Basics -> Blink.
Laboratory 9
1. To blink an LED i.e. turning a LED on and off based on the defined delay.
Components required and interfacing circuit:
 1x Breadboard
 1x Arduino Uno R3
 1x LED
 1x 330Ω Resistor
 2x Jumper

Arduino Code
/*

Blink Turns on an LED on for one second, then off for one second,repeatedly. */

// the setup function runs once when you press reset or power the board void setup()
{

// initialize digital pin 13 as an output.


pinMode(2, OUTPUT);

// the loop function runs over and over again forever void loop()
{

digitalWrite(2, HIGH);
delay(1000); digitalWrite(2, // turn the LED on (HIGH is the voltage level)
LOW); delay(1000);
// wait for a second

// turn the LED off by making the voltage LOW

// wait for a second

}
Code to Note
pinMode(2, OUTPUT) - Before you can use one of Arduino’s pins, you need to tell Arduino Uno R3
whether it is an INPUT or OUTPUT. We use a built-in “function” called pinMode() to do this.

digitalWrite(2, HIGH) - When you are using a pin as an OUTPUT, you can command it to be HIGH
(output 5 volts), or LOW (output 0 volts).

Observations:

2. To demonstrates the use of the analogWrite() function in fading an LED off.


AnalogWrite uses pulse width modulation (PWM), turning a digital pin on and
off very quickly with different ratios between on and off, to create a fading
effect
Components required and interfacing circuit:
 1x Breadboard
 1x Arduino Uno R3
 1x LED
 1x 330Ω Resistor
 2x Jumper
Arduino Code:
/*

Fade

This example shows how to fade an LED on pin 9 using the analogWrite() function. The analogWrite() function
uses PWM, so to change the pin use another PWM capable pin. On most Arduino, the PWM pins are identified
with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.

*/

int led = 9; // the PWM pin the LED is attached to

int brightness = 0; // how bright the LED is

int fadeAmount = 5; // how many points to fade the LED by

// the setup routine runs once when you press reset:

void setup()

// declare pin 9 to be an output:

pinMode(led, OUTPUT);

// the loop routine runs over and over again forever:

43
void loop()

// set the brightness of pin 9:

analogWrite(led, brightness);

// change the brightness for next time through the loop:

brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:

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

fadeAmount = -fadeAmount ;

// wait for 30 milliseconds to see the dimming effect

delay(300);

Observations:

44
Laboratory 10
1. To determine the distance of object using ultrasonic sensor interfaced with
arduino.
Components required and interfacing circuit:
1x Breadboard

1x Arduino Uno R3

1x ULTRASONIC Sensor (HC-SR04)

Arduino Code:
const int pingPin = 7; // Trigger Pin of Ultrasonic Sensor

const int echoPin = 6; // Echo Pin of Ultrasonic Sensor

void setup()

Serial.begin(9600); // Starting Serial Terminal

void loop()

long duration, inches, cm;

pinMode(pingPin, OUTPUT);

digitalWrite(pingPin, LOW);

delayMicroseconds(2);

digitalWrite(pingPin, HIGH);

delayMicroseconds(10);

digitalWrite(pingPin, LOW);

pinMode(echoPin, INPUT);

duration = pulseIn(echoPin, HIGH);

45
inches = microsecondsToInches(duration);

cm = microsecondsToCentimeters(duration);

Serial.print(inches);

Serial.print("in, ");

Serial.print(cm);

Serial.print("cm");

Serial.println();

delay(100);

long microsecondsToInches(long microseconds)

return microseconds / 74 / 2;

long microsecondsToCentimeters(long microseconds)

return microseconds / 29 / 2;

Observation:

2. To determine the temperature using temperature sensor interfaced with


arduino.
Components required and interfacing circuit:
1x Breadboard

1x Arduino Uno R3

1x LM35 sensor

46
Arduino Code:
float temp;

int tempPin = 0;

void setup()

Serial.begin(9600);

void loop()

temp = analogRead(tempPin);

// read analog volt from sensor and save to variable temp

temp = temp * 0.48828125;

// convert the analog volt to its temperature equivalent

Serial.print("TEMPERATURE = ");

Serial.print(temp); // display temperature value

Serial.print("*C");

Serial.println();

delay(1000); // update sensor reading each one second

Observation:

47
Laboratory 11
To display “Hello World” using LCD interfaced with Arduino.
Components required and interfacing circuit:
 Arduino or Genuino Board
 LCD Screen (compatible with Hitachi HD44780 driver)
 pin headers to solder to the LCD display pins
 10k ohm potentiometer
 220 ohm resistor

Arduino Code:
/*

LiquidCrystal Library - Hello World

Demonstrates the use a 16x2 LCD display. The LiquidCrystal

library works with all LCD displays that are compatible with the

Hitachi HD44780 driver. There are many of them out there, and you

can usually tell them by the 16-pin interface.

This sketch prints "Hello World!" to the LCD

and shows the time.

The circuit:

* LCD RS pin to digital pin 12

* LCD Enable pin to digital pin 11

* LCD D4 pin to digital pin 5

* LCD D5 pin to digital pin 4

* LCD D6 pin to digital pin 3

* LCD D7 pin to digital pin 2

* LCD R/W pin to ground

48
* LCD VSS pin to ground

* LCD VCC pin to 5V

* 10K resistor:

* ends to +5V and ground

* wiper to LCD VO pin (pin 3)

*/

// include the library code:

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {

// set up the LCD's number of columns and rows:

lcd.begin(16, 2);

// Print a message to the LCD.

lcd.print("hello, world!");

void loop() {

// set the cursor to column 0, line 1

// (note: line 1 is the second row, since counting begins with 0):

lcd.setCursor(0, 1);

// print the number of seconds since reset:

lcd.print(millis() / 1000);

Observation:

49
Laboratory 12
Aim of Experiment:
1. To interface the servo motor with arduino as per determined steps.
Components required and interfacing circuit:
1x Arduino UNO board

1x small bipolar stepper Motor

1x LM298 driving IC

Arduino Code:
/* Stepper Motor Control */

#include <Stepper.h>

const int stepsPerRevolution = 90;

// change this to fit the number of steps per revolution

// for your motor

// initialize the stepper library on pins 8 through 11:

Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {

// set the speed at 60 rpm:

myStepper.setSpeed(5);

// initialize the serial port:

Serial.begin(9600);

void loop() {

50
// step one revolution in one direction:

Serial.println("clockwise");

myStepper.step(stepsPerRevolution);

delay(500);

// step one revolution in the other direction:

Serial.println("counterclockwise");

myStepper.step(-stepsPerRevolution);

delay(500);

}}

Observation:

2. To interface servo motor with the Arduino for maintaining the angular
position of the shaft.
Components required and interfacing circuit:
1x Arduino UNO board

1x Servo Motor

1x ULN2003 driving IC

1x 10 KΩ Resistor

51
Arduino Code:
/* Controlling a servo position using a potentiometer (variable resistor) */

#include <Servo.h>

Servo myservo; // create servo object to control a servo

int potpin = 0; // analog pin used to connect the potentiometer

int val; // variable to read the value from the analog pin

void setup()

myservo.attach(9); // attaches the servo on pin 9 to the servo object

void loop()

val = analogRead(potpin);

// reads the value of the potentiometer (value between 0 and 1023)

val = map(val, 0, 1023, 0, 180);

// scale it to use it with the servo (value between 0 and 180)

myservo.write(val); // sets the servo position according to the scaled value

delay(15);

Observation:

52

You might also like