Introduction: ATtiny13A Line Follower

About: Make it yourself if you cannot buy one ;)

Create a robot with ATtiny13A is a challenge, it only have 1k flash and 5 IO pins. But it is good enough to create a tiny line follower.

Youtube demo video: https://youtu.be/00PYO1ThzEA

Step 1: Prepare Hardware

MCU

Today core subject, ATtiny13A. ATtiny13A have different package, I am using DIP8 one, i.e. ATTINY13A-PU.

A DIP8 IC holder

For easier unplug the MCU for reprogram, it may occur hundreds times.

Programmer

I am using a USBtinyISP, but any compatible ISP should be ok. Many page show how to use an Arduino to program the ATtiny.

Power source

A rechargeable battery, LIR2032, it is small but still can provide enough current to drive the motors.

20mm coin cell holder

For holding LIR2032.

A tiny power switch

For easier turn off the robot without unplug the battery.

Left and right light sensors

Actually, at the beginning, I want to use IR emitter and sensor pair. However, after test three pairs from different vendors, I found the readings is very depends on the distance but not the color. So I changed my mind and selected Light Dependent Resistor (LDR)

Left and right Pull-down resistors for light sensors

I found many post on the web use 10k ohm pull-up or pull-down resistor, but I found 47k ohm resistor have a better readings, so I choose it

Light source

White LED, 5mm with straw hat is preferred, because we need a wide-angle light source.

Resistor for the light source

A white LED can consume tens of MA but it is overkill since line follower only require light source for a few mm distance. So add a 5.1k ohm resistor for reduce power consumption, the resistant value very depends on the LED performance.

Left and right motors

The most power consumption is come from the motors. According to ATTINY13A specification, the maximum DC Current per I/O Pin is 40 MA. For simplicity, I don't want any extra transistor to drive the motors and also LIR2032 cannot provide too much power to do that. So I choose a tiny motor that only consume around 20 MA.

Wheel

Since I don't want to add extra gears, the wheel should as small as possible to reduce required torque and reduce power consumption. The wheel design is come from Shlonkin.

Front wheel and chassis

In first run, I just treat the LED as front wheel. It run smooth on the white paper and many surface but hard to run on the line. After few days trial, I found it is caused by the sticky surface produce by the marker ink. I have try a few front wheel design, but hard to move forward, left and right smooth at the same time. Finally I use a 8 mm steel ball to make it. It is very easy to glue the motors by hot glue, but since I cannot direct glue the steel ball as a front wheel, and lucky I can use a 3D printer right now. So I printed a chassis for the motors and front wheel. If you also can use a 3D printer, you may try to print it here.

A multipurpose PC board

It require a 6 x 5 holes multipurpose PC board to stick all parts together.

Step 2: Prepare Software

Compiler and programmer

I am familiar to Arduino in other previous project, so simply use it.

Add ATtiny13A support

Arduino need extract source for ATtiny13A support. more detail can be found in instructables by diy_bloke.

Step 3: Stick All Parts Together

I have draft a very low quality circuit for soldering on the multipurpose board. Since it is very simply, I think it is good enough.

Here is the summary for the connection:

  • PIN 1 - not connected
  • PIN 2 - left light sensor with pull-down resistor (light sensor other side connect to VCC and resistor other side connect to GND)
  • PIN 3 - left motor (test the motor turning direction before soldering, it should turn counter-clockwise, motor other side connect to GND)
  • PIN 4 - GND
  • PIN 5 - not connected
  • PIN 6 - right motor (test the motor turning direction before soldering, it should turn clockwise, motor other side connect to GND)
  • PIN 7 - right light sensor with pull-down resistor (light sensor other side connect to VCC and resistor other side connect to GND)
  • PIN 8 - VCC
  • LED PIN - long PIN connect to VCC and short PIN connect to resistor and then GND

Step 4: Install Chassis

I am using the 3D printed chassis, it makes all easier. If you cannot access a 3D printer, it can simply glue by hot glue or blu tack.

I think 8mm steel ball is overkill, but I did not have a smaller ball in hand. If you don't have one, treat the LED as front wheel is fine on smooth surface. The route drawing by a marker pen is sticky, printing route by laser printer should be smoother.

Step 5: Program Code

Program code splint in two parts. if uncomment "#define testrun", it only test run the motor ability; comment it return to the normal flow.

Program steps:

  1. Download and open the attached ino file, it may prompt create program folder alert, simply accept it.
  2. Select Tools menu -> Board -> ATtiny13A, 600 kHz - 1.2 MHz is fine
  3. Press the tick button to compile the code
  4. Connect your ISP and select Tools menu -> programmer -> your programmer
  5. If everything ok, press the upload button

Reference:

https://blog.adafruit.com/2009/11/21/how-to-progra...

https://www.instructables.com/id/Programming-an-ATT...

https://learn.sparkfun.com/tutorials/tiny-avr-prog...

Step 6: Test Run and Tuning

The motor ability is the biggest variant in this project, so it should first test it before using the light sensor.

  1. Program to test run mode.
  2. Connect MCU and battery.
  3. Turn it on and place it to a white paper (or any surface you would like it to run).
  4. The test run try to turn left and right in 3 level, then dash and turn, and then dash only.
  5. Check the dash can run in a straight line, if not, try to define LEFTDUTY and RIGHTDUTY to make it.
  6. Check the dash and turning ability and fine tune the figure. (Hint: you should find some figures, the value to turn around 15-30 degree, the value to dash a half the robot size and then turn a right angle. It can help to keep track on the line and how to land the line when first find it.
  7. Then place the robot on the middle of the prepared track.
  8. If the robot seems cannot detect the line, try to adjust the value of the THRESHOLD (0-64), I think 56 is reasonable.
  9. Show it to your friends and kids.
  10. HAPPY PLAYING!!!