The SparkFun RedBot kit contains a printed circuit board (PCB) that incorporates an ATmega328P microcontroller, which will act like the “brain” of your robot. SparkFun refers to this circuit board as the RedBot mainboard.
A microcontroller is a small computer on a single integrated circuit that contains a processor (CPU), memory, storage, and programmable input/output pins.
Compared to the tech specs of a "regular" computer, a microcontroller is much less powerful – it has a slower processor, less memory, and less storage. This is because microcontrollers are used in devices that have dedicated functions (such as: automobile engine control systems, medical devices, office machines, appliances, etc.). These dedicated devices typically don’t require as much computing power to perform their specialized tasks.
The RedBot circuit board also has various pins, ports, buttons, switches, and LED lights. Wires from different inputs (such as: sensors, etc.) and outputs (such as: motors, etc.) are connected to the pins on the circuit board to create a functional robot. You control the robot by programming an app that will run on the microcontroller.
ATmega328P Microcontroller: controls entire robot and runs robot's app
Processor: 8-bit 20Mhz AVR
Memory: 2KB RAM
Storage: 32KB Flash
Input/Output: supports up to 23 general-purpose I/O pins
TB6612FNG Dual DC Motor Driver Chip: used to control the two wheel motors
FTDI FT232R USB Chip: used to send and receive data through the USB port
Input/Output Pins: used to connect wires for inputs (sensors, etc.) and outputs (speaker, etc.)
These I/O pins are in groups labeled as "Sensor" or "Servo" – each group has 6 pins, representing a set of 3 pins on the left and another set of 3 pins on the right.
Each set of 3 pins has one pin for input/output of data, a second pin for power (5V = positive), and a third pin for ground (GND = negative). Typically, a white wire connects to the I/O pin, a red wire connects to the 5V pin, and a black wire connects to the GND pin.
The "Sensor" I/O pins are numbered as: A0, A1, A2, A3, A4, A5, A6, A7.
The "Servo" I/O pins are numbered as: 3, 9, 10, 11.
There are also I/O pins connected directly to a LED light (pin D13) and push button (pin D12).
Motor Pins: used to connect wires for left and right motors (which are a type of output)
Power Supply Jack: used to provide power to robot (by plugging in barrel jack from battery pack)
Mini USB Port: used to connect robot to computer (either to download new app from computer or to send serial data to computer)
LED Lights:
Power LED: Green LED that indicates the robot is powered on
D13 LED: Green LED that can be controlled by your robot's app
TX and RX LEDs: Green LEDs indicating data transfer between robot and computer
Buttons:
Reset Button: Restarts your robot's app (similar to turning robot off and back on)
D12 Button: Robot's app can be coded to detect if this button is pressed
Switches:
Power Switch (OFF/ON): used to turn robot off or on (be sure to turn off robot before storing to conserve battery power)
Motor Switch (STOP/RUN): normally should be set to RUN, but can temporarily set to STOP to stop motors (but robot's app will continue to run if power is on)
XBee Serial Mode Switch (HW/SW): used to set XBee serial communication mode (leave this set to HW – unless you're using an XBee wireless antenna module)
XBee Port: used to plug in an optional XBee wireless antenna module (which is not included in standard kit – and will not be used for this project)
XBEE: If you use an XBee wireless antenna module, pins A0 and A1 will be used as TX and RX for the XBee serial communication – which means you will NOT be able to use the A0 and A1 pins for another purpose, such as an ultrasonic sensor.
A microcontroller is controlled by its firmware, which acts as its operating system. Your RedBot's microcontroller has Optiboot firmware installed, which is the same firmware used on Arduino Uno circuit boards. You'll code apps for your robot using the Arduino programming language.
Unlike other computers, a microcontroller is designed to store and run only one app at a time. The app determines what actions the robot will perform. Whenever the robot is powered on, the robot's app will automatically start and will run in a continuous loop.
If you need to change your robot's app, the new app has to be downloaded over USB (and will replace the old app). Later, you will complete several practice tutorials to learn how to program and download apps that control your robot's actions.
Your RedBot robot has other useful components, which can be categorized as either physical inputs or physical outputs.
Physical inputs (such as sensors, etc.) are components that gather data from the physical environment. The D12 push button on the circuit board and the wheel encoders are both examples of physical inputs. Most of the other components on your RedBot are physical inputs that help the robot sense its environment.
Physical outputs (such as motors, etc.) are components that can perform some action in the physical environment. The D13 LED light on the circuit board and the motors are both examples of physical outputs. The only other component on your RedBot that is a physical output is its speaker.
The RedBot has a small speaker (labeled as a "buzzer") that should be attached to I/O pin 9 on the circuit board.
This speaker can produce simple sounds. The speaker can only play one tone (sound) at a time, but you can create different sounds or sound patterns. You could even program it to play simple music by playing one note at a time.
Sounds can be useful as audio alerts or feedback to people interacting with your robot.
The RedBot has two mechanical bumpers (left and right) at its front to detect collisions with obstacles.
Each mechanical bumper has a wire "whisker" that extends to one side about 6 inches. If the wire whisker collides with an obstacle, the wire will bend and eventually make contact with a metal screw attached to the bumper board. When this happens, it acts like an electrical switch, which the robot can detect has been closed.
Each mechanical bumper is connected to the RedBot circuit board by a 3-wire jumper cable (white, red, and black wires for data, power, and ground):
The left mechanical bumper data wire should be connected to I/O pin 3
The right mechanical bumper data wire should be connected to I/O pin 11
The RedBot has three IR line sensors (left, center, and right) mounted at its front close to the surface. The bottom of each line sensor has an LED that transmits infrared (IR) light, which is invisible to the human eye. The bottom of each sensor also has an IR detector, which measures how much of the IR light is reflected back by the surface that the robot is driving on.
The amount of reflected IR light that is detected depends on several factors, including the color of the surface, as well as the distance between the sensor and the surface:
A light-colored surface reflects more IR light, while a dark-colored surface reflects less IR light.
If the surface is farther away from the sensor, the IR light becomes more scattered, and less IR light will be reflected back to the detector. Even a small increase in the distance between the sensor and the surface will significantly reduce the amount of reflected IR light.
There are several robot behaviors that can be performed using the IR sensors:
The IR sensors can be used to make the robot follow a line by adjusting the left and right motor powers to keep the robot centered on the line as it drives.
The IR sensors can be used to make the robot avoid a line by turning away from a detected line. In this case, lines act as "borders" to keep the robot inside (or outside) a certain area or path.
The IR sensors can be used to count line markers that the robot crosses while driving and then make the robot stop or turn once it reaches a desired line number.
The IR sensors can be used to avoid driving over a drop-off by stopping the motors if the IR sensor measurements are too high (which may indicate the front edge of the robot is hanging over a drop-off, such as the edge of a table, a stair step leading down, a hole in the surface, etc.).
Detecting lines with the IR sensors works best with a dark line on a uniform light surface (or vice versa). The line also needs to be the right width: not too wide – but not too narrow. A line width between 0.5—0.75 inch is ideal.
Each IR line sensor is connected to the RedBot circuit board by a 3-wire jumper cable (white, red, and black wires for data, power, and ground):
The left line sensor data wire should be connected to I/O pin A3
The center line sensor data wire should be connected to I/O pin A6
The right line sensor data wire should be connected to I/O pin A7
The RedBot has an accelerometer that can be used to measure changes in motion or orientation along 3 axes (X, Y, Z). Accelerometers are used in a variety of devices, including smartphones, fitness trackers, etc.
The accelerometer is a small circuit board that should be connected to I/O pins A4 and A5 on the main RedBot circuit board.
The accelerometer can measure:
the acceleration of the device (i.e., the device speeding up or slowing down)
the acceleration due to Earth's gravity (i.e., the orientation of the device)
Although you can measure the robot's acceleration, you won't use the accelerometer to measure the robot's speed. This is because when an object is traveling at a constant speed, its acceleration is actually zero. An object is only accelerating if its speed is changing (i.e., speeding up or slowing down). Besides you will be able to directly control your robot's speed by adjusting its motor power.
However, you can use the accelerometer to detect when the robot is physically bumped – this type of change in motion is a "pulse" acceleration that is detectable by the accelerometer.
You can also use the accelerometer to detect the orientation of a device by measuring the acceleration due to Earth's gravity, which is a constant downward force acting on all objects. The accelerometer can determine if the device is parallel to Earth's surface or if the device is tilted at an angle. For example, smartphones use accelerometers to detect the phone's orientation, and then the phone changes the screen orientation to match how the phone is being held.
The accelerometer measures the acceleration along each axis (X, Y, Z) and then uses these measurements to calculate the device's angle in the XZ plane, YZ plane, and XY plane.
This diagram shows how the accelerometer's X, Y, and Z axes are oriented on the RedBot and what the XZ, YZ, and XY angles represent. These angles are also referred to as pitch, roll, and yaw.
For a wheeled vehicle, pitch and roll are the most important angles to measure as they indicate the tilt of the vehicle from front-to-back and from side-to-side.
Angle XZ represents pitch. Pitch is the front-to-back rotation on the device's Y axis. The pitch angle can range from -180° to 180°.
If the RedBot is perfectly level from front-to-back, the pitch is zero (angle XZ = 0).
If the front of the RedBot is rotated up, the pitch is a positive value (angle XZ > 0). For example, if the front of the RedBot were pointing straight up, the pitch would be 90°.
If the front of the RedBot is rotated down, the pitch is a negative value (angle XZ < 0). For example, if the front of the RedBot were pointing straight down, the pitch would be -90°.
Angle YZ represents roll. Roll is the side-to-side rotation on the device's X axis. The roll angle can range from -180° to 180°.
If the RedBot is perfectly level from side-to-side, the roll is zero (angle YZ = 0).
If the left side of the RedBot is rotated up, the roll is a positive value (angle YZ > 0). For example, if the left side of the RedBot were pointing straight up, the roll would be 90°.
If the left side of the RedBot is rotated down, the roll is a negative value (angle XZ < 0). For example, if the left side of the RedBot were pointing straight down, the roll would be -90°.
Angle XY represents yaw. Yaw is the right-to-left rotation on the device's Z axis. The yaw angle can range from -180° to 180°. However, when the RedBot is on a level surface, the yaw value cannot be accurately determined because the acceleration due to Earth's gravity is acting in the same direction (i.e., downward) as the Z axis. Therefore, you cannot use the accelerometer's XY angle to determine which clockwise direction the robot is pointed. (However, there are other sensors – not included in this kit – which can be used to accurately measure the yaw angle.)
An ultrasonic sensor uses sonar to measure the distance ahead to the closest object in the robot's path. This can be used to avoid collisions with obstacles. This is similar to how bats and dolphins use echolocation for navigation and hunting.
The ultrasonic sensor has a transmitter (i.e., a speaker) that can produce high-frequency sound, which cannot be heard by the human ear. The sensor also has a receiver (i.e., a microphone) that detects the echo of the high-frequency sound when it is reflected back from a nearby object. By measuring how much time it takes for the echo to arrive, you can calculate the distance between the sensor and the closest object.
TRANSMITTER VS. RECEIVER: The ultrasonic sensor's transmitter and receiver both look like small speakers, even though the receiver acts as a microphone. This is because speakers and microphones use a similar physical design to perform opposite functions: a speaker converts electrical energy into sound waves, and a microphone converts sound waves into electrical energy.
This ultrasonic sensor measures distances in a narrow cone of about 15° in front of the sensor. This sensor can detect obstacles located up to 400 cm away (about 13 feet). The distance measurements from the sensor are very accurate, within about 3 mm (about 0.1 inch) of the actual distance.
The primary use of the ultrasonic sensor is to prevent collisions. If the sensor detects a nearby obstacle in the path ahead, the robot can be programmed to avoid the obstacle by stopping or turning. You could even use this sensor to program your robot to navigate a maze on its own.
However, the ultrasonic sensor might not detect obstacles off to the left side or right side — if those obstacles are outside the 15° detection cone directly in front of the sensor. For these situations, you may want to use the mechanical bumpers as a fallback system to supplement the ultrasonic sensor. Since the mechanical bumper whiskers extend outwards on both sides, they can detect a collision with an obstacle that the ultrasonic sensor might not detect (as shown below).
The ultrasonic sensor should be connected to the RedBot circuit board by a 4-wire jumper cable (will be different colors – two wires are for data, one is for power, and one is for ground):
The transmitter data wire (Trig) should be connected to I/O pin A0.
The receiver data wire (Echo) should be connected to I/O pin A1.
The RedBot is a two-wheeled robot. It also has a semi-circular plastic "nub caster" on the underside of its chassis at the back. This caster acts as a third point of contact to balance the robot (similar to a third wheel, except the caster doesn't rotate).
Each wheel is driven by its own motor, which is connected to the RedBot circuit board by a pair of red and black wires. These left and right motors can be controlled as a set or independently, in order to make the robot drive forward, backwards, or make turns.
You can also determine how much power each motor receives, in order to rotate the wheels faster or slower, to control the speed of your robot as it drives and turns.
Located directly behind each wheel motor is a wheel encoder. The wheel encoder is used to count exactly how many times that motor has rotated. These wheel encoder counts can be used to:
make the robot drive in a straight line (by adjusting the motor powers if one motor happens to be rotating slightly faster than the other)
calculate how far the robot has driven (by determining how many times the wheel has turned and multiplying that by the wheel circumference)
The wheel encoder actually consists of two parts:
a Hall Effect sensor that can measure the strength of a magnetic field
a ring magnet (looks like a metal washer) attached to the motor shaft
When the motor rotates the wheel, it also rotates the ring magnet. The Hall effect sensor positioned near the ring detects changes in the magnetic field as the ring rotates. This is how the sensor can count how many times the motor has rotated.
When you think of a magnet, you probably think of a magnet that has 2 poles: north and south. It is true that magnets have pairs of N-S poles. However, a magnet can be created with multiple pairs of N-S poles. The ring magnets attached to the RedBot motors each have 4 pairs of N-S poles, similar to the diagram below.
So as the ring magnet completes one full rotation, the Hall effect sensor detects 4 changes (or "ticks") in the magnetic field as each magnetic pole passes by the sensor.
Each wheel encoder is connected to the RedBot circuit board by a 3-wire jumper cable (white, red, and black wires for data, power, and ground):
The left wheel encoder data wire should be connected to I/O pin A2
The right wheel encoder data wire should be connected to I/O pin 10
The wheel encoders are one of the most useful sensors on your robot because they can allow your robot to drive straight for specific distances and to make turns of specific angles (such as: 90° right, 90° left, 180° around, etc.).
In this first tutorial, you'll become familiar with your team's robotics kit. Your team might receive a new robotics kit that needs to be assembled – or you might receive an existing robot that is ready to use.
NEW ROBOT: If you need to assemble a new SparkFun RedBot kit, follow the instructions in the . If your teacher added an ultrasonic sensor to your kit, follow these to your assembled robot.
IMPORTANT: Once a SparkFun RedBot has been assembled, it should remain assembled (even after the project is completed). RedBot assembly is a one-time process.
The goals of this tutorial are to help you:
Understand the parts of your robot and their purposes
Identify the physical inputs and outputs that your robot can use to sense and act
This guidebook is tailored for a two-wheeled robotics kit called the , which will simply be referred to as the RedBot kit.
is a company that sells products to help people build and program electronics devices. SparkFun created its RedBot kit by incorporating an Arduino-based microcontroller into an easy-to-use circuit board and packaged it with a set of motors, wheels, sensors, and other parts to help you learn how to program a wheeled robot. It is also possible to purchase additional parts (sensors, servo motors, etc.) that can be used with this RedBot kit.
Once assembled, your RedBot should look like this:
A simple (but important) step is to understand the orientation of the RedBot — specifically, which end is the front of the robot? An easy way to remember: most of the sensors are attached at the front end, while the circuit board is located at the back end.
ADD-ON COMPONENT: The SparkFun RedBot Kit does NOT include an ultrasonic sensor as a standard component. However, SparkFun sells the , which can be easily connected to a RedBot. Your teacher may have added this sensor to your kit.
If you have an , it should be mounted at the front of the robot on top of the chassis (above the mechanical bumpers and IR line sensors). The ultrasonic sensor should face forward, like a pair of "eyes" (though an ultrasonic sensor actually uses high-frequency sound waves to "see").