Sunteți pe pagina 1din 3

Name: ___________________________________

ME 1049 Lab 2
Analog Inputs and DC Motor Control on the Arduino
This assignment is to be done individually, and is due by the end of the lab period on
February 13. Steps preceded with _____ must be demonstrated to the lab instructor for
his initials.
In this lab you will use the Arduino analog input pins and wire an analog sensor as a
speed control input for a DC motor.
1) Wire five LEDs to five digital pins on the Uno board. Also wire an analog sensor (e.g.
potentiometer, thermistor, flex sensor, photo resistor, etc.) to one of the Unos
analog input pins. Note that most of these are resistive, and can be wired in a
voltage divider circuit as shown below.
2) Write a program that:
a) Causes the LEDs to blink in a linear fashion. That is, the light appears to scroll
along the row of LEDs from one to the next, then back around to the first one.
Repeat this pattern indefinitely.
b) The speed of scrolling LED should be proportional to the voltage read from the
analog sensor. Note that your sensor will likely not read the full 0-5V range, so
adjust the scrolling rate for your particular sensor range. If the voltage is at the
lowest value, turn all LEDs off. If the voltage is at the highest value, it should
take about 0.5 seconds for the light to scroll from one end of the LED row to the
other. For a voltage between min and max, set the scrolling proportionally.
________ 3) Upload your code to the Uno and run it. Once you have verified that it works
correctly, demonstrate the system to the lab instructor. Show what the voltage
range is for your sensor.

MEMS 1049 University of Pittsburgh wwc/1-20-15

Name: ___________________________________

In the following parts you will create a pulse-width modulation controller with which to
control the speed of a dc motor. The analog sensor created above will be used to set the
desired motor speed.
4) Using the P2N2222A transistor from the Arduino kit (dont confuse this with the
thermistor, as they look identical) as the power source wired as shown below (be
sure to include the diode across the motor), test your program by driving a dc
motor. (If you dont have a transistor and flyback diode, they will be provided in
the lab).
- Note that if you face the flat side of the transistor (that shows the part number),
the pins are from left-to-right: collector, base, emitter.
- Note the diode shown is a flyback diode that prevents unwanted voltage
spikes from the inductive coils in the motor to damage the circuit when the
current is rapidly changed in the motor. The black end of the diode is the
cathode and should be connected to the 5V source, while the opposite end
(anode) is connected to the collector of the transistor. When the cathode is
biased at lower voltage than the anode (so-called forward biasing), the diode
will conduct. Normally in this circuit the bias across the diode is in the opposite
direction and current flows through the motor. When the current is abruptly
stopped (when the PWM signal goes to zero), the collapsing magnetic field in
the motors armature produces a high voltage spike that forward biases the
diode and the transistor remains protected from the spike.

It is recommended that before continuing with the lab, you test the motor circuit
first by
i) simply connecting the transistors base to 5V or ground, to see the motor be
fully on or stopped, then
ii) write a simple on-off code to replicate that test with a digital pin from the
Arduino connected to the transistors base.
5) Write a program that produces a pulse-width modulated signal to control a motor. You
should test the signal using an oscilloscope. Be sure that different duty cycles can
be set across the full range from 0 to 100%.
6) Demonstrate that the motor speed can be varied from zero to a maximum by changing
the duty cycle of the PWM signal.

MEMS 1049 University of Pittsburgh wwc/1-20-15

Name: ___________________________________

7) Using the analog sensor of Parts 1)-3) as a speed control input to the motor,
combine your sensor, programs, and motor circuit such that the microcontroller reads
the analog voltage generated by the sensor and then sets the duty cycle based on that
value. When the sensor reads zero (or low voltage), the motor should be stopped
(zero duty cycle) and when a high voltage is read, the motor should run faster. Adjust
the sensor and/or your code so that you can control the motor speed between zero and
its maximum speed corresponding to the full range of the sensor (note that because of
dissipation factors in the motor, its speed will probably go to zero before the duty
cycle goes to zero, which is fine). Note that depending on the sensor used, you may
not observe a full 0-5V range from the sensor, but you MUST adjust the code so that
the motor can be adjusted over the full range of duty cycles (0-100) by using the input
sensor.
_____ 8) Demonstrate your final program and hardware setup. One should be able to use the
sensor to vary the motor speed from stopped to its max speed. While demonstrating
the motor in the lab, use an oscilloscope to show that the duty cycle of the motor
control signal is actually changing as the sensor voltage changes.

MEMS 1049 University of Pittsburgh wwc/1-20-15

S-ar putea să vă placă și