Introduction: ATtiny13A Line Follower

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!!!

Comments

author
bwantha (author)2016-11-29

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

author
陳亮 (author)bwantha2016-11-29

try older version

author
YUSUF6731 (author)2016-07-20

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

author
陳亮 (author)YUSUF67312016-08-28

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.

author
haminhtranhanh (author)2016-08-28

Hi there,

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

author
陳亮 (author)haminhtranhanh2016-08-28

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.

author
ZipDriveRT (author)2016-03-29

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

author
陳亮 (author)ZipDriveRT2016-03-29

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: https://m.instructables.com/id/ATtiny85-Ring-Watch/

author
Jfieldcap (author)2015-12-28

Wow. Great job!

author
aequanimitas (author)2015-12-26

nice project, thanks!

author
Scramblbot126 (author)2015-12-01

Thanks!

author
Scramblbot126 (author)2015-11-30

Did you program the ATtiny with the arduino?

author
陳亮 (author)Scramblbot1262015-11-30

I am using USBtinyISP

author
陳亮 (author)2015-11-30

I am using USBtinyISP

author
DaveHee (author)2015-11-17

would the attiny 45 work

author
陳亮 (author)DaveHee2015-11-17

yes, sure! ATtiny45 is the same series but have 4 times of flash. You can write more complicated logic for it.

author
jqvr (author)2015-11-07

It's a beauty! I like the minimalistic approach. Please post a video of it running.

author
陳亮 (author)jqvr2015-11-07

posted

author
DylanD581 (author)2015-11-07

Cool Electronics and 3D Printing Project! Uploading the 3D-Printed Chassis to the Instructable Would Benefit Everyone!

author
陳亮 (author)DylanD5812015-11-07

done

author
Starsword7 (author)2015-11-07

Cool instructable!

could you post a video of it in action?

author
陳亮 (author)Starsword72015-11-07

I actually already attached the m4v video file before, I have just found instructables video feature still "coming soon". So I have put it on the Youtube.

author
grayl (author)2015-11-06

Can you tell us the specs on the motor you used?

author
陳亮 (author)grayl2015-11-06

motor body 12mm long, 4mm diameter. 60000rpm, 0.04A. I have measured the current, it consume below 25 MA without load.

author
grayl (author)陳亮2015-11-07

I actually wanted to know where you bought the motors. Thanks for the specs.

author
陳亮 (author)grayl2015-11-07

It usually used for vibrator, you may try to google "tiny motor" in image mode for more details.

author
Mic100 (author)2015-11-06

Very nice idea :)

easy to build can you post a video please
I made a robot that looks like him with detection by IR


https://www.instructables.com/id/Mini-2-wheel-robot-with-IR-sensor-weight-14gr-and-/

author
seamster (author)2015-11-06

Very cool! Nice, simple little robot. Very well done, thanks for sharing!

About This Instructable

9,794views

202favorites

License:

Bio: Do it yourself if you cannot buy it!
More by 陳亮:Develop ESP32 With PlatformIO IDEPortable WiFi AnalyzerIoT Power Consumption Concern
Add instructable to: