How to build cool stuff for the Internet of Things

Laser king Seb Lee-Delisle gives the low-down on building stuff that talks to the internet.

Over the last few years the maker community has grown exponentially. As such, it's a really great time to start experimenting with electronics. The more that our shiny gadgets are locked down and proprietary, the more we want find out what strange magic is happening inside.

As a direct response, the open source hardware community has grown, and new prototyping platforms are constantly emerging. It's never been cheaper or easier to get hardware for your own hacking projects.

Exploring electronics

My journey with electronics started when I was a kid. My dad would often bring home electronic components from work for me to play with. I learned about breadboards, making simple circuits and soldering. I still love bright, confectionary-coloured LEDs. Fast-forward to a few years ago, when I was told that you could use an Arduino to attach large knobs and buttons to your games and projects.

So I bought one. And it dawned on me that this wasn't merely a hardware interface for my computer, it was an independent device that could process logic and run code by itself. In effect, it was a tiny self-contained computer. I got hold of an 8x8 LED matrix, made a simple particle system, and I was hooked. Over the last few years, I have been integrating hardware into my digital art projects more and more. These electronic devices let you get out of the computer and into the real world.

If you want to get into hardware projects, you're probably a little daunted by all your options. Two of the biggest platforms in this arena are the Arduino and Raspberry Pi. Each has different strengths and capabilities.

Arduino

The Arduino is a prototyping circuit board comprising a central chip and several GPIO (General Purpose Input/Output) pins that you can connect stuff to. You can program each GPIO to be either an input (to read data) or an output (to control things like lights and motors).

An Arduino Diecimila

An Arduino Diecimila

But don't just buy an Arduino – it's much better to buy some kind of starter kit. Look for one with a variety of components, jumper wires and a breadboard, along with a good guide book with exercises to get you started.

There are many kits available, including one made by Arduino. My personal favourite is the Sparkfun Inventor's Kit, which comes with a nice case to keep your projects in while you're working on them. It has a great manual with clear diagrams and 16 example projects to get you started.

There is an incredible variety of Arduino code libraries, resources and add-ons available, including 'shields' that sit on top of the board and give you extra powers, like driving motors, controlling LED screens, playing music or sending out MIDI information. Here are a few of the many Arduino-compatible boards that I particularly like:

  • Adafruit's Trinket – This is tiny and cheap, with five GPIO pins. If you need more pins and memory, try the Trinket Pro or the Arduino Nano.
  • Teensy 3.1 – The Teensy 3.1 is very fast and powerful, and still very small. It uses 3.3V instead of the standard 5V, so sometimes you need to convert voltages in order to work with some components. These are the brains of my Laser Light Synths (see boxout opposite), and they're very good at controlling thousands of addressable LEDs.
  • Arduino Mega – This is much bulkier than the Trinket and Teensy (although that's not saying much), but if you need a lot of pins and memory, the Arduino Mega is for you. It has the added benefit of being a genuine Arduino, so you know your money is going to support the people that created the project in the first place. What's more, it's compatible with most Arduino shields.

Build your own Arduino

The incredible benefit of open source hardware is that you can easily move from a one-off experiment to something you can bring to production. You can take the circuit layout of the Arduino, add your own components and manufacture your own products. This may not seem important when you're first starting out, but if you get the bug, you'll be designing and manufacturing your own printed circuit boards (PCBs) before you know it.

Programming the Arduino

This interactive installation featured a 3m wide drawing robot with engineering grade servo motors, all powered by an Arduino Mega

This interactive installation featured a 3m wide drawing robot with engineering grade servo motors, all powered by an Arduino Mega

The Arduino comes with its own IDE and programming language based on C, but if you're used to JavaScript it should look fairly familiar. The main differences are that it's strongly typed, so you have to specify what type of data the variables and functions use. Working with strings and text can be a pain too – it's certainly more involved than using JavaScript. Code is compiled inside the IDE and then programmed directly onto the Arduino's chip via a USB cable.

JavaScript options

What? You only want to program in JavaScript? Call me old-fashioned but I think that working in multiple different programming languages is good for your brain. But I can understand why JS programmers might be hesitant to invest time learning a new language just for a bit of tinkering.

The good news is you can control an Arduino entirely in JavaScript with a library called Johnny-Five. You access all of the Arduino inputs and outputs entirely from within a Node.js app on your computer. There is a catch – the code runs on your computer and sends data to and from the Arduino, so it has to be tethered to your computer to work. However, it's still a nice easy way to dip your toe in the water.

There are two emerging platforms that genuinely run JavaScript on the microprocessor: Tessel and Espruino. They both have their own lightweight JavaScript interpreter, and although they don't have the availability and ubiquity of Arduino, I'm confident that the community will grow quickly.

Raspberry Pi

A Raspberry Pi

A Raspberry Pi

The Raspberry Pi is a cheap Linux computer that also has a bank of GPIO pins, making it a great platform for electronic prototyping. It has only been around for a few short years, yet already it has revolutionised low-cost computing.

A strong and vibrant community of makers has grown and already there is a vast range of cases, peripherals and learning resources available. The brand new Pi 2 is faster and has more memory than the previous models, with backwards compatibility and the same form factor as the previous B+ model.

Unlike Arduino, the Raspberry Pi can easily drive HDMI screens and play large audio files. If you're already familiar with Linux and Python or Node, it'll be very easy for you to get started. You don't even need to attach a keyboard or screen to the Pi, you can ssh in from your computer to program it. And of course the whole thing is connected to the internet via the ethernet port or a Wi-Fi USB adaptor.

Just like the Arduino has 'shields', the Pi has 'hats'that sit on top of it and provide special extra powers. My favourite is Pimoroni's Unicorn hat – an array of super-bright LEDs that sits on top of the Pi. In fact, Pimoroni is an amazing UK success story with a wonderful stock of Pi cases and components.

ST4I (formerly IoT)

A selection of components that come with the ST4I kit

A selection of components that come with the ST4I kit

You can't have missed the hype about IoT, or the 'Internet of Things'. It's so ridiculous that I hate even using the term. The fact that corporations like Microsoft have a 'Director of the Internet of Things'makes me throw up in my mouth a little. I prefer using my own term: Stuff that Talks to the Internet, (STTTTi or ST4I for short). It's equally ridiculous, but at least it's my ridiculous.

I'll let you into a little secret about the IoT: no one has really figured out what it's for. Sure we can control our thermostats and the colour of our lamp with our mobile phone, but we're still flailing our arms around in the dark trying to get a grip on how exactly it's going to work. We all know it's going to be big, we're just not quite sure what its killer app will be.

But here's the thing about technologies on the verge of finding their use: they're really fun to play with. Like really fun. It's the perfect time to be imaginative, creative and just play with this stuff. That's why I put together my ST4I workshop – it's two days of experimenting and learning and it comes with a kit full of stuff including a Wi-Fi enabled Arduino. Check out st4i.com if to find out more.

How to turn an Arduino into an ST4i device

A Raspberry Pi is already networked, but an Arduino needs extra hardware (and code) in order to connect. I like the Adafruit CC3000 Wi-Fi shield – it sits on top of your Arduino and connects to your Wi-Fi, and there are lots of code examples to help you read data from the internet.

Arduinos with built-in internet

A Linkit One

There are Arduino-compatible boards that are already internet-capable. My favourite is the Linkit One, which has a Wi-Fi chip built in. But that's not all. It also has Bluetooth and GSM. Stick a SIM card in it and it'll get mobile data straight off that. If that wasn't enough, it comes with GPS, and an audio interface. You could make your own low-tech smartphone with this board. I really have no idea why you would do that, but for some reason the idea excites me.

The server side

Connecting to a public API is relatively easy, and if you just want to set up a data logging device you can use services like Xively and data.sparkfun.com. If you want your Arduino device to respond to things on the internet, the easiest way is to poll a data API at regular intervals (say every one to five minutes).

But if you want it to respond instantly to something, you can set up a permanent socket connection to the server. This is a bit trickier, but I've been working on Node.js code to do this. It's all open source so you can keep an eye on my GitHub to see how it matures.

The future

With GSM mobile data modules dramatically dropping in price, it will only be a couple of years until everything will have its own internet connection. The concept of adding Wi-Fi to a gadget will seem really old fashioned.

I've long delighted in attaching lights, buttons and tactile interfaces to my projects, and with the growth of the hackerspace network and maker community, there are so many opportunities to learn how to make stuff. It's time to take the work we've been doing inside the computer out into the real world.

Words: Seb Lee-Delisle

Award-winning digital artist and speaker Seb Lee-Delisle likes to make interesting things from code that encourage interaction and playfulness from the public. Clients include BBC, Sony, Microsoft and Google. This article originally appeared in issue 266 of net magazine.

Liked this? Read these!