You are on page 1of 2

Programming Mr.

General
Once you have assembled Mr. General and wired up your microcontroller the next step will be to
program Mr. General. This requires you to understand how his sensors work and how to use them. Mr.
General uses infrared LEDs and phototransistors to detect objects. The way this works is simple.
When light from the IR LEDs hits an object, some of the light is reflected back to the robot where it is
detected by the phototransistor. The photo transistor works like a normal NPN transistor except that
the base connection is inside the component and is sensitive to IR light (940nm). The brighter the
light, the more the transistor turns on. Each IR LED draws 50mA. To conserve the robots batteries it is
recommended that they are only turned on briefly when a sensor is in use and then turned off again.

Although the same sensors are used on the main PCB and the smaller "Eye" PCB they are wired
differently. The eye has the phototransistors connected as four pairs, each pair connected in parallel.
This increases the sensitivity and allows the robot to "see" objects from a greater distance. The four
LEDs of the eye are connected together to form a single IR spotlight.

When the IR spotlight is turned on via a positive signal to pin 6 of the eye, IR light reflects off nearby
objects and turns on the IR phototransistors. This gives analog outputs on pins 2 (up), 3 (left), 4 (down)
and 5 (right). The voltage on these output will vary between 0V (pin 7) and Vcc which should be the
same voltage used by your microcontroller. As the object gets closer, more reflected light hits the
sensors and the voltage increases.

To make your robot track the movement of an object with the eye you must measure the difference
between left and right sensors to adjust the position of the left/right neck servo (pan). The difference
between up and down sensors is used to adjust the position of the neck up/down servo (tilt). The
program should position the servos so that the left = right and up = down. This will result in the robot
looking directly at the object. For smooth tracking to occur your program should slow the speed of the
servos as the left/right and up/down inputs become the same otherwise the head will not move
smoothly.

Sunlight and some indoor lights contain infrared light and can cause the robots sensors to malfunction.
Your program can correct this by reading the sensors with the IR LEDs turned off. By subtracting the
values obtained with the IR LEDs off from the values obtained with the LEDs on you can determine
how much of the signal is ambient IR and how much is the reflected light from the LEDs.
The sensors around the edge of the main PCB work the same way except they have only one
phototransistor each and each IR LED can be individually controlled. These sensors can face
downward to detect if the robot is about to go over the edge of a table or stairs. They can also face
outward to detect nearby objects. Although they are analog sensors, they can be connected directly
you processors digital inputs if they are calibrated properly.

To calibrate the sensors simply place a small piece of heat shrink over the phototransistor. The length
and position of the heat shrink will determine how much IR can be detected by the sensor. If a more
precise method of calibration is required then use a 10K variable resistor (potentiometer) as an
adjustable voltage divider.

A green indicator LED turns on at the same time as the IR LEDs on the main PCB. These green LEDs
can be used to show the status of the robot. Because the IR LEDs are only turned on briefly for
sensing, the green LEDs will appear to be on dimly during normal sensor use.

Infrared Communication
One advantage of using IR sensors on a robot is that they can also be used for communication. With
the IR LEDs being driven by TX (serial output) and the sensor inputs connected to RX (serial input) it
is possible for two or more robots to communicate with each other at close range.

Servo Control
Servos are a popular device to connect to a microcontroller and are found in many radio controlled
toys. A servo consist of a geared motor driven by a control circuit. This control circuit compares a
signal from a radio receiver or microcontroller with a sensor input (usually a potentiometer) to
determine the direction and speed of the motor to make the output shaft move to a certain position.
The greater the difference between the sensor data and the control signal, the faster the motor turns
to try and compensate. Mr. General uses two of these servos to position the eye.

Mr. Generals wheels are also mounted on servos but these servos have been factory modified. The
position sensor (potentiometer) has been replaced with 2 fixed value resistors and the gearbox can
now rotate continuously in both directions.

To control these servos a pulse between 1mS and 2mS is sent every 20mS. A 1.5mS pulse should
place the servo very close to centre position or in the case of the wheels, very close to stop. There will
always be some need for fine adjustment as no two servos are the same.

You might also like