Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Nodemcu-esp8266 Wifi controlled motor, solenoid, valve, switch, relay etc

By EG Projects June 10, 2019

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.     
Nodemcu controlling relay, motor, alarm door etc

Nodemcu controlling relay, motor, alarm door etc

Transistor relay and motor connections

Transistor relay and motor connections

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.
Nodemcu serial monitor

Nodemcu Serial monitor

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 
Nodemcu WiFi status

Nodemcu WiFi status

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.
Nodemcu relay load.ino


Filed Under: ESP8266, Microcontroller Projects

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Exporting sensor readings as data...
  • Inconsistent Charge Termination Voltage with battery charger
  • 21V keeps getting shorted to my UART line.
  • Voltage mode pushpull is a nonsense SMPS?
  • Voltage mode push pull with extra DC blocking capacitor

RSS Electro-Tech-Online.com Discussions

  • Is AI making embedded software developers more productive?
  • Why can't I breadboard this oscillator?
  • using a RTC in SF basic
  • Parts required for a personal project
  • Cataract Lens Options?

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • GigaDevice launches GD32C231 MCU series with 48MHz Cortex-M23 core and 64KB Flash
  • Advanced Energy releases 425 W CF-rated medical power supply in 3.5 x 6 x 1.5-inch format”
  • LEM combines shunt and Hall effect sensing in 2000 A current measurement unit
  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe