1
Name:
Muhammad Ehtisam Baig
Roll no:
RP22-EE-433
Lab 13
Interfacing and Controlling Actuators and Motors with
8051 Microcontroller.
Objective: The objective of this lab is to understand how to interface various
actuators and control circuits with the 8051 microcontrollers. This includes
controlling relays, driving a DC motor, H-bridge, Stepper motor, and generating
PWM signals to adjust motor speeds.
Material Required:
1. 8051 Microcontroller
2. LEDs
3. Resistors
4. Capacitors
5. 11.0592 MHz Crystal Oscillator
6. Push Button
7. Power Supply
8. Oscilloscope
9. Relay Module (EDR201A05)
[Link] Pair Transistors (TIP120)
[Link] (1N1199C)
[Link] and PNP Transistors
[Link] Motor
[Link] Motor
[Link] Module
2
Schematic:
Task 1: Interfacing Relays with 8051 Using a Darlington Pair
1. Connect the base of the Darlington pair to an output pin on the
8051 microcontroller.
2. Connect the collector of the Darlington pair to one terminal of the
relay coil and the emitter to ground.
3. Connect a diode across the relay coil for flyback protection.
4. Use an external power source to drive the relay (12V if needed).
5. Write a program to send a high or low signal from the 8051 to
switch the relay on and off.
6. Use small load connected to the relay to verify that it switches on
and off.
3
$MOD51
ORG 00
LOOP: CPL P0.0
ACALL DELAY
SJMP LOOP
DELAY: MOV R0, #55
HERE: DJNZ R0, HERE
RET
END
4
Outputs:
Task 2: Interfacing an Optoisolator with 8051 for Signal Isolation
1. 1. Connect the LED side of the optoisolator to an output pin of
the 8051 through a current limiting resistor.
2. Connect the phototransistor side to a separate power supply and
load, which simulates an isolated circuit.
3. Write code to control the output pin on the 8051 to turn the LED
in the optoisolator on and off.
5
$MOD51
ORG 00
LOOP: CPL P0.0
ACALL DELAY
SJMP LOOP
DELAY: MOV R0, #55
HERE: DJNZ R0, HERE
RET
END
6
Outputs:
Task 3: Controlling a Stepper Motor with 8051
1. Connect the stepper motor’s control lines to output pins on the
8051.
2. Write code to step the motor in both clockwise and
counterclockwise directions by controlling the sequence of outputs.
3. Set up a delay between each step to control the speed of the motor.
7
$MOD51
ORG 00
MAIN:
ACALL ANTICLOCWISE
ACALL CLOCKWISE
SJMP MAIN
CLOCKWISE: MOV A, #10011001b
MOV R1, #12
LOOP: MOV P0, A
RR A
ACALL DELAY
DJNZ R1, LOOP
RET
ANTICLOCWISE: MOV A, #10011001b
MOV R1, #12
8
LOOP1: MOV P0, A
RL A
ACALL DELAY
DJNZ R1, LOOP1
RET
DELAY: MOV R0, #100
HERE1: MOV R2, #10
HERE: DJNZ R2, HERE
DJNZ R0, HERE1
RET
END
Outputs:
9
Task 4: Building and Controlling a Custom H-Bridge using NPN
and PNP transistors for DC Motor Direction Control
1. Connect four transistors in an H-bridge configuration, with the
motor as the load in the middle of the bridge. Connect the gates of
the transistors to the output pins of the 8051 microcontroller.
2. Ensure that the correct transistors are activated for forward and
reverse directions.
3. Write code to switch transistors in pairs, allowing for forward and
reverse rotation of the motor.
4. Test the H-bridge to confirm that the motor rotates in both forward
and reverse directions.
10
Outputs:
$MOD51
ORG 00
MAIN: ACALL CLOCKWISE
ACALL ANTICLOCWISE
SJMP MAIN
CLOCKWISE: SETB P0.0
SETB P0.1
CLR P0.2
CLR P0.3
ACALL DELAY
RET
ANTICLOCWISE: CLR P0.0
CLR P0.1
11
SETB P0.2
SETB P0.3
ACALL DELAY
RET
DELAY: MOV R0, #100
HERE1: MOV R1, #10
HERE: DJNZ R1, HERE
DJNZ R0, HERE1
RET
END
Task 5: Generating PWM Signal on 8051 for Speed Control of DC
Motor
1. Implement PWM in software by toggling an output pin at variable
duty cycles.
2. Connect this output to the control input of the H-bridge circuit
controlling the DC motor.
3. Write code to vary the duty cycle of the PWM signal to control the
motor speed.
4. Observe the speed of the motor using oscilloscope as you vary the
PWM duty cycle and confirm that it changes according to the code.
Outputs:
12
Conclusion
In this lab, we have successfully learned Reading Analog Values with 0804 ADC
and Displaying on 16x2 LCD with 8051 Microcontroller.