Learn more >
Krishna Chaitanya | Published February 26, 2019
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.
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:
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.
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:
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.
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.
Install PubSubClient, as shown in Figure 5.
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.
For this project, we are using IBM Cloud and Node-RED to test out our device quickly.
Click Create to create the service.
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.
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.
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.
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.
warning: espcomm_sync failederror: espcomm_upload_mem failed
step1: connect GPIO0 ->GND
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?
In this series, you will learn how to build a simple - but complete - home automation system. In doing…
Learn when, where, and why a developer might choose one type of hardware device or sensor over another for an…
Get the Code »
Learn how to build a real-time chat application in a few minutes by simply dragging and dropping components and wiring…
Back to top