As an engineer, I like working out solutions to problems; that’s what motivates me. Some time ago I faced an unexpected challenge when my son gave me a NeoPixel Jewel 7 board [1] from Adafruit. It was a leftover from a project he'd been working on at university. This small, circular circuit board can be seen in Figure 1. The board is fitted with seven programmable NeoPixel RBG LEDs in and SMD outline. My only thought was…what on earth could I use it for?

Figure 1: NeoPixel Jewel 7 connected to an Arduino board.

NeoPixel + Arduino

WorldSemi Co. has been supplying RGB LEDs with an integrated controller in its product range for some time now. These feature a three-wire interface, allowing them to be easily "daisy-chained" for larger display applications. Each RGB LED can be addressed individually via a single serial data signal. You will get lots of hits, mostly from the Far East, when you enter the terms "NeoPixel" or "WS2812B" on eBay. Since I had already developed a whole series of Arduino projects, I knew it would not be difficult to control these LEDs with the help of the appropriate library from Adafruit. My first impressions of these LEDs were recorded on my retina…they are quite bright at full power, so please be careful not to stare at them directly!

The Arduino boards are a good general-purpose controller solution for many experimental setups but, if you need an Internet connection, it is better to use a different solution. At the time I was working with an ESP8266 MCU from Espressif in the form of the D1 mini Pro from WeMos. It seemed to me that this board, together with the NeoPixel LED board, would make for a good combination. To make sure the finished light source blended well into a domestic environment, it would be necessary to build it into a suitable housing.

Lamp tweaking

My solution to the problem was to modify a standard IKEA Grönö lamp for the housing. This lamp (Figure 2) only costs € 6.50 in Denmark (£7 in the UK), making it an ideal candidate for hacking. Should I end up destroying it in the process, then I haven’t really lost much — this should always be your number one consideration before you set about hacking anything.

Figure 2: The low-cost IKEA Grönö lamp.

Figure 3 shows the lamp internals; it’s just an E14 style lamp holder and power cord with an in-line power switch.

Figure 3: The IKEA lamp before hacking.

We will only need three wires to connect the ESP8266 to the NeoPixel board. The lamp holder base can be modified and the power cord discarded. The board is then fixed on top of the cut-down lamp holder base with glue. Finally, the power cord is replaced by three short leads (Figure 4).

Figure 4: The LED board attached atop the modified lamp holder.

The lamp controller circuit (Figure 5) could hardly be simpler. In addition to the NeoPixel board and the ESP8266, the lamp requires a 5 V, 500 mA mains adapter power supply with a micro USB plug. The rest of the project is purely software. The NeoPixel board is fitted with seven RGB LEDs, each with its own in-built controller in SMD 5050 format. You can also buy these LEDs individually under the designation WS2812B and thereby make almost any complex string or matrix arrangement. Each RGB LED takes up to 60 mA at full brightness, delivering a maximum luminous flux of 20 lm. You can hook them up in series and address them individually by shifting the RGB brightness data serially into the chain at one end. This makes them very easy to control.

Figure 5: The hack circuit is very simple: microcontroller board + LED board.

Software

An important attribute of the WeMos D1 mini Pro board is that it is supported by the Arduino IDE. Using the Arduino IDE has its advantages and disadvantages — what I find particularly relevant is that it allows me to get a project up and running quickly and without too much fuss. Before we start with the software for this IKEA hack, it is necessary to do a little preparatory work:

The software may seem a little complex given the simple task of controlling the LEDs, but the reason for the complexity is that an ESP8266 has built-in Wi-Fi support. If we want to make use of it, we will need some code. The software provides the following capabilities:

  • Creation of special lighting effects.
  • Internet connectivity via Wi-Fi.
  • Web server for lamp configuration.

The lamp can also be operated "offline" or in standalone mode. In this case, it will run through the colors of the rainbow at a predefined rate (e.g., 20 ms for each of the 8x8x8 color levels). If you want to be able to configure the lamp during operation, you must activate the Wi-Fi link so that the NeoPixel lamp can communicate via your local network. The necessary parameters for the Wi-Fi can be hard coded in the source code. This means any changes to the network parameters require a recompilation of the WeMos firmware. Otherwise, they can be defined during the lamp power-on ‘boot’ period. Once the lamp is connected to the Wi-Fi network it will be possible to carry out the following operations:

  • Turn the lamp on and off.
  • Control the brightness.
  • Change the delay time between color cycling.
  • Select color cycles (currently rainbow, rainbow cycles, static, candle flicker, and fading).
  • Set a fixed lamp color.

These operations can be performed via a very simple web interface (Figure 6).

Figure 6: Simple configuration interface of the web server.

The HTML code for the web page is generated using the getPage(string str) function.

All of this is handled in the software and, because of this, is not so easy to make changes to. However, it works well enough for our purposes. The web configuration interface updates the NeoPixel lamp via an HTTP POST request method. The basic procedure is described in my book, IoT Home Hacks with ESP8266. The software is structured in much the same way as for other similar projects I've developed. Figure 7 shows the software flow chart during setup with Figure 8 displaying the same for operation or mode selection.

Figure 7: Flow diagram of the setup process.
Figure 8: Flow diagram of the mode selection.

I quickly discovered that the fade function (increasing and decreasing brightness) requires a little more consideration. If you control the lamp brightness using values that correspond to a linear ramp function, the change in brightness is not satisfying. As shown in Figure 9, it's better to use a function that approximates a sine wave to produce a more gentle change in brightness. This brightness curve was simulated in Excel and the values implemented as an array byte fadeInterpolation[]. These values can of course be changed.

Figure 9: Optimised brightness curve for fading.

The article "LED-Dimmers" in Elektor 9/2018 describes this effect. The relation between the actual change in a physical stimulus and the perceived change is a psychophysical property characterized by the Weber-Fechner law.

Using the Lamp

As soon as the programmed WeMos board is powered on, the software will boot up and enter its switch-on cycle.

 

Wi-Fi connection (blue light)

In this phase, a connection with the Wi-Fi network is attempted using the network parameters programmed in software. During this phase, each of the LEDs will flash blue one after another.

 

Wait (red light)

After attempting to connect with the Wi-Fi (successfully or unsuccessfully), the board will look for user interaction via the USB port. During this period, the LEDs will flash red one after another. When an interaction is detected all the LEDs will go off. If after ten seconds no interaction is detected, the lamp begins running its pre-configured lighting pattern. After switch-on and with an active Wi-Fi connection, it is possible to control the lighting effect or operating mode of the NeoPixel lamp.

 

A different web interface

Once I had got this far with the project, I showed the results of my efforts to my son. He has a master's degree in interactive design and was not at all impressed with the design of the web interface. He went on to develop a new design (Figure 10), that proved difficult to implement in "hard" code.

Figure 10: A slicker web interface.

Instead, a design using HTML, CSS, and Javascript was developed. This is where the SPI flash file system comes into play. The ESP8266 MCU provides at least 14 MB of flash memory that can be used via the SPIFFS file system. In my book you will find information on:

  • Uploading files to SPIFFS.
  • Storing files in a PC for uploading.
  • Installation of the necessary software for the Arduino IDE.

If you’ve installed it correctly, your Arduino software directory should look similar to Figure 11.

Figure 11: The Arduino software directory should look like this.

Figure 12 shows the files for the web interface contained in the data folder. The latest version of the software can be downloaded free of charge from the Elektor website for this article. You will notice that the NEOPixel_new_20191222_load.js file is not listed in the data directory. These functions are coded directly in the ESP8266 software. This allows the ESP8266-MCU to configure the Web interface upon power-up using the parameters stored in the EEPROM.

Figure 12: Contents of the data directory.

The web interface concept has been designed for smartphone screens in portrait-display orientation. Since the NeoPixel lamp can be configured by sending it HTTP POST requests, it is also possible to control the lamp via the OpenHAB home automation solution — but that's another story.

A  successful IKEA lamp hack

Working with the NeoPixel Jewel board has led me to explore many different areas that I wasn't familiar with before the project started. Overall the result is quite satisfying; this IKEA lamp hack with its shoe-horned NeoPixel board has been lighting up my living room now for over a year.

 

----------------------------------------------------------------------------------------------------------------------

Want more great Elektor content like this?

--> Take out an Elektor membership today and never miss an article, project, or tutorial.

----------------------------------------------------------------------------------------------------------------------