In this entry, we will show you how to program an obstacle dodger robot. If your robot has an ultrasound sensor and a mini servo to move it, then you can program it to avoid obstacles. The PrintBot Evolution is the perfect tool for this kind of programming.
Don´t play with fire! Although we have this fantastical dragon skin, our robot will try to avoiding crashing and will move around any objects in its path.
How does the obstacle dodger work?
There are many ways to program a robot to dodge obstacles, but we will simply show you one of them. These are the tasks that the robot must perform:
- Taking measurements
- Detecting objects
- Executing movements correctly
Let´s take a look at each task in detail:
1) Taking measurements with an ultrasound sensor
First we will take 3 measurements using the ultrasound sensor: one to the left, one to the centre and another to the right.
![]() |
![]() |
![]() |
We are basically measuring the distance to the object in front of the sensor. This simply requires us to change the position of the sensor to face one side when we rotate the head. We can change the direction using a mini servo.
2) Detecting objects to determine how to react
![]() |
If there is no obstruction less than 25 cm ahead of the robot, we will program it to make an OK “Beep” and we will be able to go straight ahead. |
![]() |
In contrast, if there is an obstruction less than 25 cm ahead, it will make an error beep and we will have to check if we can dodge it by moving to one side. |
![]() |
First let´s see if we can dodge to the left. If there is no obstacle less than 25 cm ahead on this side, then we can move to the left. |
![]() |
If we can´t move to the left, we will see if we can dodge it by moving to the right. |
But… What happens if all three directions are blocked? Then we can program it to make a warning sound:Uh-Uhhh, obstruction ahead! Access denied!As it´s trapped, we will need to make the robot go back and then change direction, for example, by rotating to the left. | ![]() |
3) Executing movements correctly
For the last step, all we have to do is move the wheels of the robot to describe the path decided in step two.
Let the motors roll!