What are we messing with?
IoT (Internet of things) set-up to operate/control 220-240 Volt AC Bulb/Device
WARNING!! – THIS PROJECT INVOLVES WORKING WITH HIGH VOLTAGES THAT CAN CAUSE SERIOUS INJURY, DEATH, AND/OR SET YOUR HOUSE ON FIRE. PLEASE PROCEED WITH CAUTION, AND ALWAYS MAKE SURE CIRCUITS ARE UN-PLUGGED BEFORE WORKING ON THEM
Step 1: Prerequisites
- Executes Arduino program(sketch)
- Has built-in ESP8266(WIFI module) which is the main reason to prefer NodeMCU over Arduino UNO board
- To switch any 240V device(bulb in our case) ON/OFF
- Jumper wires to connect the circuit
- 240V light bulb with lamp holder
- Electrical wires to connect bulb & relay to 240V AC power supply
- USB wire to upload program to NodeMCU board from computer
MQTT (MQ Telemetry Transport)
- Medium of communication between NodeMCU development board and client(web/mobile) application - publish/subscribe pattern
- You may use MQTTLens chrome plugin to test out the connection to broker and try subscribing & publishing (not necessary needed)
- To develop a program which will subscribe to MQTT broker and fetch the latest message available and accordingly switch the 5V Relay
- Takes the user input command and publish to MQTT broker
Step 2: Wiring Diagram - Fritzing
Although this fritzing project gives an insight to the required wiring setup, Below is a theoretical brief of the same:
NodeMCU 3V3 >>Relay VCC [red jumper wire]
NodeMCU D0 >>Relay IN [blue jumper wire]
NodeMCU GND >>Relay GND [green jumper wire]
Relay NO (Normally Open) >>Bulb +ve
Relay COM (common terminal) >>240V AC Live
Bulb -ve >>240V AC power Neutral
Step 3: Software Setup
When you open this html in browser
- Script will connect to the MQTT broker(iot.eclipse.org) and subscribes to a topic(/lamp/status/)
- Once you see connection is successful, click on the switch button which will accordingly publish the message to the topic
This is the program should be uploaded to NodeMCU board, it will do the following work
- Connects to our WIFI(to specified SSID & password)
- Then connects to the MQTT public broker(iot.eclipse.org) and subscribe to the topic(/lamp/status/) same as HTML script
- When HTML does a publish to the topic in MQTT broker, callback is executed which will digitalWrite HIGH/LOW to D0 GPIO pin in NodeMCU board which in turn triggers 5V Relay ON/OFF
Step 4: Wrap Up
If you will just replace the bulb connections to any other electrical device like fan, computer, fridge etc., you should see it working for all of them.
But make sure you got the bulb working in the first place.
Thanks for reading.!
NOTE: I was not able to find any one specific article that is doing all the stuff that is being discussed here, But I have followed/referred to many different articles (from wiring to source code) to finally get to this set up, unfortunately I have lost track of most of them. If you have found any posts which have similar content kindly let me know. I am happy to credit them here.
P.S. To view images in detail with more clarity, please click on image which will open a popup of the same, and then click again which redirects to another page with a list of different image sizes where you can download better quality version of the image.