Posts | Comments

Planet Arduino

Archive for the ‘Parallax Ping ultrasonic sensor’ Category

Lil Herbert - Beginner Robot

Lil Herbert - Beginner Robot

Contest entry by Annie (note: was submitted within the deadline, I wasn’t able to add to the blog until today)

In September of 2009 I found myself in a learning mood.  Throughout my life I have been fascinated by everything: science, math, history…you name it, I love to know about it.  In September I decided I was going to brush up on my electronics knowledge and see where it would take me.  I had studied electronics at a tech school during the 90s and I’d grown up in Silicon Valley so I wasn’t completely new to the endeavor.  But upon graduation from the tech program I immediately began working on computer network support and Key System/PBX telephone system programming rather than the nitty gritty world of capacitors, resistors and ICs and found my understanding of it all both fading and lacking.

As I practiced building little 555 timer and 386 audio amplifier circuits, I soaked in as much information as I could from forums and online electronics articles.  It was then that I began hearing   about something called Arduino.  Arduino?  What, pray tell, is an Arduino?

A pizza, perhaps?  As in “I’ll have a large pepperoni and Arduino with extra cheese!”  No, that wasn’t it.  Arduino…hmmmm.

A new Italian sports car?  “The new 2010 Arduino Coupe, 0 to 60 in 200 microseconds” (Of course with a little disclaimer at the bottom explaining that the Arduino driver is a pro, so kiddies, don’t try this at home!).  Well, that wasn’t it either.

A quick search of Wikipedia and then Amazon was my road to Damascus. I had found a microcontroller that was cheap, extremely easy to learn, a massive open-source community to hold my hand as I dipped my pinky toe into the microcontroller waters, and a seemingly unending variety of applications and add-ons.  By October 9th I had my first Arduino.  A Duemilanove.  It was (and still is) a thing of beauty in my eyes.

After a week of the usual “Hello World” blinking LED type projects, I decided I needed a long term project to build upon and to hone my skills.  Thus, Herbert was born.

Herbert started out with a discussion I had with my mom.  I was thinking of  some goals to set to help me learn all of the different aspects of micro-controller use.  I wanted to learn to write code.  I wanted to continue my work designing and building circuits.  I wanted to practice my soldering skills.  A robot project was the answer!

The goals for Herbert were these:

  • Start from scratch.  To really understand the workings of Herbert I needed to build him from the ground up, no ready-made kits.
  • Have the Arduino control his movement; he must start out with simple forward, backward and turning motions autonomously.
  • Add sensors to let Herbert see the world.  His first sensor is a Parallax Ping ultrasonic sensor, but eventually he will have many different types.
  • Through code of my own creation, have Herbert avoid collisions by turning, stopping or reversing.  I felt it was important for my educational development to create my own code rather than borrow someone else’s.  I have seen some fancy avoidance programming out there that I admire greatly.  But I knew if I didn’t start from scratch I would miss out on the joys of failure.

Have Herbert be a long range project.  I decided that he could be open ended.  As I solve one set of obstacles, I can move on and add new features.  Someday Herbert will talk, tell me the weather, read me my email and play songs off my computer for me.  It’s all just one step at a time.

The Basics

Robot Chassis

Robot Chassis

I started building in late October.  I received an early Christmas present in the form of 4 motors, 4 wheels and a chassis.  I decided to focus on a pulse width modulation circuit design to control the  independent speed of each motor.  After much studying on the web,   I built a circuit with 4 Darlington transistors to control the current   through the motors with the Arduino pins controlling the current  through each motor.  In addition, I added 4 reversed biased diodes to      protect the Arduino pins from kick-back voltage.

Schematic

Schematic

This circuit worked great for my first foray across the living room floor.  I could change the motor speed by changing the PWM in the Arduino sketch and soon I had Herbert zipping around scaring the dogs.  I decided it was time to give him some ‘eyes’.  While shopping for parts at Radio Shack one day I stumbled upon the Parallax Ping))) Sensor.  It is an ultrasonic sensor that was perfect for what I was doing.  With only a 5v, Gnd and Signal pin, I knew I could get it up and running with the Arduino!

I modified my code and put the signal for the Ping sensor on pin 9 of the Arduino.  I attached the 5v and Gnd of the sensor to the respective spots on the Duemilanove.  At this point I broke from my stated goal of always writing my own code.  The truth is, I had not the slightest idea how to write my own functions at this point, let alone libraries.  Luckily, the Arduino IDE saved the day!  In Files-Examples-Sensors there is a sketch for the Parallax Ping))) sensor.

After testing the sensor on a breadboard, I wired it up on Herbert.  I then took the important parts of the Ping))) sketch and added them to my current working sketch.  Herbert saw the light and was on the move!  I had him driving forward, detecting objects in front of him and turning to avoid them.  Granted, my code needed polishing but it was a start!

At this point my goal was to have Herbert move forward.  If he detected an obstacle he would stop and sweep his ping sensor to the left and take a measurement.  Then he would swing the sensor to the right and take another measurement.  He would then compare the two to decide which was a clearer path.  I wrote the sketch and it worked….once.  Somehow I had run into my first major bug and I was at a loss to figure it out.  Herbert was acting strange, not responding correctly and dancing around like a madman.

With little time before the contest deadline and wanting Herbert to make an appearance, I decided the strange problem must’ve been something to do with the cheap wheel motors I had (they had been giving me problems now and again already) and so I quickly ordered  4 Solarbotics GM13a 150:1 mini metal gear motors and tires to match.  They are much smaller than the no-name motors I had been using, but they are quiet and nice!  Herbert became Lil’ Herbert.

I rebuilt Herbert with the new motors and wheels and ran into the same strange behavior.  Obviously the motors weren’t the problem.  I’m sure I now know what it is, and I will experiment after the contest deadline to see if I am right.  I’ve been using an Adafruit Minty Boost to power the Arduino.  It’s a little circuit that converts the 3 volts from 2 AA batteries to 5 volts and sits in an Altoids tin on Herbert’s chassis.  I now believe that having the Arduino power the ping sensor, a sweeping servo and itself is just too much for the Minty Boost, causing strange things to happen.  But, as I was running out of time, I chose to forego the sweeping of the servo until after the deadline.

So, this is where we stand.  Or where Herbert rolls as it were.  I was still using my transistor circuit to power the motors and pinging to avoid collisions.  The main problem with this setup is that the motors’ current could only go one way.  I was able to drive Herbert forward and turn him, but he couldn’t reverse or turn on a dime.  At this time I decided that I knew enough about my transistor circuit/motor setup that I could investigate motor controller boards.  I knew I could build H-Bridge circuits to allow the motors to drive either direction, but I felt the compact nature of some of the control boards I had been looking at would help me keep Herbert compact.

So into the picture came 2 Pololu Qik 2s9v1 Dual Serial Motor Controllers.  They are little, efficient and allowed me to have Herbert go forward or backwards.  I once again sacrificed my vow to write my own code and used a library specifically for these boards.  My only trouble was the code was written for one board only, and I had two.  I fumbled my way through making 2 instances of the library and all was well.

As I write this it is 3:30 PM on December 31, 2009.  I have reached the contest deadline and can do no more.  Herbert can currently sense obstacles in front of him and turn to avoid them.  He can move forward and backward.  Sadly, there was no time to resolve his neck sweep issues in time.  But as Herbert travels around the house in the coming months he will be doing more and doing it more efficiently.  I will keep adding new videos to my You Tube page and Herbert will continue to annoy my dogs.

I have included two versions of Herbert’s sketches in the zipped folder.  One is from the early days of the transistor circuit, and the other is from this very day with the motor controllers.

Herbert’s videos can be seen on my You Tube channel.  The first one, Herbert is Born, was from November.  The most recent is Lil Herbert.

Videos: http://www.youtube.com/profile?user=AnnieNakki#g/u

Share/Bookmark


  • Newsletter

    Sign up for the PlanetArduino Newsletter, which delivers the most popular articles via e-mail to your inbox every week. Just fill in the information below and submit.

  • Like Us on Facebook