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:

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Prepare Hardware


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.


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.


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


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.

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    33 Discussions


    3 months ago

    I know this comment is 4 years late, but I have to say this is the coolest, best line follower robot I've seen on Thank you for sharing it.


    10 months ago

    Where did you buy your motors from? I can't find 20 milliamp motors.

    1 reply

    Reply 10 months ago

    may be you can find some in old mobile phone.


    1 year ago

    Is it possible that the motors are wrong connected in the schematic, normally one side of the motor is min and not +

    1 reply

    Reply 1 year ago

    Hi Sembot, it just depends on the which battery pole connected to the switch. The battery holder +ve pin out easier connect to the switch, so the motors connect behine the switch is +ve. If you want to reconnect it to -ve, remember revise the code high/low level.


    2 years ago

    this sketch use 3 kb attiny13A flash memory 1kb so this sketch not uplorded plese help us

    1 reply

    3 years ago

    Hello maker,I wanna know that can ATtiny13A can be programmed via ARDUINO IDE ?

    1 reply

    Reply 3 years ago

    Hello, sorry for late reply. It is logically yes. However, ATtiny13A only have 1k flash, the Arduino Blink example binary already use up over 800 bytes. It is a big challenge to fit your program in it.


    3 years ago

    Hi there,

    Nice stuff to play around. Would you please tell me how long the battery serviced? Thanks!

    1 reply

    Reply 3 years ago

    I have not tested it, since I just play a few round every time. But I have never recharge the battery in the developing period and never encounter battery exhaust.


    3 years ago

    very nice, now do you know off hand if this attiny has connections for IMU MPU6050 ? (SCL & SDA ?) i need this type of chip and at lease 4 analog output pins with one or two inout pins

    1 reply

    Reply 3 years ago

    hi, I don't have much knowledge about MPU6050, but I have another instructables use ATtiny85 connect to I2C OLED display. You may take a look:


    3 years ago

    I am using USBtinyISP


    3 years ago

    would the attiny 45 work