NodeMCU, a popular IoT development board, provides a flexible platform for connecting and controlling various devices. In this article, we will explore how to interface a NodeMCU with a 9V solenoid motor using a relay module and a 9V battery. This setup allows for safe and efficient control of the motor, making it suitable for a wide range of projects.
Components Required: | NodeMCU |
To get started, gather the following components:
NodeMCU development board
9V solenoid motor
Relay module (suitable for the motor's voltage and current)
9V battery or suitable alternative power supply
Jumper wires
Breadboard (optional, for easier connections)
Circuit Connections:
Follow these steps to connect the components correctly:
1. Connect the positive terminal of the 9V battery to the VCC pin of the relay module.
2. Connect the negative terminal of the battery to the GND pin of the relay module.
3. Connect the input signal pin (IN) of the relay module to a digital output pin of the NodeMCU (e.g., D1).
4. Connect the solenoid motor's positive terminal to the common (COM) pin of the relay module.
5. Connect one end of a diode (e.g., 1N4007) to the solenoid motor's positive terminal.
6. Connect the other end of the diode to the normally open (NO) pin of the relay module.
7. Connect the solenoid motor's negative terminal to the GND pin of the relay module.
Code Explanation
The code starts by defining a constant variable "relayPin" as the digital output pin (D1) of the NodeMCU, which is connected to the relay module. In the "setup()" function, the relay pin is initialized as an output. Within the "loop()" function, the motor is turned on by setting the relay pin to HIGH, and a delay of 2 seconds is added to keep the motor running. Then, the motor is turned off by setting the relay pin to LOW, followed by another 2-second delay to keep the motor off. This loop continues indefinitely, providing repetitive control over the motor.
Code
Working Principle:
The relay acts as a switch to control the solenoid motor's power supply. When the NodeMCU sends a HIGH signal to the relay module's input pin, the relay closes its normally open (NO) contact, allowing current from the 9V battery to flow through the motor. This activates the motor and causes it to operate. When the NodeMCU sends a LOW signal, the relay opens the contact, cutting off the current and turning off the motor.
See Also
Check out our Free NodeMCu Projects Playlist - NodeMCu Projects
Order Electronics Projects
Want us to guide you through your project or make the project for you? Click on the button below or reach out to us via Call/WhatsApp at (+91) - 7600948607
You can -
Order Basic Electronics Projects
Order Embedded Systems Projects
Order IoT Projects
Order FPGA Projects
Order VLSI Projects
Order Image Processing Projects
Order Matlab Projects
Order TinkerCAD Projects
Order Proteus Projects
Click on the button below to fill out the project inquiry form -
Create Various Projects
Check out our Free Arduino Projects Playlist - Arduino Projects
Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects
Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects
Check out our Free IoT Projects Playlist - IoT Projects
Check out our Free Home Automation Projects Playlist - Home Automation Projects
Check out our Free NodeMCu Projects Playlist - NodeMCu Projects
Follow us -
Please do follow us i.e. #learnelectronicsindia to get daily updates about new blogs, videos, courses, products, offers, competitions, quizzes, and Internship Opportunities.
LearnElectronics India simplifies complex concepts beautifully. Thank you!
This blog post by Learn Electronics India is a goldmine for anyone looking to explore the fascinating world of interfacing NodeMCU with a solenoid motor using a relay. The author's passion for electronics is evident throughout the article, and their ability to explain complex concepts in a digestible manner is truly praiseworthy. I can't thank you enough for sharing your knowledge and empowering aspiring electronic enthusiasts like me.