This article is very old, from around 2006. It was originally published on my old website, flylab.ovh.org, now defunct. It’s unlikely to have much educational value. I’ve republished it mainly for sentimental reasons.
My first robot is based on a popular three-wheel layout (two driving wheels, one supporting wheel). The wheels are powered by two four-phase stepper motors taken from old 5.25” floppy disk drives. The chassis was made of strips of sheet metal. The robot does the following things:
- Rides forward, backward, left, and right. It can turn around in place.
- Follows the light source and tries to avoid obstacles.
- Can be controlled by an RTV IR remote controller or via cable through the RS-232 port.
- Measures the temperature with a precision of 1°C.
Gallery
Mechanics
Chassis
The robot has three wheels – two driving ones at the front and one rolling wheel at the back. The driving wheels are made on a lathe from a piece of hard rubber. The entire chassis is made of strips of steel sheet.
The supporting wheel at the back of the robot is a furniture castor, which you can find in any furniture or hobby shop. It needs to have a low rolling resistance since the floppy stepper motors are not very powerful. The motors are fixed to the chassis with 3 mm screws. In the photo below, I marked the dimensions of the chassis parts in millimeters.
The driving wheels are mounted directly on the motor’s shaft. As I mentioned previously, I used two four-phase unipolar stepper motors from old 5.25” floppy disk drives. These motors are used to move the read/write head in the floppy drive. You can see this kind of motor in the picture below:
Touch sensor
The touch sensor idea was abandoned after some testing. The sensor was made of a piece of copper wire soldered to a spring taken from a ballpoint pen. When the robot touches something, the wire shorts the contacts to the ground. During the tests, it vibrated too much and caused false measurements — the spring was too elastic. However, the touch sensor is still supported by the firmware.
Electronics
Motors driver
The driver’s schematic was copied almost verbatim from an article published in the Polish electronics magazine Elektronika dla Wszystkich (download the complete article). It was assembled on a 73 x 73 mm universal board.
Main board
An AVR family microcontroller, ATMega8 to be exact, is the brain of the robot. The microcontroller has 8 kB of program memory (FLASH ROM) and 512 bytes of RAM. This is enough to perform all the implemented tasks. The AVR family is well-known for its availability of developer tools and easy firmware uploading support through ISP (In-System Programming). The microcontroller has almost all the required subsystems integrated within the chip.
The photo of the 73 x 73 mm board on which the schematic is assembled:
As you can see, there are additional elements, such as microswitches and a DIP-8 socket, on the board. These were used during the experiments; the current firmware doesn’t support them. They are not shown in the schematic either. All NPN transistors are BC546, and PNP transistors are BC516.
Power supply
Three standard 3R12 4.5 V batteries, connected in series, are used to power the device. They provide about 13 volts for the motors. Despite this, the motors are quite weak. Power for the microcontroller and logic is supplied by the 5 V stabilizer on the driver board.
Light sensor and Analog-Digital converter
As light sensors, two photoresistors were used.
They decrease their electrical resistance when exposed to light.
Connected with 10 kΩ resistors, they form two voltage dividers.
The voltage from the dividers is measured by the AVR’s built-in 10-bit analog-to-digital converter and converted to numbers between 0 and 1023 in the firmware.
The stronger the light, the higher the result.
It’s important to connect the AD converter’s power supply pins properly, as described in the datasheet.
The VCC
pin is connected to the system supply through a simple low-pass filter made of a capacitor and a choke.
The reference voltage is set by the software to the supply voltage.
Finally, the AREF
pin is connected to VCC
.
DS1621 temperature sensor
DS1621 is an integrated-circuit digital thermometer with an I²C bus. There’s only one I²C device on the main board, but I added external goldpins, allowing the connection of additional ICs. The I²C line’s pull-up resistors were omitted because the AVR has internal pull-ups.
Infrared receiver
I used an IR sensor TSOP1836, with a native carrier frequency of 36 kHz.
The majority of TV remote controllers use this frequency.
Versions of this sensor for other carrier frequencies are also available.
The receiver’s output is connected to the hardware interrupt pin INT0
.
A low level on this pin triggers an interrupt.
RS-232 interface
The microcontroller has an internal hardware serial communication port (UART). Only a simple two-transistor voltage converter is needed to communicate with a PC via the traditional serial port.
In-System-Programming cable
Schematic of the dapa programmer cable for the parallel port. +5 V is taken from the legacy game port.
Microcontroller peripherals
The microcontroller peripherals are: the RESET button, ISP programmer connector, and crystal oscillator. The RESET is active in the low state, so a 10 kΩ resistor pulls it up to the supply voltage. It’s not strictly necessary, but it is indeed useful with the ISP programmer. A crystal resonator of 8 MHz is connected to the microcontroller in the standard way.
Firmware
The firmware was written in C, developed, and tested using the AVR-GCC compiler. The license is GNU GPL 2.0. Nowadays, it’s not very useful because it won’t even compile on modern versions of AVR-GCC. You can download the source code here.
Infrared remote (rc5.o)
This module is responsible for receiving and interpreting RC-5 commands from the standard TV remote controller. If you want to use another remote controller, e.g., from a VCR, you have to alter the numeric identifiers in the code. The remote controller buttons and commands:
1
— beep2
— go towards3
— turn on the light-following mode4
— turn left5
— stop6
— turn right7
— lights on8
— go backwards9
— lights off
Communication via RS-232 (rs.o)
Support for the internal RS-232 (UART) port of the microcontroller.
It contains functions rc_put
and rc_get
, which are responsible for sending and receiving single characters.
In the main.o module, the fdevopen
function is called with rc_put
and rc_get
as parameters, so you can communicate via UART using standard functions from stdio.h
, like scanf
and printf
.
The serial baud rate is 9600 8N1.
The robot accepts the following single-character commands via RS-232:
w
— go towardss
— go backwardsa
— turn leftd
— turn rightz
— stopx
— lights onc
— lights offv
— display the current temperatureb
— show values from the light sensorsq
— make a beeph
— show helpp
— microcontroller resete
— light-following mode
ADC converter (analog.o)
This module is responsible for handling the analog-to-digital converter built into the microcontroller.
The function convertanalog
takes the converter’s channel number as an argument and returns the measured value: an uint16_t
number in the range from 0 to 1023.
Control of the motors (naped.o)
A subroutine responsible for controlling the motors.
It contains the following functions: naped_przod
, naped_tyl
, naped_lewo
, naped_prawo
, and naped_stop
.
These functions simply set the appropriate pins of the microcontroller to the high or low state.
I²C procedures (i2c.o)
Functions like i2c_start
, i2c_stop
are included.
So far, only the ds1621.o module uses I²C.
Temperature sensor (ds1621.o)
Support for DS1621 temperature sensor via the I²C bus.
The function ds1621_temperatura
returns the measured temperature in degrees Celsius.
Searching for the light algorithm (poszukiwanie_swiatla.o)
A bit of dead-simple AI for the robot. The algorithm is responsible for finding and reaching the light source. The searching algorithm:
- Compare the intensity of the light between the left and right sensors and turn the vehicle towards the side where the light is stronger.
- If the values are equal within 30, move forward and remember the last value.
- After three seconds, measure the light intensity again. If it decreased, turn around 180° and return to point 1.
- If the value from the sensors is greater than 900, end the procedure and make a sound.
Main loop (main.o)
Main module, starting the whole system. At the beginning, all necessary procedures are initialized: interrupts, RS-232, IR, etc. Then, the processor enters the infinite loop and constantly checks the bumper’s state. In case of a collision with an obstacle, it backs off and notifies about it with a beep. Procedures responsible for interpreting commands sent via RS-232 and RC-5 are called by an interrupt triggered by the appropriate event.
Compiling and uploading the firmware
To compile the firmware source code, the AVR-GCC compiler and UISP programmer are needed.
To ensure the stability of the serial port communication, you need to switch the microcontroller clock signal source from the internal RC oscillator to the external crystal.
By default, the internal one is configured for 8 MHz.
Switching is done by setting the so-called fuses.
You have to set CKSEL4..0
in the Fuse Low Byte.
The best way to do this is to use UISP.
Here’s the appropriate command:
uisp -dprog=dapa --wr_fuse_l=0xef --wr_fuse_h=0xd9 --wr_fuse_e=0xff
To compile the firmware, in the source directory, enter the command make
, then make burn
to send the compiled program to the microcontroller.