How to coordinate movements (motor synchronization) with SPIKE Prime Word Blocks

| | ,

In this article, I’ll explain how you can run motors to different positions simultaneously. Running these motors at the same time is difficult with LEGO MINDSTORMS or SPIKE Prime Word Blocks. The problem is that move-to-position blocks your program. This tutorial explains how to synchronize the motors precise movements.

Why is this tutorial important? Take a dancing robot: you want the arms to go up and down in exact opposite movements. And they have to keep coordinating their movements during the complete song. In The First LEGO League, a synchronized motor movement can also save precious seconds. You could, for instance, grab an element while retracting an arm.

Coordinated movements for dancing, walking, and FLL missions

In this tutorial, we’ll use the Ladybug model. It is a six-legged walker – a hexapod. To move, it needs to lift its body to one side with the middle legs. Then it has to shift the free, airborne legs forward. After that, it can push backward on the ground with the supporting legs. Switch to the other side and repeat. 

The model is built with a single SPIKE Prime kit, but the programming techniques apply to Word Blocks in LEGO MINDSTORMS Robot Inventor 51515 as well. If Word Blocks is too simple for you, I have also detailed how to synchronize multiple motors in Python. The SPIKE and Robot Inventor have an on-board MicroPython that is quite powerful.

We could program this movement by running each of the three motors in turn. It works, but it looks clunky. It’s robotic in a bad-looking way. Wouldn’t it be much smoother if the legs moved simultaneously, one forward and one pair backward? 

Option 1: Coordinate with the multiple motor button

The first option for running motors at the same time is selecting multiple motors in the blue Word Block. The problem here is that you can choose only one target per set of motors. Multiple motors will not work for our ladybug because one set of legs has to run forward while the other runs backward. I could cheat by changing the build. But then the model will not be able to turn on the spot anymore.

Multiple motors SPIKE Word Block

Option 2: Use broadcast to run multiple stacks at the same time

Our next option is to broadcast a message. If we broadcast, we can start several stacks at the same time. Every motor in every stack will start together at the moment of the broadcast. The broadcast is an improvement over option one because now we can set different targets for each motor.

In this particular case, I’m using ‘broadcast and wait’ because I want motors A and B to finish before moving motor D. The ‘broadcast’ Word Block would run motor D at the same time.

Option 3: Use the pink move block for magic synchronization

Our third option is to use the pink movement Word Block. LEGO provided this Scratch block to drive straight with a robot. To drive straight, the robot wheels need to move at precisely the same speed. They should also stop together and start together. We can use that behavior for other purposes than driving. The cool thing about the pink Word Block is that you can hinder motors or accelerate them all you want. Eventually, they’ll catch and go back in sync.

In the example below I have built everything into a Myblock. The first thing this does is tilt the Ladybug to one side. Then it makes sure the left legs are opposite of the right light legs with the ‘Go to position 90’ Scratch block. Once motors A and B are in position we can call the pink ‘Start moving’ word block. Any block that has ‘start’ in the in the name, takes almost no time to execute. It starts running the motors and immediately moves over to the next Scratch block.

Once the legs are moving forward and backward, this MyBlock keeps track of the position of motor B to decide whether the bug should tilt to one side or the other. Once it has done the desired amount of steps, it exits the loop and stops all motors.

My Block that makes the Ladybug move a certain number of steps

Conclusion: use broadcast with Word Blocks to run motors at the same time

To make motors move at the same time, the most flexible option is to use the ‘broadcast’ Word Block. If your motors can run continuously, and there are only two of them, you can make use of the magic inside the pink Scratch blocks.

There’s also a video tutorial on YouTube. 

Do you like this model? Get full building instructions, Word Block program, and Python program in the downloads section.

Support my work & Don’t Miss any updates

I hope you enjoyed this article. It took me a few days to write it and collect the image materials. If you appreciated it, consider supporting me on Patreon. Supporters get free monthly building instructions.

If you have more questions, feel free to ask them in the comments. If you follow me on Facebook, Instagram, and YouTube, these social media platforms will notify you of new articles and tutorials as I make them. 


Python Motor Synchronization: Coordinating SPIKE or MINDSTORMS motors

How to display two-digit numbers on a 5×5 LED Matrix with LEGO SPIKE Prime or Robot Inventor


Leave a Reply

%d bloggers like this: