Upgrade Your Smart Lamp to Work Without WiFi

Add a push button to an ESP8266-based smart lamp, use AI to write the firmware change, then upload it so brightness can be controlled even when WiFi is unavailable.

In the previous project, we built a WiFi-controlled 3D printed smart lamp. It worked great until the WiFi didn't, which always seemed to happen when someone wanted to turn it on. This update adds a physical push button and uses AI to help modify and upload the code.

When finished, the button cycles the lamp through low, medium, and high brightness without a phone. If you haven't built the lamp yet, start with the smart lamp guide.

The smart lamp project

Tools used to add the button

Step 1: Install the Button

Use a non-latching push button, the kind that springs back up when released, like a garage-door button rather than a wall switch. A latching switch will not cycle brightness correctly.

Choose a location on the lamp, drill a clean hole, and use the utility knife to remove rough edges. Mount and wire the button. Once the hardware is installed, move on to the firmware.

Step 2: Write the Code with AI

ChatGPT is one option for AI-assisted coding. The important rule is to be specific: AI takes instructions literally, and missing details invite guesses.

"Add a button to my lamp" might produce a power toggle or color-changing feature. The desired behavior here is to cycle through off, low, medium, high, and back to off. A clearer prompt is:

Add a push button on pin D2 that cycles between off, low, medium, and high brightness levels for the lamp's white LEDs.

You can paste your existing working code into the chat so the tool can use it as a starting point. Ask for a complete ready-to-upload program if that is easier than merging code snippets; reviewing how it fits together is still useful for learning.

Step 3: Upload the Code to the ESP8266

  1. Download and install the Arduino IDE.
  2. Open Preferences > Additional Board URLs and add the ESP8266 board package URL.
  3. In Boards Manager, search for ESP8266 and install it.
  4. In Tools > Board, select NodeMCU 0.9 (ESP-12 Module).
  5. Connect the ESP8266 over USB and find its port under Tools > Port.
  6. Click Upload.

Adding ESP8266 support in the Arduino IDE

If compilation reports Adafruit_NeoPixel: No such file or directory, install the missing libraries through Library Manager:

  • Adafruit NeoPixel
  • ArduinoJSON
  • WiFiManager by tzapu

Installing the required Arduino libraries

Upload again. When it finishes, disconnect the ESP8266 from the computer and reconnect it to the lamp.

Step 4: Test Your New Smart Lamp

Press the button and check that brightness cycles through off, low, medium, high, then off again. The lamp now combines WiFi control with a physical control that works without a phone.

Recap

We added a button to the lamp, modified its housing, used AI to help write the firmware logic, and flashed the updated program to the ESP8266. The source article also offered a direct code download; add its file link here if you are restoring that download on this site.