Cliff Avoider

Views: 7331 Difficulty: 3 Status: Complete

Two proximity sensors help this bot avoid cliffs.

Proximity sensors extending out from both sides of this robot ensure there is ground to roll on. If one sensor detects a drop-off the robot turns int the other direction. If both sides detect a cliff then the robot gets very anxious. The result is a perimeter following behavior that emerges from the simple rules of turning away from edges and going striaght if no edges are detected. Like many of our bots, this cliff avoider makes ample use of the binary proximity sensor from pololu.

Plexi Body

The plexi glass body has two broad wings that house the proximity sensors. These sensors extend out in front of both wheels and ensure that the bot doesn't take a nose dive.


This bot tries to stay on the table without any human help. Corners are tricky as the two sensors sense danger in both directions. Notice how the simple behaviors of turning to avoid edges leads to a more complex behavior of following the perimeter of a shape (as long as that shape is convex).

Arduino Code

Control a servo robot using differential steering based on two binary proximity sensors. The robot exhibits a somewhat emergent behavior of avoiding cliffs, and following convex perimeters. This arises from the interaction between three rules:
  • If there are no cliffs go straight
  • If there is a cliff to the right, turn left
  • If there is a cliff to the left, turn right
Notice there is no rule for what to do when there is a cliff on either side. In the video you can see how this presents problems at corners. Can you make this code better? Let us know how in the comments!
/* LucidTronix Cliff Avoider Servo Bot 
 * Control a servo robot using differential
 * steering based on two binary proximity
 * sensors. avoids cliffs, and follows
 * convex perimeters.
#include <Servo.h>  
Servo right;
Servo left;

int leftSensor = 0;
int rightSensor = 1;

void setup() {
  pinMode(leftSensor, INPUT);


void loop() {
  int leftIn = digitalRead(leftSensor);
  int rightIn = digitalRead(rightSensor);
  if (rightIn == HIGH){
    right.write( 45 );
  else if (leftIn == HIGH ) {
    left.write( 165 );
    right.write (165 );
  else {
    left.write( 165);   
    right.write( 65 );

Download EAGLE files and code

Zipped archive of the EAGLE files and the arduino code.
Click Here to Download: Download EAGLE files and code


Title Description # Cost Link Picture
Servo Motor Continuous rotation servo motor. 2 $13.95 Link 09347-1
Proximity Sensor Digital proximity sensor. 5v Value: 5v 2 $6.95 Link 0j1178.600
Servo Wheel Wheel that attaches easily to servo motors. 2 $4.0 Link Servowheel_lrg
ATMEGA168A-AU IC MCU AVR 16K FLASH 32TQFP Value: 1.8 V ~ 5.5 V 20MHz 1 $2.43 Link Screen_shot_2012-12-28_at_7.31.53_pm
Crystal CRYSTAL 16.00000 MHZ 20PF SMD Value: 16MHz 1 $0.53 Link Ecs-270-20-3x-en-tr
Resistor Chip Resistor - Surface Mount RES 10K OHM 1/8W 5% 0805 SMD Value: 10k 1 $0.1 Link Screen_shot_2012-12-28_at_7.29.44_pm
Wall-ter is a wall following robot....
Light sensors guids this robot towards the light....
Servo motor, JPEG camera, and Arduino Leonardo combine to make a panoramic camera....
Control a 120v outlet with a 5V arduino....
Write messages on Liquid Crystal Displays with potentiometers or keyboards....
Rainbow flower necklace using the TLC5940....
Wearable digital compass displays the direction in green LEDs....
Arduino-powered spherical camera with 2 Servo Motors and an SD Card....