Making a smart lamp from scratch

Making a smart lamp from scratch

Tags
IoT
DIY
Arduino
Published
Author
A step-by-step tutorial on how to go from a far-fetched idea to a working product
notion image
Expectations vs Reality
notion image

Have you ever asked yourself the following questions?

  • Can hot glue fix EVERYTHING?
  • Is it hard to make smart hardware?
  • Can you pour concrete into a cardboard mould?
If not, maybe it’s high time. But if you did, then welcome to the club! We recently had an internal hackathon at EL Passion, and I came up with a challenging idea. Making a lamp!
A smart lamp.A smart lamp out of concrete! A smart wooden/concrete lamp with an RGB LED strip… And BLUETOOTH!
Within two short days of the hackathon (with a small overhead) we accomplished all of it!

It all started with Electronics

About two months ago, I began to play around with electronics. I wanted to broaden my horizons, learn what cables to cut in the case of intelligent machines uprising and expand outside of my Frontend Engineering knowledge. I guess most of you can relate.
I started with the basics, got some components, watched tutorials and then could not decide what to do next.
After about two months, I remembered that there was a hackathon coming up!
I also recently saw Stephanie Nemeth’s talk at a front-end conference, where she had shown the fantastic things you can do with Arduino and RGB lights. So I decided I want to make something as neat as that.
But I wanted to make something that would be usable, functional and would require DIY, coding & electronics skills.
I settled on the most obvious thing one can make with lights — a lamp. And I found a perfect DIY build I wanted to imitate.
notion image
I already had an idea. Now I needed a team.

Pitching — Gathering the Team

Three days before the hackathon, we usually have pitching, where we present our ideas to the rest of the company and gather people that will work on our project. I’m not a great salesman, so mine sounded a bit like:
Ummm, so yeah, I want to make a Concrete Smart Lamp. Thank you very much.
Despite the lack of information, there were five people interested in joining my team! We had an impressive set of skills:
  • Maciej — I was like the CEO of the group. I Planned the build, made sure we have everything we need and helped to bring all the pieces together (figuratively and literally).
  • Wojtek — He took the role of the Head of Electronics. He planned out the circuit, built a prototype and worked with Jakub (iOS) to make sure Bluetooth worked. He also made sure we didn’t burn down the building.
  • Ula— The Concrete Chief of Carpentry and Hot Glue. She made sure we did things right, kept the deadline tight and worked on the wooden body of the lamp.
  • Aga— The Handyman of the team. She appeared when we needed her the most, and made sure our “manual” part of the build would work.
  • Jakub— Head of Mobile Development. Made sure we had an amazing, native, cross-platform-but-actually-only-ios-because-who-uses-android-lol app to control our lamp.

Shopping (Nerd Version)

Let’s take a look at the shopping list. I listed only the things that we used and embedded permanently in the lamp. All the additional equipment, Arduino (prototyping, loading code to AVR), and components that we broke are not counted in.
item
price
description
Concrete
25 PLN (~7$)
5 kilograms of fast-dry (1h) concrete. We used about one-third of it.
Wood
40 PLN (~10$)
I bought some low-quality pine planks, which we later painted. I recommend investing a bit more in a better type of wood if you can.
MOSFET x 3
4.50 PLN (~1.20$)
Model: N-MOSFET IRFZ44N - THT
5V Stabilizer x 1
1.5 PLN (~0.40$)
ATmega328 x 1
12 PLN (~3.23$)
Model: ATmega328P-U DIP AVR
Rotary Encoder x 2
6.60 PLN (~1.80$)
With pressable button, 20-pulse 12mm - EC11 vertical
Knob for Encoder x 2
2.40 PLN (~0.70$)
model: GCL15 silver - 6/15mm
Power Supply x 1
8.90 PLN (~2.40$)
model: 12V / 1,4A - DC 5,5 / 2,5mm
DC Socket 5.5x2.1 mm
1 PLN (~0.30$)
DIP 28 pin Socket
2 PLN (~0.60$)
So we won't have to solder AVR directly to strip board)
Bluetooth Module 4.0 BLE
30 PLN (~8$)
model: HM-10 MLT-BT05–3,3V/5V. HC-06 or HC-08 modules would also do
Cables, Solder, Strip Board
10 PLN (~3$)
necessary to connect all the things :)
12V RGB Led Strip
15 PLN (~4$)
needed length: 105cm
Overall cost: 159 PLN (approx. $43)
It’s possible to get all the items for a lower price, but in our case, it was quite urgent.
notion image
Planks, concrete, sanding paper and other useful things.

Part 1: The Concrete Base

notion image
The construction phase of the project was an exciting challenge. We spent the first 2 hours discussing how to make a cast for concrete that would meet the following requirements:
  • Leave space on the bottom for electronics
  • Leave two holes for hue and saturation knobs
  • Leave space for the wooden arm
We came up with something like this:
notion image
 
It looks simple but making it wasn’t that easy. To make the cast we used a cardboard box, a lot of grey tape, a “magic mouse 2” box, two plastic straws and some hot glue.
notion image
Later we mixed and added concrete.
notion image
Not for lactose intolerant people, sorry…
We didn’t want the cast to deform, so we used more tape and four litres of milk. We also put the wooden base into the concrete so that we would have space for it later (we nearly forgot about it though). All this is the equivalent of a “quick fix” on production systems, but as they say:
If it looks stupid but works, it ain’t stupid
~ Smart People
This quote became our motto for the rest of the build.
I don’t have an image of the base right after taking it out from the cast, but here it is after a bit of sanding and already with the wooden arm installed. We also added some silicone legs, so that the concrete wouldn’t scratch the tabletop.
notion image
You can see me soldering in the back.

Part 2: The Wooden Arm

notion image
The arm is made out of two separate parts: the top of the lamp and the base with a cable inside. We connected them with a large screw, for which we drilled holes in both top & bottom parts.
notion image
Miraculously we didn’t burn down the office.
notion image
Turns out correctly measuring things is tough.
We started by making the top part of the arm.
notion image
Full representation.
notion image
The top part was quite a challenge, as it required some delicate work with a soldering iron, but let’s start with the basics. We made it out of three pieces of wood, two thin ones (sides) and a square one. First, we glued everything together, drilled a hole for the large screw that holds the top and bottom parts together. After doing some sanding to make up for the fact that the planks were a bit crooked, Ula painted the arm, and once it dried, I went on and started mounting LED strips onto it.
First thing I did was measure out how to cut-up the LED strips. We didn’t want to put one long part inside, as it would not give that much light, so after measuring how much we’d fit, I cut up three strips, each one measuring 35cm. Then I soldered the main cable to the first part of the LED tape and used a heat-shrink tube to secure the connection.
notion image
A heat shrink tube and solder joints connecting two LED strips.
After taping the first strip onto the wood, I realised that I forgot what cables I connected to Red, Green, Blue and 12V+ outputs. It was a small setback, but we thankfully had a multimeter that allowed us to check the connections.
Next thing I had to do was to solder the two LED strips in series with the first part. It took me some time, but I managed to do it, despite having an 8$ soldering iron, with a tip that shrunk with each use. We tested it by connecting the cable to the breadboard and using one of the rotary encoders to change colour.
notion image
It’s slowly coming together.
The bottom part of the arm, as shown on the GIF above, was also quite challenging.
notion image
notion image
The lower part of the arm was complicated because we had to embed the cable inside of it. We thought about cutting it in half, carving out some space and then piecing it back together, but that would be error-prone, and time-consuming. In the end, we decided to glue on three additional pieces of wood to create some space for the cable, as shown on the graph. That’s also the reason why the part inside the base is slightly narrower.
We were missing a few parts, some pieces of wood, and the screw that would hold the arm together. We took a short break from all the work and went to the store to buy all those things.
The natural pine colour wasn’t that nice, so Ula painted both top and bottom parts of the lamp to make them a bit darker. We left it to dry overnight, and the next day, we connected it, and it looked great!
notion image
Painting process.
notion image
Cable arrangement inside the lamp.

Part 3: Software

iOS App

I was not that involved in the iOS App creation process so I cannot give a more in-depth insight into the code. Jakub took the lead and delivered a working app before the end of the first day. On the second day he expanded it to have more incredible features, such as “Ambilight” like support, where, when you play a video, the lamp syncs colours with it (demo at the end of the article).
There were some issues with Bluetooth connectivity, more precisely, one Bluetooth module connected to iOS but not to Android, and another went the other way around. Right now the lamp only works with iOS, but for an MVP, that’s enough. And the Bluetooth module can be easily switched if needed since it is not soldered in place.
Speaking from my expertise, I can say that the App looks impressive, and the speed with which Jakub delivered it is also incredible!
notion image

Arduino/ATmega Code

The whole code is open source on GitHub. You can go through it. I’m not going to dive into the deep technicalities of how it works. Wojtek, who wrote most of the code, would be better suited to do it, so I created a high-level overview of how everything works. The simplified algorithm goes as follows:
  1. Define constants for pins e.g. #define LED_RED 9
  1. Instantiate hueRotartsaturationRotary and bluetooth software serial
  1. Run void setup() { ... }
    1. Run startup sequence R => G => B => GB => RB => RG => RGB (helps with checking if colors are hooked up correctly
    2. Begin listening for bluetooth serial on 9600 rate
    3. Begin listening for hueRotatary and saturationRotary
    4. Setup brightness controls pins VALUE_INCREASE and VALUE_DECREASE to INPUT_PULLUP to avoid faulty readings
  1. Run void loop() { ... } in loop
    1. If brightness changed, update the lampColor hsv variable
    2. If hue changed, update the lampColor hsv variable
    3. If saturation changed, update the lampColor hsv variable
    4. Update actual lamp color with analogWrite() based on previously set huesaturation, and brightness in lampColor variable.
    5. Re-run the loop

Moving from Arduino to ATmega

Wojtek wrote the first version of the code for Arduino, and later I updated it to work on plain ATmega chip. The differences are minimal, as I introduced only two main changes:
  • I removed one of the Serial connections — previously we had one serial connection we used for debugging (printing to the console on the computer) and another one for Bluetooth. When we moved to ATmega, we didn’t need the debugging one anymore, which freed up two pins and simplified the connections.
  • I changed the arrangement of the pins — to better fit everything onto the stripboard, I modified the physical layout, which required changing the reference pins in the code.
You can see the pull request that contains a diff of all the changes if you’re curious.

Part 4: The electronics

Our plan was quite ambitious, for such a short time, but thankfully, Wojtek is quite smart and played around with electronics before, so he was the “lead” for this part.
notion image
We started with baby steps, testing different solutions by trial and error. Wojtek worked on both the code and the circuit simultaneously and tested how everything works. The electronics part of the lamp consisted of:
  • Microcontroller — the brain
  • Two knobs with buttons to control brightness, hue and saturation
  • Bluetooth module for wireless control
  • LED strip for light, duh…
At first, we used Arduino instead of a standalone microcontroller, and we put everything on a breadboard to simplify the development process. At the end of the second day, we had everything connected on the prototype board. Bluetooth, rotary encoders and Arduino. This is what it looked like at the demo session:
notion image
We also managed to burn down one Bluetooth chip…

Part 5: Let’s make it smaller!

After the hackathon, I wanted to spend some time and shrink the electronics to fit inside the lamp, so that the build is complete. To shrink down the electronics I had to:
  1. Replace Arduino with ATmega328
  1. Plan out connections on stripboard
  1. Solder socket for AVR so that we can replace it if needed
  1. Solder non-removable elements (transistors, DC socket etc.)
  1. Wire it all together
I started with replacing Arduino. To do so, I had to install the bootloader onto the ATmega AVR (it’s the same one Arduino uses). I watched some tutorials (linked below the blog post) on how to install the bootloader and how to use Arduino as an ISP programmer (it lets us upload software to the microcontroller without any additional hardware). After doing so, I updated the code to use slightly different pins and Voila!
notion image
Arduino disconnected successfully!
Next, I had to solder it all onto a tiny stripboard.
It was my first time working with stripboards, and I couldn’t find any simple software to help with the physical circuit design, so I went old school and planned it out by hand. I printed a sheet of dotted grid paper where dots represented holes of the stripboard. Then I drew all the connections and the way they should fit based on the current breadboard circuit.
notion image
Planning the circuit layout itself took me more than an hour.
To make it more understandable and visible, I created a graphic that represents the circuit on the stripboard.
notion image
Representation of created circuit. In the real build, I had to adjust it slightly, to fit all the components, but it looks 90% like the one above.
After about ten hours of soldering (still a newbie), and two burnt fingers (don’t touch the components if something smells funky) I managed to get it working! It went better than expected
notion image
In-progress photo, to build up for the big reveal!
 
notion image
All the pieces put together. White cables are knobs, small wires with black insulation are the LED connections
 
notion image
View from the bottom. I used a thin copper wire to connect the joints
 
notion image
If you look close enough you can see all the glue we used.
 
notion image

The Finished Product!

Check out a full demo where I go through all the features that this lamp has. Despite a couple of issues, e.g. crooked rotary knobs, and colours not being represented correctly sometimes, it works!
full demo
Video preview
 
Everything fits underneath the concrete base!
notion image
notion image
For me, and hopefully, the rest of the team, this has been one of the most satisfying hackathon projects yet. Both the process and the outcome were incredible, we had a lot of fun, and we learned a lot about working with wood, concrete and electronics.
If anybody wants to build a similar lamp or needs more details, feel free to comment and ask me anything!

Resources

Inspiration