Battle of the LED Strip

Pete Januarius

Issue 7, January 2018

This article includes additional downloadable resources.
Please log in to access.

Log in

In one lounge room, a battle of Twitter hashtags is going down.

Many of us would recall a scene in Big Bang Theory series, where they experiment with turning a light on and off over the internet. What seemed like a fairly nerdy idea when it aired, is fundamental to the IoT movement. But what if, instead of flicking a virtual switch, lights automatically responded to events happening on the internet automatically? When Peter isn’t busy teaching others to code, he likes to tinker, and has created a system to do just that. We had to find out more.

This idea is a lot of fun. Are you simply listening to the public Twitter stream for a specific hashtag?

Yes it was a huge amount of fun to conceive, design and build. I was given the Arduino as a present about a year before I built the project. At the time I didn’t really know much at all about electronics or microcontrollers and it took me about a year to decide what I wanted to do with it. Once I realised that I could do something to enhance my Christmas lights with LEDs, I started to investigate further. I ran into knowledge limitations fairly quickly. LEDs, resistors, voltage regulators.. it all started to confuse me a bit. I’m from a software background and to me that’s what makes sense. Hardware is a recent venture for me and is not something I pick up all that quickly. One of the great things about this project was the fact that my (now) 11-year-old daughter was interested in helping me. As someone who runs a coding and tech training company that teaches children - this was the best outcome. My daughter even managed to help me realise that I’d put my transistors the wrong way round which saved me hours of pain!

That’s fantastic! Making the transition from software to electronics isn’t always smooth, but it’s worth it! We’re glad your daughter could help you out too!

Regarding the hashtag - yes - I simply setup a program to listen to the public twitter stream. I had to get it done by Christmas so I had a time constraint. Therefore I was looking to take the simplest route. Simplest is always best when you are delving into something for the first time. When you understand it better, then you can go crazy - in a creative way. The way the tweets were set up, all it required was for a user to tweet the hashtag #LEDThing and supplement this with a HEX colour such as #FF0000 (bright red). My NodeJS code would “find” this tweet pretty much instantaneously and so, for example, if someone in the UK tweeted, my 5m LED strip which was stuck to the wall above the TV in our playroom in Sydney, Australia - would change colour about one second later. It was so cool! The coding was the simple bit for me, as I am a software developer by trade. Go and search twitter right now for #LEDThing. Ninety per cent of the tweets are from me and my friends, I expect!

LOL - perhaps not after this feature is published! You have configured the system to read a hashtag. Have you considered adding keywords such as “red” or “blue” for the not-so-techy?

Actually no! That sounds like a great idea which I probably should have thought of before! To be honest I wanted to make it super simple for myself so parsing the message with a HEX colour such as #00FF00 was easier than deciphering a colour like “lime”. It could be done fairly easily but it just means adding some kind of colour lookup or mapping. You would also have to inspect every single word unless you forced the user to follow a format such as color:red. In that case things would be slightly easier for the poor programmer. Thinking about it, a few people had trouble with the HEX colour and I’ll bet that it made no sense to a lot of people when I originally explained it on Facebook. Using “normal” accessible colours may reach a larger audience as it takes it out of the geekyverse somewhat. I can’t believe I didn’t do that originally as I’m all for de-geekifying stuff and really hate it when things are esoteric and unfathomable.

Hey, that’s what v2.0 is all about, right?! Did you have any challenges reading the Twitterverse, or was it all fairly straight forward?

As I explained above - being a software developer meant this was always going to be the easy bit. I wanted to use NodeJS if I could, rather than Java or Python - just cause I know it inside out - so after coming upon the amazing Johnny-Five library, I realised I could achieve my end-goal with this and keep it in Javascript land. The only limitation of Johnny-Five is that you need to keep the Arduino plugged into the computer that is “feeding” it, which immediately presented me with a problem. I needed to keep the whole setup inside the TV cabinet and leave it running 24x7. This led me to the Raspberry Pi...


Ah ha! We wondered why you were running both an Arduino and a Raspberry Pi, but it does make sense now. Of course you could have run all your code on the Pi, but this was an evolution and sometimes following steps without the benefit of hindsight. Tell us about how it came about.

Yes - I realise now that I could have dispensed with the Arduino and used the Raspberry Pi alone - however... remember the original goal was to use the Arduino that was given to me as a present for Christmas? So I was determined to use this. As far as I was concerned, the Raspberry Pi was there just to provide me with an internet connection and handle the Johnny-Five library. Using NodeJS meant that I could mix and match anything I wanted in my code and so that was how it went. I just had one file with some twitter code mixed in with Johnny-Five, which allowed me to control the LEDs. At the end of the day it was convenience! NodeJS is a powerful tool on the Pi, and has access to the GPIO. Did you have problems controlling the LED Strip directly?

NodeJS is powerful - full stop! There are libraries for everything out there. Controlling the LED strip was easy. It is no different to controlling a single LED. The LED strip was non-addressable - again my philosophy of simplicity coming into play. It is so important to actually achieve something when doing anything new, otherwise can be very discouraging to try it again. If you can do so and have fun in the process, that is a bonus. This is something that we try and achieve for all the students that attend our tech workshops. Your point about the GPIO is correct. The funny thing is I didn’t even use it - I was just using the RPi as my controller computer.

We’ve all done things a certain way at one time or another, only to realise later it can be simplified - that’s part of the process! How often are you polling Twitter?

I was using the Twitter Streaming API so it was all event-based for me; in other words no polling. I wouldn’t recommend polling for anything really, as we live in the heady days of websockets and asynchronous code. I don’t exactly know what the underlying twitter library code is doing, but then I don’t really care - as long as it does the job... and it did!

So that basically means I listen for an event. When an event comes in (which means it found a relevant tweet) - I simply take action (i.e., call a function or something). When you are first doing this, it is a good idea just to console.log the event data so that you can prove to yourself that it is working. After this, parse the event and send the relevant bit of info to your function as a parameter value.

Getting Twitter to do the heavy lifting is always a great idea - especially with limited Arduino resources at your disposal. What happens if there are competing tweets at the same time? Does it blend the two values (say red and blue would display purple) or just take the latest, or something else?

Are you kidding? Er no.. the first tweet shows, then the second tweet clobbers it! Again it comes down to the fact that I just wanted the thing to work. The cheap LED strips aren’t that great for colour variety to be honest so blending the colors may only be a good idea if your LEDs can give you a sensible output colour. My idea of a HEX colour was kind of lost because my LED strip couldn’t dream of showing all those lovely colours.

One of the really cool things about the project was that my family were watching the BBL (Big Bash League) over the summer. I set the colour to as close to Sydney Sixers “pink” as I could, as that was our team. I then asked people to tweet the colour of the team that they thought were going to win the current match. This was a lot of fun.

Testing the LED strip.

That does sound like a lot of fun! So “newest Tweet rules”! We love it. We could see a fun team game here, listening for two competing hashtags, where the brightness of the two colours is determined by tweets per hour or similar. Have you experimented with anything like that?

I haven’t, but I think that could have the makings of an interesting game. You could have a red team and a blue team, and have a kind of swing-o-meter that indicates the current state of play of the game (which could be anything). That way you could tell who was winning at any given point in time (i.e., if the LED strip is “redder” then the red Team is winning. You wouldn’t even have to use Twitter. Any API in the world could be used in any context. It is just a matter of imagining something interesting. Hmmm... I wonder!

Perhaps we’ve just come up with the next Olympic sport. Twitter hashtag decathlon! Okay, maybe not... but it would be fun to experiment with. If you had your time over to restart this project again, what would you change?

That’s another great question. I think it’s always important to keep learning and despite the fact that I generally have very little spare time (I have four children and a busy job) - I still think it’s very important to push forward in my learning and understanding, using my creativity where I can, and leveraging anyone else’s whenever possible. So what would I do?:

  • I would dispense with the Arduino and use the Raspberry Pi.
  • I would still use NodeJS as I don’t believe other languages can compete here!
  • I would use a better quality set of LEDs and definitely use an addressable strip so that I have a variety of patterns I could show.
  • I would consider building some feedback for the user. The big problem with this project was that only I and whomever was in my front room could really enjoy it, because no one else could see the LEDs. Therefore I would think about snapping a photo and uploading it to a website for every “message”. That way the user who changed the colour could actually see it happen.
  • If the strip is addressable I might consider doing something like morse code along it - who knows? I’m sure it is possible!
  • I would definitely build it as a project to use within my company as a learning experience.
  • I would do something to stop values being “clobbered” (e.g., queue up “messages” and give each one their moment of glory for a minimum amount of time).
  • I would use Bluetooth or WiFi to also be able to change the lights through a colour wheel interface - just for a bit more flexibility and fun!
  • I would move it beyond the realms of the breadboard and into “PCB reality” - though to be honest I’m not sure of the best way of doing this.

With something like this though, the possibilities are endless. I’m sure others could think of different and better ideas than me!

working LED
The working LED strip.

Asynchronous Twitter / photo reply magic? Now that would be fun... just don’t include the original hashtag or you might create an infinite loop and break the internet! What other amazing projects are you working on now?

Well - I’m not sure I would call my projects amazing, but since this one I’ve built an RFID reader - I was thinking of registering our classes in 2018 this way. I have also built an RC Car from scratch - chassis and all; it was pretty simple to be honest. I used an Arduino Mega and a basic RC Controller and motor driver. I found some code to control the motor on the internet. It all worked first time so I was very happy! I also built an IoT transmitter and receiver using MQTT and the Heroku cloud product as my broker. The idea here is to make a morse code toy, which children can use to learn morse code and play with. This is still a work in progress. I used ESP8266-12E boards for this but need to get the power consumption down.

Right now I’m building an arcade controller (think 1980s-style) but it is kind of secret so I’m not going to say much about it right now. I’ve built the box out of pallette wood and so far so good... This will be a Retropie thing - way cheaper than an XBox and much more fun, plus you learn a bunch of stuff along the way. We should all do this instead of just wasting our money on consoles, TVs and electronics, which has to be bigger and better than the last one. Let’s teach our kids to be producers and not just consumers - and what better way than to model that behaviour ourselves!

After this I would love to build an automated watering system with moisture and temperature sensors. I’m sure this will be a big undertaking, but we love vegetable growing in my family, so I am itching to do this one.

To be honest I wish I could just have a whole year building stuff - I’m glad my job let’s me do this for at least some of the time!

Don’t we all? Thanks for taking us through your project Peter, it really is amazing!

Nexgen Codecamp

Nexgen Codecamp started in July 2016 and are focused on educating students in emerging technology. Growing from a code-only bootcamp, the organisatoin has now broadened its vision and expertise to provide new opportunities for students, teachers and schools in the form of a holistic Young Technologists program for students and professional learning opportunities for teachers.

In 2018, Nexgen Codecamp will be focussing on incursions, holiday courses and our Young Technologist Program. Our long-term objective is to help schools teach technology, and whilst we are a commercial company we are more about supporting schools and teachers, rather than commercialising education.

We are always on the lookout for instructors who are both passionate about technology, and passing on their knowledge to the next generation, so if you live in or around Sydney, please reach out and connect with Nexgen Codecamp.

hands on at camp
Getting hands-on at Codecamp.
happy customer