2

Scratch and LEGO WeDo

You may have heard of the computer programming language Scratch. It’s a child-friendly system where you code by dragging around colored blocks and snapping them together – and for that reason some schools call it ‘Computer LEGO’. Even better, Scratch has a built-in extension that allows it to work with LEGO’s WeDo robot kits. I want to tell you about how I’ve been using Scratch and WeDo with children in the UK.

Scratch Interface with WeDo Blocks
Scratch once the WeDo extension has been enabled. The yellow dot next to LEGO WeDo in the middle column indicates that the WeDo hub hasn’t yet been plugged into the computer. If it’s red, you need to install the browser plug-in. Green indicates that you’re good to go.

Scratch is developed by The Lifelong Kindergarten Group at the Massachusetts Institute of Technology, and is completely free to use. You can either use the online version at the scratch.mit.edu website, or you can download and install the Scratch 2.0 Offline Editor. If you go for the first approach, you also have to install a browser plug-in (see here). The plug-in doesn’t seem to work reliably across all browsers and operating systems – so if you’re having problems try a different browser. If instead you’re using the Scratch Offline Editor, everything you need is already built-in, so you’re good to go.

LEGO launched a new version of WeDo, WeDo 2.0, in January 2016, and the Scratch team has since released an extension that works with it. This post is all going to be about the original WeDo. This kit includes a hub you plug into your computer, a motor, a tilt sensor, a distance sensor, and loads of LEGO blocks. The LEGO WeDo Software is sold separately, but you don’t need anything extra if you’re using Scratch instead. Having said that, I would recommend buying the Power Function Lights, as they’re relatively cheap, and are fully compatible with Scratch and the WeDo hardware.

Once you’ve got your kit, just plug it into the USB slot, start up Scratch and go to ‘More Blocks’. Next select ‘Add an Extension’ and then LEGO WeDo. If you don’t see these options, you may need to update your Scratch to a newer version. A selection of new blocks will now appear, offering very self-explanatory options for controlling the motor and reading the sensors. You can control the motor speed and direction, find out how far in front of the distance sensor the nearest surface is, and in which direction the tilt sensor is angled.

All of these blocks can be fully integrated with any Scratch program, so you could use the tilt sensor to control a sprite, or have the motor react to events in a game. The main limitation is that with Scratch you can only use one WeDo hub at once – if you’re using the LEGO WeDo Software you can connect up to three at once. This limits you to using just two electronic components at a time: a motor and a sensor, two sensors, two motors, a motor and a light, etc. As each kit only comes with one hub, this isn’t likely to be a problem for most of us.

Now, how about the LEGO WeDo kit itself? The base kit includes some 158 elements – a mixture ranging from standard four by twos to cogs and gears borrowed from the LEGO Technic range. And if that’s not enough for you, there’s a resource set with another 326 bits, but it doesn’t include any more electronic components – you have to buy them separately. This brings us to what I really love about WeDo – it uses classic studded LEGO bricks, rather than the studless Technic beams used in the MINDSTORMS EV3 set, so it really feels like LEGO. Every robot you make, you build brick by brick – so you really can make absolutely anything. An EV3 set is also at least twice the price – so I’d much rather go for a WeDo set any day.

Scratch Code for Controlling ‘Drumming Monkey’. The tilt sensor keeps the sounds in synch with his movements.
Scratch code for controlling ‘Drumming Monkey’. The tilt sensor keeps the sounds in sync with his movements.

There are twelve official models you can make with the WeDo set. You don’t get the instructions with the kit (unless you buy the activity add-on to the software), but you can download them for free from the LEGO website. There’s a good variety here – ranging from a sailboat that rocks, to a foot that kicks anything placed in front of it. The sailboat is intended to be used as part of a story ­­– you can add sounds and vary the speed and degree of rocking with your Scratch program. The sounds and any visuals will play through your computer’s speakers and screen as normal. The foot is probably the simplest model to build, but also one of the most popular with children. It uses the distance sensor to detect when an object is placed in front of it and then turns on the motor to kick it.

Another favorite is the ‘Smart Spinner’. It uses the motor to rotate a spinning top, and the distance sensor to detect when to switch the motor on and off. It uses gears to step up the motor speed, so the top goes on spinning for ages after release. ‘Goal Keeper’ is also very popular – you use the computer keyboard to move a soccer goalie into the path of balls rolled towards him. You can also use the distance sensor to detect every time a ball gets past him. Scratch can keep count of the number of goals, and play a sound every time as well.

Four models respond to your actions. The alligator snaps her jaws shut when you put your hand inside. The lion rises up and roars when you move the meat he is guarding. The giant awakes and stands up when you put a LEGO man in front of him. The ‘Cheerful Fans’ rotate and bob up and down when you get close. In my version, I made them move faster (and make more noise) the closer you get. ‘Dancing Birds’ is similar to Cheerful Fans, but they simply spin around under computer control, without using a sensor to respond to your actions. ‘Drumming Monkey’ beats drums with his arms, and if you add the tilt sensor, you can coordinate drum sounds to play in sync with his movements.

The Official WeDo Models
The twelve official WeDo models

There’s another story-based model – ‘Airplane Rescue’ – which uses the tilt sensor to adjust propeller-speed based on its orientation. You can also add sound effects and calamities such as the engine stuttering to a halt mid-flight. Finally, ‘Flying Birds’ is unique in not using the motor, but using both sensors instead. You manually flap her wings, and she can play a sound through the computer every beat, and another one when you tip her head down to peck at her feet.

I’ve always used Scratch rather than LEGO Education’s WeDo Software. I’ve created my own Scratch studio with code for each WeDo robot here, and I’ve added videos of them in action to my Vimeo channel here. I’ve used the WeDo kits as part of Code Clubs run by Success4All, and at a primary (elementary) school with high ability 7 to 9 year-olds. Success4All is a voluntary organization that provides free tutoring and educational clubs for children in economically and educationally disadvantaged areas of Newcastle upon Tyne. Code Club is a UK organization that helps volunteers to run computer programming clubs in schools and community centers across the UK and internationally, mainly using Scratch. Code Club is aimed at 9 to 11 year-olds, but Success4All’s Code Clubs have been open to children of any age – and I’ve found that Code Club projects and the WeDo robots work well with children from 7 right up to 17.

LEGO Education markets the WeDo kits at primary schools for children aged 7 to 11. In my experience, the models are quite advanced for this age group. Keen LEGO builders will be fine, but it can take a child a full hour to build a model, before they even start with writing the code to control it. Many children will find it hard to persevere with a model this hard, and will need a bit of help and encouragement to get to the end. Even when they have completed one, they are not likely to have much time or stamina left to actually do any coding.

One solution to this problem is to get the children to start with much simpler models. I’ve done this by getting them to copy a model I’ve created, such as a car that moves forward or backward under keyboard control, but uses the distance sensor to stop before it hits an object in front of it. Another simple model is a magic wand that will only light up and play a sound when tilted in the right sequence of moves. There’s a video of it here.

Scratch code for a car that wont crash
Scratch code for a car that won’t crash. You can control it with the arrow keys, but it won’t move forwards if it detects and obstacle less than ten units ahead.

No doubt there is lots of good learning just in building the LEGO, especially in relation to mechanics and gears, so another solution is to let the children build the models and then load in a program you’ve already written (or the code from my Scratch studio). This works well too – and the children can then go on to modify the model and/or code themselves. If you’re able to leave the models intact until the next session, that would be a good solution too. Once the kids have built a few models, they’ll probably speed up, and more-experienced/older kids will be fine from the start.

Mechanical Grabber
My Mechanical Grabber. If you place an object in front of the jaws, it will reach out, grab it, and pull it back. The distance sensor detects objects and the motor uses a rack and pinion to move the arm. The jaws open when the arm is pushed forwards, and close when it is pulled back.

We haven’t really got to the real fun of WeDo yet – the massive potential to make your own creations. The kits are capable of doing way more than LEGO’s official models. You can see 12 of my own creations on my Vimeo channel, and the control code for each in this Scratch studio. That’s an open studio, so you can contribute your own creations too (and some people already have). I’ve included photos in the projects as backgrounds, so you should be able to work out how to build the LEGO models.

I’ve really tried to explore what the WeDo sets are capable of – and the answer is a lot. They may not have as many motors or as diverse a range of sensors as the NXT and EV3 sets, but with a bit of ingenuity you can get them to do all sorts of things I’m sure their creators never imagined. I’ve made an earthquake detector, a machine that reaches out and grabs anything put in front of it, a car that drives around automatically turning to avoid obstacles, a version of the soccer goalie mentioned above that moves to save goals automatically, a machine that will move a pole until it finds its balance point, and a kind of ‘radar’ that will draw a graph of objects it senses in its surroundings. Even having done all this, I’m sure there is loads more that you can achieve with WeDo.

Having given an overview of what you can do with the WeDo kits, I’m now going to show you a couple of useful snippets of code. If you put one of these snippets of code in Scratch (don’t try to use both at once), you’ll be able to see the current reading of the distance or tilt sensor. This is really useful for seeing how those sensors work, and for debugging purposes.

Scratch Code for Reporting Sensor Values
Scratch code for reporting the sensor values

Finally, I just want to make a brief shout-out to PicoBoard, another piece of hardware supported by Scratch. It has four sensors: a push-button and a slider, as well as light and sound sensors. It also has four inputs that measure resistance, allowing you to easily make and add your own sensors. There is a lot of potential to use this together with WeDo kits to augment their sensing capabilities, and so create more capable robots.

Whether it’s to play with for your own entertainment, or as part of a mission to advance the technical skills of our planet’s next generation, I’d strongly recommend getting hold of a WeDo kit. I’ve certainly enjoyed playing with mine!

The following two tabs change content below.
I work at Gosforth East Middle School in Newcastle upon Tyne, UK. I used to run Code Clubs and teach Scratch at Collingwood Primary School in North Shields and at Success4All in Newcastle.

Latest posts by Mike (see all)

3 thoughts on “Scratch and LEGO WeDo

  1. Hi, can I ask if you have a Mac? I read something about Scratch only working with Lego WeDo if you’re using iOS?

    Basically, I want to buy a WeDo starter kit without paying the extra £50 for the Lego software!

    Thanks xx

Leave a Reply