# My Zumo 2040 Arduino Library

**URL:** https://forum.pololu.com/t/my-zumo-2040-arduino-library/29124
**Category:** Share your projects
**Created:** [June 30, 2026, 8:48am UTC](https://forum.pololu.com/t/my-zumo-2040-arduino-library/29124 "2026-06-30T08:48:32Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![AdamGreen](https://forum.pololu.com/user_avatar/forum.pololu.com/adamgreen/32/11194_2.png) [@AdamGreen](https://forum.pololu.com/u/AdamGreen)
#### Post date: [June 30, 2026, 8:48am UTC](https://forum.pololu.com/t/my-zumo-2040-arduino-library/29124/1 "2026-06-30T08:48:32Z")

</div>

I recently ported [Pololu’s Zumo 32U4 Arduino Library](https://github.com/pololu/zumo-32u4-arduino-library) to the [Zumo 2040](https://www.pololu.com/category/308/zumo-2040-robot). The initial Unofficial RP2040 port is now complete and version **0.1.0** can be found in the following repository on GitHub:

> **[GitHub - adamgreen/zumo-2040-arduino-library: Library to help interface with the on-board...](https://github.com/adamgreen/zumo-2040-arduino-library)**
>
> Library to help interface with the on-board hardware of the Pololu Zumo 2040 robot.

It includes all of the functionality found in the 32U4 version with the addition of support for the addressable RGB LEDs found on the Zumo 2040. The list of supported classes/functions includes:

- PololuZumo2040::ButtonA
- PololuZumo2040::ButtonB
- PololuZumo2040::ButtonC
- PololuZumo2040::Buzzer
- PololuZumo2040::Encoders
- PololuZumo2040::OLED
- PololuZumo2040::Motors
- PololuZumo2040::LineSensors
- PololuZumo2040::ProximitySensors
- PololuZumo2040::IMU
- PololuZumo2040::RGBLEDs
- PololuZumo2040::ledYellow()
- PololuZumo2040::readBatteryMillivolts()

Here is an excerpt of Pololu’s **BorderDetect.ino** example ported to the Zumo 2040:

```c++
#include <Zumo2040.h>

#define QTR_THRESHOLD 300

#define REVERSE_SPEED 200
#define TURN_SPEED 200
#define FORWARD_SPEED 200
#define REVERSE_DURATION 200
#define TURN_DURATION 300

OLED display;
ButtonA buttonA;
Buzzer buzzer;
Motors motors;
LineSensors lineSensors;

void waitForButtonAndCountDown()
{
  ledYellow(1);
  display.clear();
  display.print("Press A");

  buttonA.waitForButton();

  ledYellow(0);
  display.clear();

  // Play audible countdown.
  for (int i = 0; i < 3; i++)
  {
    display.gotoXY(3, 0);
    display.print(3-i);
    buzzer.playNote(NOTE_G(3), 200, 15);
    delay(1000);
  }
  display.gotoXY(0, 0);
  display.print(" GO! ");
  buzzer.playNote(NOTE_G(4), 500, 15);
}

void setup()
{
  waitForButtonAndCountDown();
}

void loop()
{
  if (buttonA.isPressed())
  {
    // If button is pressed, stop and wait for another press to
    // go again.
    motors.setSpeeds(0, 0);
    buttonA.waitForRelease();
    waitForButtonAndCountDown();
  }

  lineSensors.read();

  if (lineSensors.rawSensorValues[0] < QTR_THRESHOLD)
  {
    // If leftmost sensor detects line, reverse and turn to the
    // right.
    motors.setSpeeds(-REVERSE_SPEED, -REVERSE_SPEED);
    delay(REVERSE_DURATION);
    motors.setSpeeds(TURN_SPEED, -TURN_SPEED);
    delay(TURN_DURATION);
    motors.setSpeeds(FORWARD_SPEED, FORWARD_SPEED);
  }
  else if (lineSensors.rawSensorValues[LINE_SENSOR_COUNT - 1] < QTR_THRESHOLD)
  {
    // If rightmost sensor detects line, reverse and turn to the
    // left.
    motors.setSpeeds(-REVERSE_SPEED, -REVERSE_SPEED);
    delay(REVERSE_DURATION);
    motors.setSpeeds(-TURN_SPEED, TURN_SPEED);
    delay(TURN_DURATION);
    motors.setSpeeds(FORWARD_SPEED, FORWARD_SPEED);
  }
  else
  {
    // Otherwise, go straight.
    motors.setSpeeds(FORWARD_SPEED, FORWARD_SPEED);
  }
}

```

If you happen to try it out, please let me know what issues you encounter so that I can try to fix them and further improve the library. Thanks ahead of time for any feedback you throw my way.

---

<div class="post-metadata">

### Author: ![justbeatit](https://forum.pololu.com/letter_avatar_proxy/v4/letter/j/cdc98d/32.png) [@justbeatit](https://forum.pololu.com/u/justbeatit)
#### Post date: [July 5, 2026, 12:05pm UTC](https://forum.pololu.com/t/my-zumo-2040-arduino-library/29124/2 "2026-07-05T12:05:14Z")

</div>

Thank you. Does this library support new versions like Arduino UNO R4, Arduino UNO Q etc.?

---

<div class="post-metadata">

### Author: ![AdamGreen](https://forum.pololu.com/user_avatar/forum.pololu.com/adamgreen/32/11194_2.png) [@AdamGreen](https://forum.pololu.com/u/AdamGreen)
#### Post date: [July 5, 2026, 2:48pm UTC](https://forum.pololu.com/t/my-zumo-2040-arduino-library/29124/3 "2026-07-05T14:48:36Z")

</div>

> [@justbeatit](#):
>
> Does this library support new versions like Arduino UNO R4, Arduino UNO Q etc.?

No, it is for the newer [RP2040 based version of the Zumo robot](https://www.pololu.com/category/308/zumo-2040-robot). It contains code that is specific to that microprocessor such as using PIO for wheel encoders and line sensors.

The only way you could use something like an Arduino UNO R4 with the Zumo would be if you used the [Zumo Shield for Arduino](https://www.pololu.com/product/2521). For that version of the Zumo, you would be better starting out with the Zumo Shield Arduino Library:

> **[GitHub - pololu/zumo-shield-arduino-library: Arduino libraries for the Pololu Zumo Shield and...](https://github.com/pololu/zumo-shield-arduino-library)**
>
> Arduino libraries for the Pololu Zumo Shield and Zumo robot kit for Arduino.

---

<div class="post-metadata">

### Author: ![AdamGreen](https://forum.pololu.com/user_avatar/forum.pololu.com/adamgreen/32/11194_2.png) [@AdamGreen](https://forum.pololu.com/u/AdamGreen)
#### Post date: [September 1, 2026, 4:53am UTC](https://forum.pololu.com/t/my-zumo-2040-arduino-library/29124/4 "2026-09-01T04:53:55Z")

</div>

I have made a few updates to this library:

- **0.1.1** (2026-07-06): **LineAndProximitySensors.ino** was using raw line sensor readings when it was supposed to be showing the calibrated results.
- **0.1.2** (2026-08-27):
  - **readBatteryMillivolts()** now disables the down emitters. Previously it would return large values if called when the down emitters were turned on.
  - Added **LineSensors::startRead()** to allow the line sensor readings to be started in the background and the results read at a later time by calling LineSensors::read().
  - **ProximitySensors::readBasic()** now adds a short delay before checking the proximity sensors for the detection of another robot’s IR transmitters. Previously it would return a false positive result if called too soon after its own IR transmitters were disabled.
