/Modules and Components/

Ping Sensor

The Ping Sensor I used in the Robot 1 was a Maxbotix LV-EZ1.


These guys have a whole range of ultrasonic sensors for every occasion and you can see some of the differences here.


The LV-EZ1 is one of their more low end sensors. I paid about $30 for it, but it is still quite accurate. The only issue I had was with smoother surfaces on more than a 45 degree angle. The Ping didn't always register back, but that could be caught with a few design mods to the robot. maxbotix - lv-ez1


I attached it to a couple of servos in a bracket so that I could move it left and right and up and down to explore the area. I picked these up from a place called Robot Gear.


There are three modes you can use with the Maxbotix sensors - Analogue, PWM (Pulse Width Modulation), and Serial. I found the PWM method to be more accurate for my setup.


It's literally as simple as plugging in the Voltage and Ground lines to the appropriate pins, then hooking either the Analogue or PWM line to an analogue or digtial pin on your Arduino. I used PWM as I found it more accurate and I hooked it in to Pin 8.


Ultrasonic Ping Sensor from Maxbotix - LV MaxSonar


You can actually use the TX and RX channels to daisy chain up a number of sensors and save on PIN space. To have used multiple sensors on the Robot 1 would have solved my issue where the one sensor would bounce off a smooth angled surface. I could have hooked up a number of sensors on different angles to catch this.


The following is the sketch uploaded directly to the Arduino.


It basically sends out a 8 pings within half a second, averages the 8 results to accomodate for noise, and then sends the averaged result back to the Serial Monitor for you to see.




//Following code modified from original code by Author: Bruce Allen - 23/07/09

// Set up the constant variable to read in the ping. I have set this one to Digital Pin 8 on the Arduino.
const int pwPin = 8;

// Store these values to convert the pulse in to distance.
long pulse, inches, cm;

// variable for the final distance
int distSensor = 0;

// *********************************


void setup() {
  // Intitiate Serial connection for debugging and seeing the results live
// *********************************


void loop() {

  int i = 0;
  distSensor = 0;

  // Average of 8 conesecutive readings (within 1/2 a second) to accomodate noise      and error
  for (i=0; i<8; i++) {

      // Used to read in the pulse that is being sent by the MaxSonar device.
      pulse = pulseIn(pwPin, HIGH);

      // Pulse Width representation with a scale factor of 147 uS per Inch.
      inches = pulse/147;

      //change inches to centimetres
      cm = inches * 2.54;
      //add all 8 readings together
      distSensor += cm;

      // Wait for 1/20th of a second - 50 miliseconds

  // get average of the 8 readings
  distSensor /= 8;

  // send the results back to the console on the pc to review.


  // Wait for 1/2 a second - 500 miliseconds

// *********************************