how to control Lego motors and servos with Arduino

hello dear arduino-experts

i want to take a Lego-Car (only a basic - chassis like here: https://www.instructables.com/id/Build-your-own-Custom-Arduino-Remote-Control-and-L/ )

The aim is to control Lego buildings from Arduino boards with low cost parts. This first projet where i do not want to adapt the traditional servo-motor 9g to plug it with Lego blocks. I want to stick with the Lego Power-functrions.
in other words: For this project i do not want to make use of the low cose parts: i.e. the servo-motor 9g

i want to take Control Over the Lego Power Functions and the so called Lego Technic Servo Motor.

the question is: how to control Lego motors and servos with Arduino

some musings:

  • Lego has a 4 cable connector. Two of them supply power (+9V & GND) and the other are optionally +9V and they are called C1 and C2.
  • the Servo turns in some directions: eg right or left max 90 deg when we supply PWM to either C1 ("left") or C2 ("right"). (or the other way round - in other words left and right and viceversa)

That basically means that what I need is a 9V PWM and be able to supply it to either C1 or C2.
What is more the frequency has to be 1150 Hz.

Now the question is how do I achieve this goal? i have heard about using the L298N motor-controller:
The A L298 dual H-Bridge motor control module for Arduino - this can help here to get connected to wired control LEGO Power Functions Motor. With this Arduino can control LEGO Power Functions Motor to forward, backward, and besides this also in the so called float, brake, PWM variable speed, and lots of other things more.

how to controll the Lego-Power functions: Well i guess that i have have few options, with different precision and complexity:

  1. i can do this with some configurations one of the PWM HW blocks
  2. i can make usage of a timer to trigger a sw function - but it might be simpler to just configure the Pulse wiede Modulation HW block.
  3. i can make usage of some existing legacy library that will implement one of the above mentioned methods

the question: which method would you recommend

i am willing to learn something of the AVR internals and it will be the solution with the least overhead.
are there some tutorial.

besides this: is there a brick that i can use here?

i have heard bout a brick:

a fully functional prototype of a brick (2 x 4 x 1) that has been developed to make it easy to control PF motors with Arduino boards. It has a PF connector on the top to connect the PF motor and a 4PIn cable to connect to the Arduino board; it has 8 anti studs on the bottom to connect it to LEGO bricks. It allows controlling the direction and speed of the PF motors. We tested it with the M-motor, L-motor, XL motor and the train motor.

see: Brick to connect PF motor to Arduino board - LEGO Technic, Mindstorms, Model Team and Scale Modeling - Eurobricks Forums

do you recommend this brick - do you think that this is useful!?

1 Like