<!-- 
.. title: Building my first robot
.. slug: building-my-first-robot
.. date: 2014-06-19 20:51:14 UTC+02:00
.. tags: robot, atmega32u4
.. link: 
.. description: 
.. type: text
-->

This month I created my first [robot](https://github.com/atteroTheGreatest/robocar).

I love creating projects. Usually they are just a software, but this time it
was different. I wanted to dive into hardware. I knew some electronics, I had
a few courses in electronics on university, both analog and digital electronics.

Recently I finished an edX course: [embedded - shape the world](https://www.edx.org/course/utaustinx/utaustinx-ut-6-01x-embedded-systems-1172)
where I had to write programms for Tiva launchpad. It was a bit tedious, but also a lot of fun.

I decided that I want to to use my new skills to create something awesome... a robot.

A `robot` is a pretty broad definition ![robot](http://blog.spoongraphics.co.uk/wp-content/uploads/2011/robot/robot-character.jpg).

My project had a following requirements:

- be able to ride autonomously
- avoid to obstacles
- have a proper documentation

Those requirement doesn't sound impossible. But how do we start?

###Components

What do we need to create a robot?

- brain - chip to control a robot
- motors with drivers
- sensors to gather information about an environments
- chassis

I used atmega32u4 as a brain of my robot.

- it's pretty easy to use
- it's well documented
- it's pretty cheap
- it has USB and easily programmable
- I already had an arduino board with atmega32u4

It's parameters aren't very impressive, but chip is okay for most use cases of
begginers.

I wanted a simple chassis and didn't want to create it from scratch, so I bought
sparkfun [redbot chassis](https://www.sparkfun.com/products/10825). It's quite
cheap and works just fine. It also had simple DC motors.

Apart from chip, chassis and motors I used a simple distance sensor:

[distance sensor](https://www.sparkfun.com/products/10825) mounted on servo.

It created a radar which I used to scan my environment.

###Design

I didn't have a concrete project design. It was developed in small iterations.

The final circuit design looks like this:

![circuit](https://camo.githubusercontent.com/dd7a75f24fee1ab5e024868c62b6b1606ea20b42/687474703a2f2f692e696d6775722e636f6d2f484a554f6c48672e706e67)

###Short deadline

I wanted to finish this project and do it fast. I set myself a goal to finish
it in three weeks and after those three weeks open source its code and show
the robot to the world.

Having a short deadline was a very good decision. Of course, if I had more time
I would probably made some things better, but would I finish it? I don't know,
probably not.

It was a bit crappy and wibbly-wobbly, I used duct-tape and zip-ties but learned
a lot.

I open sourced on the last day, wrote about it on warsaw-hackerspace mailing list
and showed people live. I had a great feedback.

Now, after my first iteration I know something about robotics!

For my next project I would probably used more advanced microcontroller, such as
for example tiva launchpad, because I ran out of timer on my small atmega.

I would probably use another sensor, because after I open sourced my code, some
people told me that there are much better alternatives which give better sensor
data.

Writing documentation and open sourcing my code gave me a lot of satisfaction.
My code is now useful for other people and I have a robot: 

![zenon-bot](http://i.imgur.com/35FpQ5d.jpg)

Observing it is a lot of fun, it's a bit clumsy but also cute :).

