Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Using a Pololu carrier with Sharp GP2Y0D810Z0F

The following is to hopefully describe where I am at and the issue I have.

I have been building an Arduino based robot for the last year or so. All has
been working quite well until I wanted to use a digital sensor to work in close
range, 4 to 6 inches, situations. I am aware that the Sharp GP2Y0D810Z0F w/Pololu
carrier will not give an exact distance, rather if an object is not in its range
will give a HIGH or a LOW when an object is sensed.

Using the following code I get what I see are expected results…

This gives me:

void loop() {
 
Serial.print("Digital Signal 6:");
Serial.println(digitalRead(6), BIN);

= the following output:

Digital Signal  6:1 - when the sharp s810 sensor does not see anything
Digital Signal  6:0 - when the sensor sees an object in the appropriate range.

My intent is to use the above data, if a sensor 6, 7, OR 8 (or how many sensors
I am using) that outputs a LOW means an object in its range and execute some
arduino code to direct my robot to avoid a the obsticle, nothing if the output is a HIGH.

Well, I am sure that you are saying “so what is your issue?”

The issue is I must be missing some code that I do not understand. I wish to be able to
do what I can do with my analog ir sensors, for example:

#include <SharpIR.h>

SharpIR sensorA1( SharpIR::GP2Y0A41SK0F, A1);  // 4 cm to 30cm
SharpIR sensorA8( SharpIR::GP2Y0A41SK0F, A8);  // 4 cm to 30cm
SharpIR sensorA4( SharpIR::GP2Y0A21YK0F, A4);  // 10cm to 80cm

void setup()
{
  Serial.begin( 9600 ); //Enable the serial comunication
}
void loop()
{
  
  delay(200);

  int distanceA4 = sensorA4.getDistance();
  Serial.println(distanceA4);

  delay(200);

  int distanceA1 = sensorA1.getDistance();
  Serial.println(distanceA1);

  delay(200);

  int distanceA8 = sensorA8.getDistance();
  Serial.println(distanceA8);
  
  if (distanceA4 >= 50) {
    FASTFORWARD(); //Move quickly when no object or wall is close
  }
  else if (distanceA4 >= 20) {
    SLOWFORWARD(); //Cut speed when object/wall is close
  }
  else if (distanceA1 > distanceA8) {
    CCW();       //rotate left to avoid object
    delay(4320); //180 degrees continue 'till next sensed object
  }
  else if (distanceA8 > distanceA1) {
    CW();        //rotate right to avoid object
    delay(4320); //180 degrees continue 'till next sensed object
  }

I know there are some code pieces missing here, but this snipet of code works
perfectly running a group of 3 Omni wheels giving my bot very precisemovement.
NOW comes my ignorance, I have no idea how to code the results given
by the s810 sensors into proper movement instructions for the short range issues
I am attempting to address!!

Oh, and please don’t just suggest I use a different sensor. I have invested in
12 - sharp GP2Y0D810Z0F sensors with matching carriers at $114.24. They should
work, I just cannot figure the code. Well, actually, they do work but my thinking cap is
kind of busted concerning the correct code. ;-(

Thankyou for listening to my ramblings. :slight_smile:

Hello, Oldred.

I moved your post to the “Sensors” section of the forum since it is about the GP2Y0D810Z0F digital distance sensors.

It is not clear to me what kind of behavior you want or how the code you posted relates to the digital distance sensors. Could you try rephrasing your questions and posting specifics details about what you are having problems with?

Are you trying to replace your analog sensors or add the digital sensors to what you already have? It might help if you gave an explanation of how your robot behaves now with your current code and how you want it to work when you use the digital sensors.

Brandon

I guess I failed at explaining my issue. I am not attempting to replace my other sensors. I want to use the new sensors as an addition to the existing ones.

What I am having issues with is no matter what I code I cannot “tell” the robot that the digital sensors (a LOW) have determined something in its path and move to avoid the obstacle.

I hoped the additional code I provided showing the code I use with the analog sensors indicates I desire the same behavior to occur when the digital sensors are LOW. I know I get “distance” information with the analog sensors and only a LOW or HIGH from the digital ones. I simply am trying to write code that allows the Arduino “see” the sensor is outputting a LOW and take evasive maneuvers.

What I write does not function as I expect… example:

if (digital6 = LOW) {
     RIGHT(); //turn right
    }

Does not result in any movement!! No matter how many different ways I code a LOW sensor output! I would hope reading the Analog code gives some idea that I use the Analog output to make the robot move to avoid object, I just want the LOW output to give a similar effect.

Where with the Analog:

else if (distanceA4 >= 20) {
SLOWFORWARD(); //cut speed
}

Works just fine. But not with a 6" distance.

To answer your last question the configuration of the Analog sensors functions very well. My system can run into small blind spots, I simply want the short distance sensors to pick that up to avoid collision.

If this does not help I will send the complete code that works.

Thanks for listening.

You should be able to use the sensor’s digital output like you are saying and simply check it with an if statement. If that is not working for you, I suspect the problem is with your code, so you should post the version of your code that includes your attempt to integrate the digital sensors.

By the way, just in case your example code from the previous post is accurate, please note that you should use == in if statements instead of =. The == operator is for comparisons while = is for assignment.

Brandon

Brandon,
I appreciate your comment about == vs. = in an if statement. I actually fixed that as I do understand the difference… don’t know what happened to my brain after I added the digital sensors oh, well… :roll_eyes:
Thanks!

1 Like