O'Reilly logo

Make an Arduino-Controlled Robot by Michael Margolis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10. Autonomous Movement

This chapter describes how to use a distance sensor to enable the robot to see and avoid obstacles as it moves around. The first sketch, named myRobotWander, drives the robot forward, and if it detects an obstacle, it stops and rotates the robot to try and find a clear path to move forward. Another sketch, named myRobotScan, adds a servo that can rotate the sensor so the robot can look left and right without having to twist itself around.

Hardware Required

Connect the Ping sensor and servo the right way around; the black wires (ground) go nearest the pin marked -, the white (or lighter color) signal wire goes nearest the pin marked S (Figure 10-1).

Ping sensor and servo plug into pins on the motor shield

Figure 10-1. Ping sensor and servo plug into pins on the motor shield

Sketches Used in This Chapter

myRobotWander.ino

Uses a SONAR distance sensor (the Ping sensor) to enable the robot to see and avoid obstacles as it wanders around. #defines are added for front and rear obstacles (only the front is implemented in the sketch), the look module has added support for distance sensing. This sketch introduces a new tab, named Distance, which contains the Ping sensor code that you originally saw in Sonar ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required