256 bit shiftregister (74hc595) powered by ESP8266

157 Lightbulbs controlled by ESP8266

For an art installation (Christaan Boltanski @ Oudekerk — Amsterdam) we had 157 light bulbs randomly laying on the ground. Every day at 12:00h one bulb needed to be switched off.

Problem

You could just unscrew a lightbulb everyday, but how would you test if everything is still working? Rescrew all light bulbs :-| Perhaps mounting 157 wall sockets and plugs to 1m2, nahh doesn’t fit.

This shows the space we had to work with. Mounting wall sockets was no option.

Solution

To save space and keep everything safe, we need relays and some logic. ESP8266 to do http requests, Shiftregisters to control a lot of relay’s, circuit breakers to make it more safe. Cherry on top would be a dimmer for the 2 mains group we have, 2 x 16A (220v).

Shiftregisters

Off the shelf Shift Registers did not fit the specs. They only exist in 8 bit per board. Every relayboard has 16 relays, so 2 shifregister boards per relayboard (8bit x 2 boards = 1 relay board with 16 relays). Mounting and chaining these boards are fine if you just need a few. Talking about 32 boards makes it to impractical.

Custom PCB

Knowing the technical solution it was time to build a custom PCB with 16 (74hc595) then stack just two of these boards and bob’s your uncle. I had designed custom PCB’s in Illustrator but never with real PCB design tools. Starting with the free version of Eagle was a disappointment, buying a license even more. You pay the license to get a bigger design canvas. But I had no clue how big it was going to be. Autodesk did refund my license, kudos! Open Source all the way and really Kicad is your friend, just like Joe ;)

Kicad

It is never easy to wrap your head around new software. The youtube channel of Contextual Electronics did help me a lot. Just open Kicad and follow everything step by step. Sure after a few day’s you have your PCB design. Do not forget to add the Kicad and openhardware logo to your PCB, it is nice for the community and looks cool :)

Getting your PCB printed is easy and cheap. I choose to make one in The Netherlands (mijnprintplaat.nl) and the other in China (PCBway). The only two differences where the production time and price. China: 7 days, €35, Netherlands: 14 days, €152,- I only did a visual inspection of the boards and soldered one of each supplier. Well no difference. Future projects will be send to PCBway.com

Download 128bit shiftregister board (Kicad files)

Fresh and naked 128bit shiftregsiter PCB
Kicad schematic, routed schematic and the working 128bit board.
First test with the new 128bit shiftregister board, I’m a happy camper. ;)

The Build

Having all restrains and specs it was time for some elbow grease. Building a massive relay box is no rocket science but you need your brain to think ahead and recheck your wiring.

Shopping list

  • NodeMCU ESP8266 + 0.96 Inch OLED
  • 2 x 10.000 Watt dimmer (80 x 30Watt = 2400Watt per group)
  • 30W 5v Power supply
  • DC booter for case fan
  • 2 x PC case fans
  • 2 x 100 mtr wire; Red, Black
  • 3 x 16A circuit breakers
  • Big metal case
  • Din rails 6 x 40Cm
  • Din rail connectors (dual and single)
  • Din rail bridges
  • Mobile wifi
  • Wire stripper
  • Makerbeam stuff to fiddle with mounting issues
  • Cable binders
  • 10 x relayboard (16) or as many as you need

Total costs for the build is around €1700,- for the hardware and PCB’s only. Mistakes, wrong decisions, faulty hardware, hours of work, rework not included. To get an idea I started working in august 2017 and the project was live in November 2017. About 3 months of work, that’s only the evening hours.

NodeMCU ESP8266 + 0.96 Inch OLED Board. Having a display is practical for debugging. You know what’s going on and when there’s a fault other people can call me and tell me the error displayed on the ESP.
The empty box
Mouting dinrails in to see how everything is going to fit.
Starting with a basic layout where we divide the 2 x (220v) mains groups into sections that can be dimmed.
Cable guy is working.
Left: ESP connected to the dinrail. Right: DC booster to power the case fans (12V).
Tidy up cables
Ready for the first boot.

Installation

The small electronics are all done and the relays are clicking away. The machine is brought to the Oudekerk for final installation. After a few tests we discovered some faulty power lines and light fixtures. Which caused the breakers to fire. Double checking every powerline before installation is a necessity. The failure number of 157 light bulbs was about 15%. Either the bulb did not work at all or failed short after. That is why the ESP program has a test cycle.

Installation of the 157 wires.
Time to do some bulbing.

Time to test

A small test program will fire all lights in sequence and has nothing to do with the art, it’s only for debugging.

Code

The ESP will get JSON data from a webserver. In our case a google appengine instance. The ESP will only read, every 10 seconds, the file an do as it is told.

JSON data served from a google appengine

The app will return the current lights that need to be switched on. Every day @ 12:00h it will change this value.

{"switch": "12:00","appinit": "2","title": "oudekerk","description": "Boltanski - Oudekerk","enddate": "2018-04-30","totallights": "160","id": "xxxxxxxxxxxxxx","lights": 54}

ESP Source code

The code was written on the go, and surly can be compactor, nicer. To do the bitshifting I used the Arduino Shifty library. That worked like a charm for about 16 x 8bit (74HC595) = 128 bits. But I needed more. ShiftRegister74HC595 to the rescue. Out of the box it just worked with 32 x 8 (74HC595) = 256 bit shift register. Download source

Troubles

Everything on a hardware level was fixed quickly. New cables, light bulbs etc. The only thing the ESP did was sudden reboots. After debugging the ESP with some stacktraces, I found some code bugs. I simplified the program, and made the logic that it did nothing when; for example the wifi was shutdown or the program was unable to get a new update from the server. This new program I tested for 2 days without any sudden reboot. Stacktrace your code and let it run for a few day in a controlled environment is…handy :)

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.