Connecting the Sharp Distance Sensor to the m3pi

I’ve started working with my batch of 6 m3pi’s and oh are they awesome.
But, I’d like to connect a sharp short distance sensor on to the mbed.
I actually have no idea where I need to plug all three of his cables. I tried extrapolating according to the 3pi wall follower but if I understand correctly connecting the sensor to the PC5 will disable my line following sensors.
So, can anyone give me a short tutorial as to where exactly I need to connect the sensor’s cables?

Thank you very much,

Hello, Uriel.

Are you talking about the Sharp Distance Sensors (SDSs) with analog outputs that Pololu sells? For the rest of this post, I am assuming you are.

On the m3pi, connecting the distance sensor to the 3pi directly will require modifying the 3pi’s software because it does not have a command to take and relay analog readings to the mbed. You would have to write that software yourself. The easier and probably more performant way to connect the distance sensor is directly to the mbed. If you prefer modifying the 3pi serial slave program, let me know and I can help you with that.

On the m3pi the analog inputs (pin 15 through pin 20) are used as LED outputs, so you will have to modify the m3pi to disconnect the LED circuit from the mbed. A description of the LEDs is in the m3pi user’s guide. Desoldering the 470 ohm resistor (the resistors that are connected to the m3pi via the red traces in the picture below would be a good way to disconnect the circuit. Save the resistor in case you want to restore the LED circuit! Also, in general, desoldering is harder than soldering so make sure you know how to desolder things before attempting it.

After you’ve modified your m3pi, here are the connections I recommend:

  1. SDS GND to m3pi GND
  2. SDS Vcc to m3pi VCC
  3. SDS Vo to the mbed analog input you disconnected the LED circuit from

Then you would use the mbed AnalogIn library to read the sensor.

- Ryan

Hello Ryan and Uriel
I have both 3pi and m3pi and would like to mount my two GP2Y0D805 seniors with carrier boards to one of the robots if possible. I’m not sure with one? So that the robot can detect objects when they are running the maze program. Say on the left front and right front of the robots
Thanks Gary

Hi Gary.

I’m not sure what you’re asking as the only question in your post seems to really just be a statement with a question mark on the end. Is there something specific you are confused about?

- Ben

Hello Ben
3pi is robot that I would like to hookup the sensors to. I found most of the info on your website except for how to setup code in the maze program.
Thanks Gary

You still haven’t actually asked any questions. The maze example code we provide is intended for use with a line maze and uses the 3pi’s reflectance sensors. If you want to instead run in a walled maze using distance sensors, you will need to make substantial changes to the sample code, and while we can give you feedback on your attempts, we cannot provide this code for you. If you are just trying to detect obstacles while exploring a line maze, you need to better explain what you are trying to do and ask specific questions about what you’re stuck on if you want some help.

- Ben

Hello Ben
Again my apologies
What I needed was to fine out the physical layout on 3pi for the two seniors, I did after taking a hard look at the forum, so that problem is done. And yes I’m trying to detect obstacles then exploring a line maze. This is for a larger robot that I’m building to work in a warehouse moving stuff from point A to point B and avoiding People along the way. I build small at first then go Big.

Can anyone share some code for the sharp sensors?
I am a novice so modifying / adding to code is my present skill level.
Anyone know of ANY available AVR Studio code (C++) available for a basic obstacle avoidance using two sensors on PC5 and ADC6?

Stand by. I have 1 Sharp distance sensor that works fine on my m3pi. I’ll get back to you.

OK, I’m back. Hope this helps…donde

I have the Sharp 10 cm sensor, that is GP2YOD810ZOF.
VCC, 5 volts comes from the 3pi battery supply, ground from common ground of m3pi.
I use pin 12 of the MBED for digital in.
First of all the 3pi is set up as Slave.

Here is some code for the PID line-follower

m3pi m3pi; // engage 3pi slave This is before main()

DigitalIn dist_sen(p12); // Distance sensor pin This is before main()

dist_sen.mode(PullUp); // This is after main()

Below is a 2nd while() after the first one, and the end of program

 while(on)  {   
        if(dist_sen)  // Distance sensor pin high    This if statement and break; does the sensor work. The rest is my stuff.
        else         // spin 180 if obstruction
      m3pi.stop();    // stops when atfull()
      if (on == 0) {
      all_stop = 1;  // full shutdown
      all_stop = 0;


Sorry for the thread necromancy, but this is unclear to me. I have a Sharp Digital Sensor (GP2Y0D805Z0F) and want to connect it. Ryan said mbed’s VCC, but the mbed has different Voltages (VIN, VOUT, VU), and there is the VCC from the 3pi. So the VCC from the 3pi is the correct one? And can I use any position labeled VCC on the 3pi base for that (like the convenient row of three VCCs in the front…)?

Is there a list of the free pins of the mbed somewhere? There’s always the schematic diagram, but that is a bit unpractical.



That Sharp digital distance sensor has an operating voltage of 5V, so you could connect it to VCC on the 3pi, which is 5V. The mbed runs on 3.3V logic but is 5V tolerant, so you should be able to connect the output of the Sharp digital sensor directly to it. The m3pi schematic diagram is the easiest way to see which IO pins are available (why does using that seem impractical to you?). The mbed pins without net labels are completely free.

- Jeremy


Well a chart of unused pins would be quicker, as the pins in the schematic are not ordered. Maybe I’m just lazy…


One benefit to using the schematic is that it makes it easy to see how the used pins are used and determine if they can be appropriated for some other purpose in your design. The pins with no net labels are completely free, but some of the other pins are conditionally free (e.g. the COM_TX, COM_RX, and COM_nRST pins if no Wixel or XBee module is present), and some pins can be used for multiple things (e.g. the LED control pins can be used as general-purpose digital outputs). I agree that this could be conveyed nicely (and, in some ways, more conveniently) with a table, but I think the schematic does a decent and, ultimately, more thorough job.

- Ben

3pi robot I can not connect using the proximity sensor. when I use my proximity sensor and solder to connect, the light sensor and serves only one sensor alone, the other input port is not working, please help how should I fix it?

:frowning: :frowning: :frowning: :frowning: :frowning:


I am having difficulty understanding your problem. Could you please provide a more detailed description of the issue and your setup (e.g. what sensor you are using, pictures of your setup, and a connection diagram)?


I recently bought , and have been trying to found out how to attach it to a Pololu 3pi. I have googled answers endlessly and still have no answer as everyone seems to use the analog distance sensor. The ports on my sensor are as follows;
V/N or VIN (cannot tell)

Will someone please tell me how to attach this sensor and send schematic diagrams aswell as real attachment pictures.



It is unclear from your post whether you are using just a 3pi expansion board on your 3pi or are also using an mbed controller. Either way, you should be able to connect the output from the sensor to any of the available I/O pins on your main controller. If you are just using the expansion board without an mbed, you can find more information on which pins on the 3pi are available in the “Available I/O on the 3pi’s ATmegaxx8” section of the 3pi robot’s user’s guide. If you are using an mbed, you can see which I/O pins are not connected to anything else in the schematic in the last section of the m3pi’s user’s guide. In the schematic, the pins on the mbed that do not have a red label next to them, like p24, p25, p29, and p30, are free and can be used to get input from sensors or control peripherals.

As stated in the “Using the Sensor” section of the sensor’s product page, you should connect the VIN and GND pins to a source that is between 2.7 and 6.2V.

If you continue to have trouble connecting the sensor, you could post a picture or diagram of how you have it connected, and I would be happy to take a look at it.