IDPL - 5: Integration of Actuators with NodeMCU
Integration of Actuators with NodeMCU (Servo Motor/Relay)
Objective
To interface a servo motor and a 5 V control relay with NodeMCU ESP8266 and control the actuators using a simple program.
Required Components
- NodeMCU ESP8266
- Servo motor
- Single-channel 5 V relay module
- External 5 V power supply
- Jumper wires
- Breadboard
Circuit Diagram
Board Connections
Pin Connections
| Component | Connection |
|---|---|
| Servo Signal | NodeMCU D5 (GPIO14) |
| Servo VCC | External 5 V supply |
| Servo GND | GND |
| Relay IN | NodeMCU D1 (GPIO5) |
| Relay VCC | 5 V supply |
| Relay GND | GND |
Important: The relay module's control side operates at low voltage, but the relay can be used to switch a 230 V AC load. Do not work on the 230 V side while it is energized. Mains wiring should only be performed by a suitably qualified person using appropriate electrical protection and insulation.
Working Principle
A servo motor is an actuator that can rotate to a specified angular position. The NodeMCU sends a control signal to the servo through D5 (GPIO14). In this experiment, the servo is moved between different positions.
A single-channel relay module allows a low-voltage control signal from the NodeMCU to operate an electrically isolated switch. The NodeMCU controls the relay through D1 (GPIO5).
When the relay is activated, its internal contacts change state and can be used to control an external load. The relay's contact side is rated for switching suitable loads up to its specified rating, including 230 V AC applications.
The servo and relay are controlled independently by the NodeMCU.
Arduino Code
// © 2025, Cognifront. Member of The IoT Kits Family.
// Experiment: Integration of Actuators with NodeMCU
// Actuators: Servo Motor and Relay
#include <Servo.h>
Servo myServo;
int servoPin = D5; // GPIO14
int relayPin = D1; // GPIO5
void setup() {
// Attach servo to D5
myServo.attach(servoPin);
// Set relay pin as output
pinMode(relayPin, OUTPUT);
// Keep relay OFF initially
digitalWrite(relayPin, LOW);
// Set servo to initial position
myServo.write(0);
}
void loop() {
// Move servo to 0 degrees
myServo.write(0);
delay(1000);
// Move servo to 90 degrees
myServo.write(90);
delay(1000);
// Move servo to 180 degrees
myServo.write(180);
delay(1000);
// Return servo to 0 degrees
myServo.write(0);
delay(1000);
// Turn relay ON
digitalWrite(relayPin, HIGH);
delay(2000);
// Turn relay OFF
digitalWrite(relayPin, LOW);
delay(2000);
}
Required Arduino Library
The program uses the Servo library.
For ESP8266 boards, install the ESP8266Servo library if the standard Servo library is not available or does not compile correctly with the selected NodeMCU board.
Observation
- The servo moves through approximately 0°, 90°, and 180° positions.
- The relay switches ON and OFF at the programmed intervals.
- The NodeMCU controls both actuators independently.
- The relay provides electrical isolation between the low-voltage control circuit and its switched load circuit.
Result
The servo motor and single-channel relay were successfully interfaced with NodeMCU ESP8266 and controlled through programmed digital signals.
Conclusion
This experiment demonstrates actuator control using NodeMCU ESP8266. The servo motor provides controlled angular movement, while the relay allows the NodeMCU to control an external electrical load through a low-voltage control signal.
Safety Note: The NodeMCU and relay control connections are low-voltage circuits. A 230 V AC load presents a serious electric-shock and fire hazard. The mains/load side of the relay must be installed and tested only by a qualified person using appropriate electrical safety procedures.