Professional Documents
Culture Documents
(ARDX)
arduino experimentation kit
CIRC-01 Blinking LED
CIRC-02 Multiple LEDs
CIRC-03 Transistors & Motors
CIRC-04 Servos
CIRC-05 74HC595 Shift Registers
CIRC-06 Piezo Speaker
CIRC-07 Pushbuttons
CIRC-08 Potentiometers
CIRC-09 Photo-Resistors
CIRC-10 Temperature
CIRC-11 Relays
(NEDX)
netduino experimentation kit
NCIR-01 Blinking LED
NCIR-02 Multiple LEDs
NCIR-03 Transistors & Motors
NCIR-04 Servos
NCIR-05 74HC595 Shift Registers
NCIR-06 Piezo Speaker
www.oomlout.com/oom.php/products/ardx/circ-03 1/7
22/6/2019 products:ardx:circ-03[.:oomlout:.]
NCIR-07 Pushbuttons
NCIR-08 Potentiometers
NCIR-09 Photo-Resistors
NCIR-10 Temperature
NCIR-11 Relays
PROJECTS
(RARM)
robotic arm
(CNC1)
desktop cnc router
(SESW)
servo switch
(OAWR)
obstacle avoiding walking robot
LABS
(FUTU)
the future
STORE
(UK&EU)
united kingdom&EU
(OTHER)
the rest of the world
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
CIRC
03
www.oomlout.com/oom.php/products/ardx/circ-03 2/7
22/6/2019 products:ardx:circ-03[.:oomlout:.]
The Circuit
The Parts
CIRC-03 Transistor
2 Pin Header
Breadboard Sheet P2N2222AG (TO92) Wire
x4
x1 x1
Diode 10k Ohm Resistor
Toy Motor
(1N4001) Brown-Black-Orange
x1
x1 x1
Schematic
Resources
.:download:.
breadboard layout sheet
http://ardx.org/BBLS03
.:view:.
assembly video
http://ardx.org/VIDE03
www.oomlout.com/oom.php/products/ardx/circ-03 3/7
22/6/2019 products:ardx:circ-03[.:oomlout:.]
/*
* setup() - this function runs once when you turn your Arduino on
* We set the motors pin to be an output (turning the pin high (+5v) or low (ground) (-))
* rather than an input (checking whether a pin is high or low)
*/
void setup()
{
pinMode(motorPin, OUTPUT);
}
www.oomlout.com/oom.php/products/ardx/circ-03 4/7
22/6/2019 products:ardx:circ-03[.:oomlout:.]
/*
* loop() - this function will start after setup finishes and then repeat
* we call a function called motorOnThenOff()
*/
/*
* motorOnThenOff() - turns motor on then off
* (notice this code is identical to the code we used for
* the blinking LED)
*/
void motorOnThenOff(){
int onTime = 2500; //the number of milliseconds for the motor to turn on for
int offTime = 1000; //the number of milliseconds for the motor to turn off for
/*
* motorOnThenOffWithSpeed() - turns motor on then off but uses speed values as well
* (notice this code is identical to the code we used for
* the blinking LED)
*/
void motorOnThenOffWithSpeed(){
int onSpeed = 200; // a number between 0 (stopped) and 255 (full speed)
int onTime = 2500; //the number of milliseconds for the motor to turn on for
int offSpeed = 50; // a number between 0 (stopped) and 255 (full speed)
int offTime = 1000; //the number of milliseconds for the motor to turn off for
/*
* motorAcceleration() - accelerates the motor to full speed then
* back down to zero
*/
void motorAcceleration(){
int delayTime = 50; //milliseconds between each speed step
www.oomlout.com/oom.php/products/ardx/circ-03 5/7
22/6/2019 products:ardx:circ-03[.:oomlout:.]
Still No Luck?
If you sourced your own motor, double check that it will work with 5 volts and that it does not draw too much
power.
Making it Better?
Controlling Speed:
We played with the Arduino's ability to control the brightness of an LED earlier now we will use the same
feature to control the speed of our motor. The Arduino does this using something called Pulse Width Modulation
(PWM). This relies on the Arduino's ability to operate really really fast. Rather than directly controlling the
voltage coming from the pin the Arduino will switch the pin on and off very quickly. In the computer world this
is going from 0 to 5 volts many times a second, but in the human world we see it as a voltage. For example if the
Arduino is PWM'ing at 50% we see the light dimmed 50% because our eyes are not quick enough to see it
flashing on and off. The same feature works with transistors. Don't believe me? Try it out.
Why stop at two speeds, why not accelerate and decelerate the motor. To do this simply change the loop() code
to read
// motorOnThenOff();
// motorOnThenOffWithSpeed();
motorAcceleration();
Then upload the program and watch as your motor slowly accelerates up to full speed then slows down again. If
you would like to change the speed of acceleration change the variable delayTime (larger means a longer
acceleration time).
www.oomlout.com/oom.php/products/ardx/circ-03 7/7