Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

EE 101 – Digital Control with Embedded Systems Student Name:

_______________________

DRIVING HIGH POWER DEVICES FROM


A MICROCONTROLLER
INTRODUCTION
Microcontrollers are great for grabbing input from sensors and controlling actuators like
DC motors. However, they are limited in their ability to drive things that require power.
They are NOT sources of power. Many actuators require substantial drive currents that
can only be obtained via external BJT and FET circuits.

In this lab you will develop a means to drive a motor based on the level of light sensed
by a photoresistor. In the first application you will simply control the motor speed in one
direction using the light level and a PWM driving signal. In the second you will drive the
motor in forward or reverse depending on the light level.

 Learn how to use a photo sensor in a voltage divider


 Read in an analog signal from a voltage divider
 Drive with single BJT transistor: Condition the analog value to drive a PWM signal to
control a motor’s speed
 Drive with an H-bridge. Create a state machine to drive the motor in forward or reverse
depending on the light level

MATERIALS
 Arduino Programming book (Blum)
 5516 photoresistor and Datasheet. Red circuit board labeled “Analog Sensor”
 Either, 2N2222, 2N3409 or 2N4238 NPN transistor and Datasheet
 H-Bridge DC Motor Driver module(see figure 0)
 Multimeter (you will need this!!)

1 Gallagher 2021
EE 101 – Electrical Engineering Concepts Student Name: _______________________

Figure 0. Parts you’ll need in this lab. Your NPN may look different and come in
a different package.
Optional
 O-scope
 Power Supply.

EXERCISES
Part I. Build a voltage divider using photo resistor

We will use a voltage divider to translate a light level into an analog voltage to be read
by the roboRed. This digital value can then be used in the next section to drive a motor.

Procedure:
Work methodically. Don’t assemble everything and then debug. Work in small steps.

Figure 1. Photo sensor circuit using a voltage divider

2 Gallagher, 2022
EE 101 – Electrical Engineering Concepts Student Name: _______________________

1. Analyze the photo sensor you have in your kit. It is a photocell(resistor) that changes
Rs with light intensity on it. It is in series with another constant resistor, R1 which has a
value approximately 10kohm. Its just a simple voltage divider.*

* some kits have a blue module with a photo resistor. Don’t use this. If you have
a blue module simply get a photoresistor from the cabinet and use it in series
with a 10kohm resistor as shown in Figure 1.

2. Connect your photo sensor to power. Use the 5V board as a source and ground on the
other. Don’t connect the analog input yet. Use a multimeter to ensure that the voltage
out at S changes with light level.

3. Activate the analog to digital converter on the UNO. Use the


example/analogWithSerialOutput to get you started. Record your values of the ATD in
Table 1.

4. The “example/analogWithSerialOutput” has an analog output from pin 9 included. You


can connect pin 9 to an LED as shown as optional in Figure 1 to make sure that your
PWM signal is varying from a low duty cycle (short pulse widths to high duty cycle (long
widths or even 100% on) with a presence or absence of light. This will be important to
control the motor in part 2.

Part 2. Controlling a DC motor with an npn BJT

Use a single BJT to “amplify” the power from the MCU. You will use an external power
supply to drive the motor, not the power from the MCU/USB as we have been.

Your kit should have either a 2N2222, a 2N3904 or a 2N4238 NPN transistor. Any one
will work. It should have three leads. Make sure to identify the type you have and the
use a google search to identify the leads as “emitter”, “base” and “collector”, as in figure
2.

3 Gallagher, 2022
EE 101 – Electrical Engineering Concepts Student Name: _______________________

Figure 2. Schematic to drive a motor in one direction with a single BJT


amplifier. Note the external supply for the motor. This should be 5V from
your benchtop DC power supply. Ground is shared!!! Only one ground.

Procedure:
1. You will use the benchtop DC power supply for your motor power. The power to the
MCU will continue to be the 5V USB supplied by the computer. We want to limit the
amount of current in the motor to 300 mA.
a. Dial to voltage level to 5V with nothing connected
b. Without any other circuitry, connect your motor to the same supply.
c. Note that there are two knobs: one for current and one for voltage. While the
motor is running adjust the current to limit at 0.3A or 300 mA. The voltage will
likely be lower too but don’t make any changes there.
2. Your kit should have either a 2N2222, a 2N3904 or a 2N4238 NPN transistor. Any one
will work. It should have three leads. Make sure to identify the type you have and the
use a google search to identify the leads as “emitter”, “base” and “collector”
3. Modify your circuit to add the transistor, current limiting base resistance and motor on
the collector side, as in figure 2.
4. If you pick the right mapping parameters so that the output modulates between 0 and
255 as you cover the sensor, then you will observe to motor to run full speed in the light
and come to rest or near-rest in the dark.

This completes part 2.

Part 3. Using an h-bridge to drive a DC motor

See this video for a review of H-Bridges. There are many tutorials
(https://www.youtube.com/watch?v=iYafyPZ15g8) Don’t worry. We have an H-bridge
module in the kit. See figure 0. Your H-bridge can control two DC motors designated A
and B. The direction and speed of a motor by input to two control pins, IA and IB. For
motor B your board calls them B-IA, B-IB. Table 1 indicates the function at IB and IB

Mode H-Bridge IA H-Bridge IB


1 0 0 off. Soft break
2 1 0 direction 1 (ex cw)
3 0 1 direction 2 (ex ccw)
4 1 1 off hard break

Table 1. Operation of the H-bridge module in your kit.

Procedure:

1. Build the circuit shown in figure 3. Note, you’re not using the sensor here at all but its
convenient to leave it in for part 4.
2. Use simple digital outputs at pins 9 and 10 to drive the motor through modes 1-4 in
table 2. You can put a 3s delay between each one to observe the action of the motor.
Something like this included in the main loop:

4 Gallagher, 2022
EE 101 – Electrical Engineering Concepts Student Name: _______________________

Serial.print("mode 1");
digitalWrite(IA,0); // #define IA 9
digitalWrite(IB,0); // #define IB 10
delay(3000);

Don’t forget to initialize 9 and 10 as digital outputs!

Figure 3. Schematic of motor driven by h_bridge.

Part 4. Motor direction control with sensor input

In this part you’ll build an application that will control the direction of the motor using the
light sensor:

With ambient light there is no motor action. With a dark setting the motor will go in one
direction and with a bright setting, say using your phone to illuminate the sensor, the
motor will go in the opposite direction. In both cases, the motor will be only 50% full
duty cycle.

Since both pins 9 and 10 are PWM-(analogWrite)-capable, you can simply swap the
function of the pins to get the motor to reverse direction.

Procedure:

1. Establish sensor settings and desired analog output ranges using table 2.

Light level Actual Mapped IA IB


sensor value
value
Ambient 0 0
Full bright DC 50% 0
5 Gallagher, 2022
EE 101 – Electrical Engineering Concepts Student Name: _______________________

Full dark 0 DC 50%


Table 2. Record sensor values. DC refers to duty cycle. A 50% duty cycle is
achieved with analogWrite(IA,128) // 255/2 = 128

Use your results to gauge what values should constitute “bright” and “dark” and can be
used to control the motor direction.

2. Use an existing state machine as a template to begin. Create a 4 state machine


(including a reset) that will drive the motor in one direction if the mapped sensor value
exceeds the bright value you determined in 1 and in the other direction if it falls below
the dark value. Make sure the motor is only operating at 50% duty cycle in both
directions.

Things to consider:

1. Can you envision an application that controls not only the direction but also the speed of
the motor with this application?
2. What would you do to avoid the motor from being turned on and off as the sensor
crossed a transition value?

Part 5. Driving a Larger Load with a Relay

A relay can be used to drive larger DC and AC loads. This is in contrast to the
transistor-driven examples we just did that could only drive DC loads. In this part you’ll
use your blue relay board (see figure 5) to drive a load of your choice. You may control
the relay closure as shown in Figure 4 using digital output pin 9, but its your choice.

The relay board in MY kit has two relays. The input side to the micro controller has pins
for control (IN1 and IN2), power (VCC) and ground pins. Note that there is a jumped
Vcc pin that must be in place for the npn shown in figure 5 to be powered. The npn and
flyback diode are both placed directly on this board. How convenient!!!

The output side simply creates a short beteen the NC (normally closed) pin and com or
between NO (normally open) pin and com. Note, the ground on the input side and the
grounds shown on the load or output side are NOT connected. These two circuits are
said to be electriclly isolated which is a good thing in many circumstances.

6 Gallagher, 2022
EE 101 – Electrical Engineering Concepts Student Name: _______________________

Figure 4. Relay circuit schematic

Figure 5. Relay circuit hybrid layout and schematic.

Procedure:

1. Find your relay and locate the pins described above. Examine the relay board
and locate the flyback diode and the npn.
2. Find a suitable load for you to examine. For example, you could use the same
DC motor from the previous sections and drive it again with the external power
supply. Other options:
i. DC fan motors in the supply cabinet that run off 12 V. Use the extrnal
supply.

7 Gallagher, 2022
EE 101 – Electrical Engineering Concepts Student Name: _______________________

ii. Solenoid plunger in your kit. See the box with “solenoid, stepper and
driver”. Try driving it with 5V.
iii. Speakers. Not sure how intersting these will be with a quasi DC signal.
They might just make a beep every time you switch on and off
3. Connect your load to the circuit as shown in both figures 4 and 5.
4. Make a very basic Arduino program that will drive the relay to be closed for 0.5s
and open for 1.0 s. This can just be a simple loop with delays.

Things to consider:

1. would a relay be good for PWM control of the load power?


2. What does the flyback resistor do?

8 Gallagher, 2022

You might also like