IoT Set-up to Operate/control 220-240 Volt AC Bulb/Device; NodeMCU Amica + 5V Relay + MQTT + Arduino IDE + Web Browser (HTML + JavaScript/jQuery)

What are we messing with?

IoT (Internet of things) set-up to operate/control 220-240 Volt AC Bulb/Device

NodeMCU Amica + 5V Relay + MQTT + Arduino IDE + Web Browser (HTML + JavaScript/jQuery)

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

Make sure to follow the instructions mentioned in the below link to proceed further.

https://www.instructables.com/id/Quick-Start-Guide…

Hardware:

NodeMCU Amica

  • Executes Arduino program(sketch)
  • Has built-in ESP8266(WIFI module) which is the main reason to prefer NodeMCU over Arduino UNO board

5V Relay

  • To switch any 240V device(bulb in our case) ON/OFF

Miscellaneous

  • Jumper wires to connect the circuit
  • Breadboard
  • 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

Software:

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)

Arduino IDE

  • To develop a program which will subscribe to MQTT broker and fetch the latest message available and accordingly switch the 5V Relay

Web Browser

  • 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

HTML script:

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

Arduino program(sketch):

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.

Source: IoT Set-up to Operate/control 220-240 Volt AC Bulb/Device; NodeMCU Amica + 5V Relay + MQTT + Arduino IDE + Web Browser (HTML + JavaScript/jQuery)


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top