Control your Arduino with Scratch over Bluetooth

Yes, really. Scratch is this wonderful MIT visual programming toolbox that you can get for free in many different languages. Its an excellent starting point to teach children how to program. But you can go even further: Some weird spanic guys wrote an Arduino sketch that let’s the Arduino interface with a modified version of Scratch called S4A (“scratch for arduino”). Brilliant. Yes, you can build robots and control them with the visual programming language. But: the Arduino has to stay connected to the computer permanently because the interaction works over a Serial connection. Hm… As i am working on some kind of school teaching electronic project at the moment (some info in german) i wanted to bring that further by introducing Bluetooth (the docs are mentioning an xbee RF connection but i can’t believe this would be a feasible way for a normal teacher + it requires an adpator on the pc side as well). So i wanted to control the serial connection to the Arduino over the air, ideally from o broad set of possible devices like Laptop, Tablet, iPhone etc. – wait: iPhone?

The iPhone introduces another special hurdle to the project as Apple decided not to support standard ‘classic’ Bluetooth connections, but only BLE (“bluetooth low energy”). I am pretty sure there is no technical background for this as Android phones have no trouble to support all kinds of BT connectivity, but anyway, i had to deal with that as well.

Fortunately there are numerous BT-boards and adaptors out there so it shouldn’t be hard to find one matching my requirements. I quickly digged into the modules from itead/seeed that are easily available, cheap and normally well documented etc.

I first tried the HM-06 module, connected it to my Arduino Uno just like described in this nice tutorial  on instructables, launched S4A and voilá – Scratch was reporting values from the distant Arduino!

But it didn’t work for my iPhone or iPad – so i tried the HM-11 which works with a TI CC2541 chip. Although the documentation mentioned a passthrough-mode for UART and the module came with TX/RX connections, it was not possible to pair it to a computer or mac and get the serial link over the air. Obviously a misunderstanding as the TI-Chip clearly only supports BLE 4.0 and no “classic” Bluetooth.

So i ordered another module, this time the HM-13 which can be ordered on a nice Grove-Breakout board including voltage regulator etc. (which is very important – the modules are quite sensitive regarding over-voltage and require straight 3.3 volts on VCC).

After some struggles i managed to get this working as desired – had to fix the baud-rate as the module is communicating with 115200 baud by default and Scratch tries to do 38400 initially. So please check the baud-rate at which your BT-module is communicating and try to set the Serial-speed in the S4A-scetch accordingly.

As the HM-13 is a dual-mode BT chip it can be run in both modes – as classic BT device that has to be paired to the other device and then simulates a serial connection, or as BLE 4.0 device, that can be seen on an iPhone with a specific app (i used the ones from TI that ship with their SensorTag.

Of course this setup cannot only be used for Scratch but any Serial connection can be routed over the air – it should even be possible to flash new firmware onto the Arduino that way (will be tested once i get my 100nF capacitor to connect the reset line). And BTW – if you only need serial over the air i’d recommend the HM-06 module mentioned above – it does this job very nicely as a single purpose device.


About holadiho
This entry was posted in Arduino, educational and tagged , , , . Bookmark the permalink.

1 Response to Control your Arduino with Scratch over Bluetooth

  1. Pingback: How to flash an Arduino over the Air with Bluetooth | Making connected stuff

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s