The Birth of LABron
Introduction
Our first lab helped up build confidence working with Arduino and ended with us working towards Milestone 1. First, we experimented with blinking LED and the analog inputs of the Arduino supplied by a potentiometer. Later, we combined these functions to dim an LED using the potentiometer. Lastly, we began experimenting with servo functionality and built our first robot, affectionately nicknamed LeBron.
Internal Blink
We ran the original
Blink.ino
example on our connected Arduino
board and were able to see the LED
blinking. This code used the
LED_BUILTIN
pin on the board
and toggled it on and off. This introduced us to
basic Arduino mechanisms and program structure.
Modifying Blink Sketch
Changing the source code to
control an external LED was quite
quick. We connected the LED and
300 Ohm resistor in series with pin 7 and
were able to demonstrate controlled blinking
behvior using
digitalWrite
and a
specific delay with
delay
.
Variable Voltage Using a Potentiometer
After replacing the LED on pin 7
with a potentiometer, we were again
able to demostrate correct behavior
and manipulate voltage by dialing
the potentiometer CW and CCW. The
changes in value from turning the
potentiometer (read with
analogRead
are shown on the
Serial
monitor.
Using Variable Voltage to Dim LED
In this segment of the lab we
linked our previous steps (lighting
up an LED and reading an analog
voltage from a potentiometer) using
the map
and
constrain
function.
This was necessary because the
digital value of the analog input
has a range of 0 to 1023, but
writing an analog value to the LED
was based on a range of values from
0 to 255. Luckily, the functions we
used already existed to scale the input value down the necessary output value.
The potentiometer reading controlled the brightness of the LED's light.
Controlling Servos Using Potentiometers
Now that we'd learned to control
LEDs with a potentiometer, we made
a leap to controlling servos using
potentiometers. This required some
knowledge of servo functionality:
movement is controlled with a range
of int
values from 0
to 180, where 0 constitutes maximum
speed rotation in one direction,
180 constitutes maximum speed
rotation in the other direction,
and 90 a stopped servo. This
changed the parameters when using
the map
function.
Additionally, where previously we'd
use an analogWrite()
function to output the mapped
value, we instead used an existing
Servo
library to
attach()
and
write()
to the
Servo
objects we defined at the top of our code.
Building a Robot
Building off the success of
operating the servos, we were able
to begin constructing our first
robot. First, we created an
invert()
function so
that we could control the servos
simultaneously (since the 0 moved
the servo one direction and 180
moved the other direction). Without this important addition, the orientation of the servos opposite to each other would result in the wheels turning in opposite directions. The code base beyond this consisted of turning the servos on and off for various amounts of time so that eventually we were able to draw a figure-8 pattern, nicely encapsulated in our figEight()
function. The robot itself consisted of a main plate to which we velcroed our Arduino board and 9V battery, and many screws, nuts, and washers to attach the servos and their wheels.
Summary
In this lab we were able to develop a functioning robot that drew out a figure-8 pattern. In the process we learned how to read and write to the pins of our Arduino board, and operate our Parallax servos with success. In future labs, we will make it a point to save our code separately more often so that we can show the exact file that we accomplished the particular task with.
Extra Credit
The Arduino board we used didn't have enough separate 5V pins for our needs, so we soldered a wire to the 5V pin to a small board, from which we were able to solder additional wires to wherever we needed power (primarily the servos). In our final video, you can see a tiny board hanging off the back of the robot!