Archived | Create a wifi smart button

Archived content

Archive date: 2021-06-09

This content is no longer being updated or maintained. The content is provided “as is.” Given the rapid evolution of technology, some content, steps, or illustrations may have changed.

Smart buttons are one of the current trends in IoT-enabled wearables. You can use them to trigger a diverse set of actions effortlessly. This tutorial walks you through the basic setup for creating your own DIY smart wifi button and linking it with IBM Cloud.

Initially, the ESP8266 device is in deep sleep, which helps to reduce the overall power consumption and to save the low capability batteries from running out quickly. When the user hits the reset button, it triggers a boot cycle. Once the device finishes booting up, it connects to a hardcoded wifi hotspot, connects to the public MQTT server, publishes a message with the device ID in it, and then goes to sleep. The message triggers an action on the cloud. Figure 1 shows this cycle.

Figure 1. Boot cycle
An illustration of the boot cycle

Estimated Time

This tutorial will take approximately 60 minutes to complete.


This tutorial assumes that you have basic knowledge of electronics (and optionally some soldering skills). Before beginning this tutorial, you need the following:


You can build your smart button in these 4 steps:

  1. Set up connections
  2. Install firmware
  3. Test your device
  4. Finalize the build

Set up connections

We are going to use Arduino IDE to program our smart button. To set the ESP8266 device in bootloader mode, first connect it, as shown in Figure 2.

Figure 2. Set ESP8266 in bootloader mode
Set ESP in bootloader mode

One best practice to properly boot (especially in bootloader mode) is to first reset with GPIO0 connected to GND and then leave GPIO0 as floating.

Now before connecting the ESP8266 device to your PC, you need to install a couple of chipset drivers:


Install firmware

  1. Open the Arduino IDE, and install the ESP8266 microcontroller board by adding the following url in Arduino->Preferences->Settings->Additional Boards, as shown in Figure 3.
    Figure 3. Add additional board
    Add additional board
  2. Install the ESP8266 board from library manager at Sketch->Include Library->Manage Libraries, search for ESP8266, and install the built-in board, as shown in Figure 4.

    Figure 4. Install built-in board
    Install built-in board
  3. Install PubSubClient, as shown in Figure 5.

    Figure 5. Install PubSubClient
    Install PubSubClient
  4. Now you can quickly use the following code in Arduino IDE, replace the wifi credentials, and burn it onto the ESP8266 board. Make sure that you’ve selected the right board preferences before you upload, especially the board type and port number.

     Board: "NodeMCU 1.0(ESP-12E Module)"
     Flash Size: "4M(3M SPIFFS)"
     CPU Frequency: "80 MHz"
     Upload Speed: "115200"
     Get Board Info

Once you are done uploading, you can quickly verify it by opening your serial port, and you should see the text “Published click trigger” appear every time you reset.


Test your device

For this project, we are using IBM Cloud and Node-RED to test out our device quickly.

  1. Sign in to your IBM Cloud account.
  2. Click Catalog.
  3. Search for Internet of Things Platform.
  4. Click Create to create the service.

    Figure 6. Create IoT service
    Create IoT service
  5. Open the app URL, and you should be redirected to a Node-RED dashboard. Create the flow shown in Figure 7. Copy the flow from the JSON file in my repo, and click Import from the Node-RED main menu.

    Figure 7. Flow in Node-RED dashboard
    Flow in Node-RED dashboard
  6. Try resetting your ESP8266 device and you should see a message on the debug pane in Node-RED, shown in Figure 8. This indicates that our smart button is working as it is supposed to.

    Figure 8. Message in debug pane
    Message in debug pane

Finalize the build

Once you have verified that your device is working as it is supposed to, then you can remove the pins from it and quickly solder it down according to Figure 9.

Figure 9. Circuit diagram
Circuit diagram

If the trigger is working as expected, you can use it to trigger multiple actions, like sending an SMS, controlling an actual electronic appliance, or trigger a serverless function that starts a container.

Common errors and debugging

warning: espcomm_sync failederror: espcomm_upload_mem failed

step1: connect GPIO0 ->GND step2: Reset step3: disconnect GPIO0 from GND and leave it floating (Not connected to anything)

Sometimes the current supplied by a standard USB is not enough to run the chip. Try to connect an external power supply or use a different port while programming.


This tutorial showed you how to set up an ESP8266 microcontroller and connect a smart button to it, and then program the smart button to trigger various actions. What will you program your smart button to do?