Friend Lamp - Stay in Touch With Light

by PaulW45 in Circuits > Raspberry Pi

91 Views, 0 Favorites, 0 Comments

Friend Lamp - Stay in Touch With Light

IMG_0805 (1).png
Friend Lamp

The Friend Lamp lets someone know you are thinking of them with just a touch. This simple lamp glows with a colour. Touch the top and the colours change. When you see a colour you like, let go. The colour you have chosen will be sent to your friend's lamp. They will see the colour change and know that you were thinking of them.


Supplies

IMG_0797.png

Parts you will need for each lamp

  1. Raspberry Pi Pico W
  2. TTP223 Touch Button Module - I got 10 for around $2
  3. WS2812 RGB LED board - I used these
  4. A lamp you can modify - These are the ones I used
  5. A small stand off to mount the LED board.
  6. Double-sided tape.
  7. Thin hookup wire

You can adapt this project to almost any lamp. I found these ones on AliExpress for around $5 and they ended up being perfect - I was able to repurpose the touch pad and they were the perfect size for the 12 LED ring I chose.

WS2812 LED boards are available in different shapes and sizes; It is simple to modify the code to adapt to boards with a different number of LEDs.

Be sure that you get a genuine Raspberry Pi Pico W - I initially got some "compatible" boards, but they didn't have the correct Wi-Fi chip.

Tools

  1. Soldering iron
  2. Solder
  3. Small Philips screwdriver
  4. Side cutters
  5. Scissors
  6. Drill with 2.5mm bit

Disassemble the Lamp

IMG_0759.png
IMG_0760.png

The first step in this project is to disassemble the lamp and remove the unnecessary components.

The lamp simply pops apart by levering the top away from the bottom.

This will reveal a small circuit board, a battery and a wire leading to the touch pad on the top of the lamp.

When I opened my first lamp the touch pad wire pulled away from the board, but this wasn't a problem because it needs to be disconnected anyway. If your wire is still attached, I recommend desoldering it rather than cutting it. You want to keep the wire as long as possible for ease of assembly later, and you will be able to reuse the already stripped end to connect to the touch button module.

With that wire disconnected you can then remove the four screws holding the circuit board and the battery connected to it.

NOTE: The battery in my lamp was charged, so be careful not to short it out; Batteries can get hot and catch fire if shorted. I suggest cutting the wires so that they cannot short. If you decide to dispose of the battery, make sure you do so safely. Do not place it in your household rubbish.

The lamp's existing circuit board can be flipped over to provide a platform for installing our new circuit. Remove the small white plastic actuator from the switch and use a pair of side cutters to cut the black actuator close to the switch body.


Mount the LED Ring

IMG_0766.png
IMG_0767.png
IMG_0768.png

Insert the circuit board back into the lamp upside down. Place the LED ring so that it is approximately centred around the hole in the board. Use a marker or similar to mark the board through one of the mounting holes on the LED ring. Make the mark as far away from the USB/Switch slots in the lamp's lower case. This will ensure we have enough space for the Raspberry Pi board.

I mounted the LED ring with a small standoff I found in my parts box. It needed a 2.5mm hole. I used a drill with a 2.5mm bit to make the hole in the lamp circuit board. I also needed to enlarge the existing mounting hole on the LED ring. There are circuit traces on the LED ring board, so be careful when drilling. Use a slow speed.

Once you are happy with the fit, remove the LED board so that you can make the connections.

Connect the Circuit

Schematic_New-Project_2025-01-09 (2).png
IMG_0770.png
IMG_0773.png
IMG_0775.png
IMG_0789.png

The wiring of the circuit is quite simple. The LED ring needs to be connected to the Raspberry Pi. The TTP223 needs to be connected to the Raspberry Pi and the existing touch pad on the lamp needs to be connected to the TTP223.



Connect the LED ring

There are four solder pads on the LED ring. We need to connect to three of them:

  1. DI - Data input
  2. 5V - 5V supply
  3. GND - Ground or negative supply

I used 3 wires split off some ribbon cable I had around, which keeps the connections neat, but you can use individual strands of wire. Leave yourself about 5cm of wire from the LED module to connect to the Raspberry Pi.


Connect the TTP223 module

The TTP223 module has three connections. We need to solder wire to these as we did with the LED ring. These connections are:

  1. VCC - 3.3v supply
  2. I/O - This indicates when a touch is detected
  3. GND - Ground

Again, I used 3 wires split off some ribbon cable. Leave about 6-8cm of wire to connect to the Raspberry Pi.

The module has a touch sensor area on the circuit board, but we want to make use of the touch plate that is on top of the lamp. To do this we need to solder the wire that we disconnected earlier to pin 3 on the TTP 223 IC.

If you hold the TTP 223 module so that the black IC is on the left, pin 3 is the pin on the bottom left of the chip.

You will need a fine tipped soldering iron and a steady hand. Be careful to ensure you don't accidentally connect pin 3 to the pin next to it.

The TTP module fits nicely up inside the plastic tube that carries the wire from the touch sensor on top of the lamp. Be careful not to apply too much tension to the wire as you assemble your lamp as the wire can easily come away from the board.

If it does, simply re-solder it. In my case I ruined a couple of modules trying to connect to the small test point at the bottom of the board before deciding on connecting directly to the IC. I was glad I got the 10 pack!


Connect the Raspberry Pi

The final step is to connect the six wires from the two modules to the Raspberry Pi. The circuit diagram is shown above. The connections are:

  1. WS2812 5V to Raspberry Pi VSys (Pin 39)
  2. WS2812 Gnd to Raspberry Pi Gnd (Pin 38)
  3. WS2812 DI to Raspberry Pi GP27 (Pin 32)
  4. TTP223 VCC to Raspberry Pi 3V3 (Pin 36)
  5. TTP223 Gnd to Raspberry Pi AGnd (Pin 33) OR Gnd (Pin 38)
  6. TTP223 IO to Raspberry Pi GP28 (Pin 34)

NOTE: Ensure that you route the wires from the TTP223 through the centre of the LED ring before soldering them to the Raspberry Pi. The wires from the LED module itself do no need to go through the centre.

Set Up an MQTT Service

Friend Lamps communicate by sending messages over MQTT. Each lamp connects to a configured MQTT broker and sends a message on a topic when it changes colour. Other lamps that are subscribed to the same topic get that message and change their colour to match.

There are a few different free MQTT brokers available. I am using iotBind. They have an easy to use broker that supports up to 20 devices with no charge.

Once you have selected and signed up for a broker you will need five pieces of information:

  1. The broker host name
  2. The broker port (typically 1883)
  3. The username to authenticate to the broker
  4. The password to authenticate to the broker
  5. Your topic name.

You will use these in step 5.

Set Up the Raspberry Pi Pico

Set up the firmware

If you have already loaded Micropython firmware into your Raspberry Pi and set up Thonny (or other editor of your choice) you can skip ahead to the next section Load the code.

If need to do these things, you can head over to this Instructable and then come back here when you are done with step 3.

Load the code

For this step I am going to assume that you are using Thonny to work with your Raspberry Pi. If you are using some other editor then I assume you know what you are doing and will be able to work it out.

The Micropython code for the FriendLamp is available from GitHub. You can either clone the repo or just download the repo as a zip file.

  1. Once you have all of the files in a folder, open that folder in Thonny and connect your Raspberry Pi via a USB cable
  2. Press the 🛑 button on the toolbar and ensure that your Pi is responding
  3. Select "Manage packages..." from the "Tools" menu
  4. Select "Install from a requirements file"
  5. Select "Requirements.txt"
  6. Configure your mqtt broker:
  7. Open the mqtt-sample.json file in the Thonny editor and change the values to those you obtained in step 4
  8. Save the file as mqtt.json.
  9. Select all of the files in the folder in the top pane in Thonny
  10. Right click and select "Upload to /"
  11. Select the main.py file and click the green ▶️ button

If all goes well, the LED should turn red and you should see a message in the console that the lamp is in setup mode.

Connect to your Wi-Fi

To connect to your Wi-Fi network, the Raspberry Pi needs to know your Wi-Fi network name (SSID) and password. Note that the Raspberry Pi only works with 2.4GHz Wi-Fi networks.

Use your laptop or phone to connect to the FriendLamp Wi-Fi network. The configuration web page should open and you can enter your network name and password.

After you save these settings, you will need to press the green ▶️ button to restart the lamp.

This time you should see messages on the Thonny console that your lamp is in application mode and that it has successfully connected to the MQTT Broker.

Hold your finger on the touch pad and the lamp will cycle through random colours. Remove your finger when you see a colour you like. This colour will now be sent via MQTT. If you have another lamp set up, it will change to that colour.


Final Assembly

IMG_0788.png
IMG_0791.png
IMG_0805 (1).png

You can now reassemble the lamp.

  1. Mount the LED ring on the stand off and tighten the screws/nuts
  2. Put the circuit board in the lamp and fasten with screws (I found that I could only secure it with two screws once it was upside down, but that was sufficient)
  3. Use some double-sided tape to secure the Raspberry Pi to the lamp board. Line up the Raspberry Pi USB connector with the "switch" hole on the lamp base. Connect the USB cable and push the Raspberry Pi board as close to the edge of the lamp base as you can.
  4. Gently press down on the Raspberry Pi board to fix it in place.
  5. Insert the touch sensor board into the central pipe
  6. Snap the lamp back together.

Repeat these steps with a second lamp and give it to a friend. Of course, you aren't limited to just two lamps; You can have as many as your MQTT broker allows.

Enjoy