Datasheet

Chapter 5 Tactile Navigation with Whiskers
158Robotics with the BOE Shield-Bot
Whisker Navigation Overview
The RoamingWithWhiskers sketch makes the BOE Shield-Bot go forward while monitoring
its whisker inputs, until it encounters an obstacle with one or both of them. As soon as the
Arduino senses whisker electrical contact, it uses
an if…else if…else statement to decide
what to do. The decision code checks for various whisker pressed/not pressed
combinations, and calls navigation functions to execute back-up-and-turn maneuvers. Then,
the BOE Shield-Bot resumes forward motion until it bumps into another obstacle.
Example Sketch: RoamingWithWhiskers
Let’s try the sketch first, and then take a closer look at how it works.
Set the 3-position switch to position 1.
Reconnect the BOE Shield-Bot’s battery pack to the Arduino.
Create, save, and run RoamingWithWhiskers.
Disconnect the BOE Shield-Bot from its programming cable, and set the power
switch to 2.
Put the BOE Shield-Bot on the floor, and try letting it roam. When it contacts
obstacles in its path with its whisker switches, it should back up, turn, and then
roam in a new direction.
// Robotics with the BOE Shield - RoamingWithWhiskers
// Go forward. Back up and turn if whiskers indicate BOE Shield-Bot bumped
// into something.
#include <Servo.h> // Include servo library
Servo servoLeft; // Declare left and right servos
Servo servoRight;
void setup() // Built-in initialization block
{
pinMode(7, INPUT); // Set right whisker pin to input
pinMode(5, INPUT); // Set left whisker pin to input
tone(4, 3000, 1000); // Play tone for 1 second
delay(1000); // Delay to finish tone
servoLeft.attach(13); // Attach left signal to pin 13
servoRight.attach(12); // Attach right signal to pin 12
}
void loop() // Main loop auto-repeats
{
byte wLeft = digitalRead(5); // Copy left result to wLeft
byte wRight = digitalRead(7); // Copy right result to wRight
if((wLeft == 0) && (wRight == 0)) // If both whiskers contact