Lego WeDo : Interface motor and sensors to Arduino Uno R3

I have a Lego set part number 9580. It's old. I bought it about 15 years ago. I got it out of the loft today for a grandchild to play with. It works on Windows 11 with the official Lego software. I'm interested in controlling the motor, and reading the sensors, via an Arduino Uno R3, or a Nano, Mega, Leonardo, ESP32. I just picked Uno R3 as it's common and avoids the 3.3V versus 5V discussion.

The PC interfaces with the motor and sensors using the Lego "USB hub" shown in the image below. Each motor / sensor has its own 4 way cable that plugs into the "USB hub"

I'm trying to find the interface spec for that 4 wire cable, so that I can use the motor and sensors with an Uno R3.

I've done quite a lot of Googling and chatted with Google AI (expecting AI to be a waste of time, and it was). If anyone reading this has worked out what's going on on that 4 wire interface, I'd be interested to hear about it, and about any Arduino projects using this interface.

[Edit: Added - the specific sensor I have are the tilt sensor and IR proximity sensor]
[Edit: Added - I know about how to use a transistor to switch a motor, and PWM to change the speed. I also understand how to read analogue inputs for any sensor with an analogue output]

I don't see how ...

My first guess is I2C for 4 wire cable, but if you supplied more info lke where those cables are meant to go would help clarify.

It saves people asking if I'm using a microcontroller with 5V or 3.3V IO

If it's that old it is almost surely 5V.

One end of the cable plugs into the "USB Hub" (Lego terminology). The other end is hard wired to a motor or sensor, e.g. the IR sensor:

...which we just had a (short) discussion about :wink:

That would be nice if it was. I've ordered an extension cable that I can hack to have a look on my scope. I was just asking on the forum to see if someone had already done the reverse engineering that I'll end up doing if nobody here knows the spec

If it's USB, it may be a simple serial connection, or they could use the 4 wires for I2C. Hopefully your scope can tell you.

USB 1.1/2.0 has only 4 conductors, so maybe this USB hub really is just that?

This should be easy to confirm/deny. If it really is a USB hub then the PC should be able to detect and identify the hub and individual devices plugged into the hub.

What does your O/S tell you about this hub, and does it list the devices plugged into it?

What does lsusb tell you?

All packed away now and the evening meal is almost ready. I'll see if I can find it in device manager in Win11 tomorrow.

Is that the Lego Mindstorms or whatever it was called? I vaguely remember looking at Mindstorms (?) in the Lego store at Mall of America with my gf because she wanted to learn engineering.

I don't know how similar it is to mindstorms. This product is aimed at school STEM classes. It comes with a teachers' guide. The product series is branded as "WeDo". Here's a picture of the box and one of the UI.

The outer two are 9V and ground for downstream device power and the inner two swap (9V & GND) back and forth for motor direction.

I'll check that tomorrow. I was expecting 5V USB power.

Here's a page about it.

Thanks for that. I spotted this:


Maybe it's the same cable, but it's using USB power. I'll measure the voltage on the connector pins tomorrow and report back

I did some experiments this morning and was able to rule out some of the perfectly reasonable suggestions you kind people offered.

Not I2C

Not serial

Not a true USB hub.

This one is close, but it's using 5V and the UI has some way to detect the presence of a motor.

First I checked, using a very low voltage continuity tester, to see if there was a direct connection between the USB power pins and the pins on the "hub".

Then I plugged the USB Lego "hub" into my PC and ran the Lego application. I checked the voltages with my scope, and could see the pins always had steady DC voltages on them:

I've not attempted to check how it works with the sensors yet. I'm going to wait until I get the Lego extension cable I ordered so that I can make a break out board for the cable going to the sensor(s) rather than probing those tiny pins with nowhere to clip the scope earth clip to.

It looks like Lego have "modernized" the interface and eliminated the 6-cell battery box from back in the day as well as added some detection capabilities to the UI.

I downloaded the instruction .pdf for the 9580 LEGO® Education WeDo™ Construction Set. While similar to the Technics sets our kids had, it doesn't use the 9V power pack. Looks like a fun kit though.

Hi Dave!

Due to your preparation I was able to identify some sources that (hopefully) may be of assistance for you ... I admit I used AI to speed up the search but checked its answers.

This is my summary so far:

The 4-pin connection system belongs to the legacy LEGO Power Functions 1.0 ecosystem. It was used in the original LEGO WeDo 1.0 set (released in 2009) before being replaced by the 6-pin LPF2 system in WeDo 2.0.

Source: https://www.juniorstem.co.uk/explore-juniorstem-lego-robotics/wedo-1-0/

While the physical plug shape is identical to standard Power Functions, the WeDo 1.0 USB Hub re-routes the electrical signals to match USB power limits:

LEGO WeDo 1.0 (5V System) Component Identification and Data Reference

The identification process relies on a continuous analog voltage check performed by the WeDo 1.0 Hub across the C1 (Pin 2) and C2 (Pin 3) lines against Ground.

When a component is plugged in, its internal fixed identification resistor (or raw motor coil) completes an electrical circuit, creating a specific voltage drop that acts as a unique signature.

The Hub instantly decodes this analog voltage level to identify the exact device type attached, allowing the software to automatically load the correct interface for that specific sensor or actuator.

Further information regarding the Tilt Sensor:
https://ofalcao.pt/blog/2014/the-lego-wedo-tilt-sensor#:~:text=The%20value%20of%20R1,tolerance%20resistor.

The documentation for "Linux Kernelk Drivers for ev3dev-stretch" contains information about LEGO WeDo 1.0 components. See the LEGO WeDo on the main page and look into Appendix A: Sensor Data and Appendix B: Motor Data:

https://docs.ev3dev.org/projects/lego-linux-drivers/en/ev3dev-stretch/index.html

The following Bachelor Thesis may be of additional interest (WeDo 1.0 is shortly mentioned but it aims at newer versions):

CONTROLLING LEGO TECHNIC ACTIVE ELEMENTS FROM EV3

https://theses.cz/id/j11q6d/xblask05_bakalarska_praca.pdf

If you may use AI to search for further information it is crucial to emphasize that you are looking for WeDo 1.0 and compatibility to the LEGO Power Functions 1.0 ecosystem. Still you will get feedback that is a mixture of 1.0, 2.0 and EV3.

AI can be stubbornly stupid and persistent ...

Good luck and have a lot of fun with Lego and your grandchild!
ec2021

[Edit:] The ID process is described as follows (not verified!):

  • When the port is empty, no current flows, and both C1 and C2 read a maximum of 5.0V.
  • When you plug in any WeDo 1.0 sensor, its internal 3.9 kΩ resistor immediately completes a circuit on C1, pulling the voltage down to a steady mid-range level (around 2.5V to 3.0V). The Hub registers this stable drop and concludes: “An active sensor is present on this port.
  • Because the Motion Sensor and Tilt Sensor share that exact same 3.9 kΩ marker on C1, the Hub instantly evaluates the voltage on C2 to tell them apart. The Tilt Sensor exposes a passive resistance step on C2 right away, whereas the active circuitry of the Motion Sensor alters the C2 voltage based on initial infrared levels.
  • If the internal pull-up voltage on C1 and C2 instantly collapses straight down to 0V. The Hub recognizes this massive, near-zero voltage drop and instantly registers: "An actuator (motor) is connected."
  1. C1 acts as an uninterrupted "presence and heartbeat check." If you unplug the wire, C1 snaps back to 5.0V, and the software immediately drops the connection.
  2. C2 handles the payload data stream, converting real-time mechanical changes (tilting or object distance) into varying voltage drops that the software interprets as values
    from 0 to 100.

(I am very curious to see whether you can confirm the results... :slight_smile: )