The age of internet of things makes life easy. How about making it more easy by controlling your every day appliances with your cell phone. This is a simple tutorial on effectively controlling a motor, switch, solenoid, water valve, door or relay with nodemcu esp8266 wifi module. The end mechanical device is controlled through internet. A simple web page list downs the control buttons. Nodemcu will respond to each button press. Web page can be accessed on desktop as well as mobile devices. Nodemcu is working as a server, serving a web page. Client device desktop or mobile is working as a client. Both the server and client must be connected to a same network(WiFi device) in order to work properly.
Solenoid/Relay is controlled with pin#13 or D7 of nodemcu. Note that nodemcu can not supply enough output current to drive a heavy load like motor, alarm etc. A transistor is switched on and off to control the output load. Transistor also helps in isolating the heavy load circuit from nodemcu. It prevents nodemcu from back emf current spike produced by relay coils. An NPN transistor is used in the project. Resistor Rb value can be between 220 ohm to 1k ohm. A fly wheeling diode is connected across the coil of relay to protect the circuit from back induced current when power is shut off. Vs can be from +5v to 24 volts. With this configuration one can connect much heavier loads at the output of the relay. Now you can control motors, solenoids, alarm, cameras and many other appliances easily. Note the ground of external voltage and ground of nodemcu must be connected with each other for proper circuit working. Circuit diagram of the project is given below.
Solenoid/Relay is controlled with pin#13 or D7 of nodemcu. Note that nodemcu can not supply enough output current to drive a heavy load like motor, alarm etc. A transistor is switched on and off to control the output load. Transistor also helps in isolating the heavy load circuit from nodemcu. It prevents nodemcu from back emf current spike produced by relay coils. An NPN transistor is used in the project. Resistor Rb value can be between 220 ohm to 1k ohm. A fly wheeling diode is connected across the coil of relay to protect the circuit from back induced current when power is shut off. Vs can be from +5v to 24 volts. With this configuration one can connect much heavier loads at the output of the relay. Now you can control motors, solenoids, alarm, cameras and many other appliances easily. Note the ground of external voltage and ground of nodemcu must be connected with each other for proper circuit working. Circuit diagram of the project is given below.
Project code is written in arduino ide. You must first include the nodemcu board support for arduino ide. Open arduino ide go to preferences. In the additional board managers URL: enter http://arduino.esp8266.com/versions/2.4.1/package_esp8266com_index.json. Now go to Tools-Boards-Board Manager, and search for ESP8266 and install the package. ESP8266WiFi.h header file functions are used in the project. This file must be included in the arduino library folder in order to successfully compile the project.
Upload the above code in nodemcu, make sure to select correct board and uploading speed in arduino ide before uploading. After successful uploading open the arduino Serial Monitor. You will see the nodemcu WiFi connection status and server working or not. If server is properly started you will see a URL displayed in serial monitor. The URL will be some thing like in the picture on right side.
|
This URL is actually the web page served by the nodemcu. Enter this URL in your mobile or desktop browser and press Enter button. Make sure your client mobile or desktop is connected to same network to which nodemcu is connected. Browser will display a page with two buttons
Pressing the buttons will make the output load connected to nodemcu to turn on and off. The status of load will automatically be changed when any button is pressed.
Download the project code. Folder includes arduino .ino file. Please provide us your feed back on the project. Write your comments and queries below.
Filed Under: ESP8266, Microcontroller Projects
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.