Analog input always returns 0 after calling robot.init

I have a Pololu 3pi with an accelerometer attached to pin 5. I can read from it and display the value on the LCD no problem.

However, after I call robot.init(2000) in order to use the line following feature, the accelerometer always returns 0.

Here is a simplified version of my code:

    #include <OrangutanLCD.h>
    #include <OrangutanMotors.h>
    #include <OrangutanBuzzer.h>
    #include <PololuQTRSensors.h>
    #include <Pololu3pi.h>
    int accelPin = 5;
    Pololu3pi robot;
    unsigned int sensors[5]; 
    void setup() {
      pinMode(accelPin, INPUT);

    void loop() {
      while (true) {
        lcd_goto_xy(0, 0);

Without the line robot.init(2000), the accelerometer works perfectly; with it, it returns only 0. Any ideas?

Update: I found that this will work using pin number A5 rather than 5, and with robot.init(2000); in the void setup rather than main.

1 Like


I am glad you were able to get it working by switching to A5. Digital pin 5 on the 3pi is used for motor 1 (left motor) control, so I suspect this conflict was causing the problem. The A5 pin can be used to control the IR emitters, but if the jumper (labeled PC5) is not installed, then A5 is free. You can find more information about all of the 3pi’s pins and their functions in the “Pin Assignment Tables” section of the 3pi Robot User’s Guide.