Introduction: Controlling Appliances From Smartphone
We all have switched on lights,fan and other appliances using Bluetooth as a for low range applications. Now we are going to look over controlling appliances using WiFi. Now we are restricted here to local WiFi only but you can host your IP on any site like 000webhost etc. to control it from anywhere from the world.Here we are going to learn that.
We would mainly understand here the working of the WiFi to switch on off appliances and the working of relay that we are going to use. NodeMCU will be here the brains of the organisations.It has inbuild WiFi capabilities. You can learn more about it in any instructables or YouTube video.So I'm not going into here its hardware here.
Step 1: Parts Required
1. NodeMCU with USB cable
2. 1 5V Relay module
3. Load..I'm here using 9V LED
4. 100ohm resistor optional
6. 9V supply
Step 2: Working of the WiFi and the Relay
The NodeMCU here connects with our router and creates a local IP.When we open that IP in our smartphone or Laptop( connected over the same router) we will see a webpage with buttons( or as you may develop in the code..we will come soon there).Then there we can turn on or turn off appliances.Now by hosting your IP you can control it anywhere around the world.But here we are restricted to local WiFi and IP only.
Now NodeMCU is a 3.3V device and it cannot drive anything that requires more than 3.3V. So here comes the relay. An electromagnetic relay is nothing but a electromagnetic switch.The COM of Relay Switch is initially connected with NC( NC and COM are thus shorted) when the input coil receives no voltage. When ever the input coil receives 5V or 3.3V it becomes energized and by mutual induction the relay switch moves from NC to NO.Now COM and NO becomes shorted. So if a load is attached keeping COM-NO as a switch, voltage appears over the load whenever the input coil receives voltage.Otherwise no voltage appears across the load when the input coil does not receive logic level 1( 3.3 or 5V).So two isolated circuits can be switched on and off with relays but it is always good to test it beforehand.
Relay are of many types,like electromagnetic relay,solid state relay,etc. Here we are concerned with cheapest electromagnetic relay only.You can also opt for Solid state relay if you wish or if you have it.
See the pics attached here for more details.
Step 3: Connections and Testing
Now see the above pic and connect as given. Here we are using a 9V light as load, now a relay can handle AC appliances as well but here We are concerned about safety too..so we are taking 9V device.
For testing the Relay( if it is at all good) we just put a 100/330 ohm load across the relay output, supply power ( just replace the light in the pic with resistor and rest is the same) and put the multimeter probes across the resistor.Power up the relay module.Now put the IN wire at 3.3 V of NodeMCU ( Here in the pic there is UNO, but it will work same with NodeMCU..don't worry). You will see the green light of the relay module ON and there is 9V at the multimeter screen. This is just done for the test of the Relay.
Step 4: Uploading Code and Test It
Now if your relay is at all okay then upload the code attached here to the NodeMCU. Change your ssid and pass of your router at the beginning of the code. then upload.
See the video if you are using for the first time. After uploading open the serial monitor and copy the URL. Now open up a browser and search for that URL. You will come with a screen as given in the pic attached.Now you can switch on and off the lights. As always you can always add more devices along with more relays and change the code as your need.You can open with laptop or mobile which are connected to the same router as that of the NodeMCU is connected.
So now you are familiar with it..so carry on with your automation project.Please comment down for any problems.