IDPL - 5: Integration of Actuators with NodeMCU
IDPL - 5: Integration of Actuators with NodeMCU (Servo Motor)
Objective
To interface and control a servo motor and a Buzzer independently using NodeMCU ESP8266.
Required Components
- NodeMCU ESP8266
- Servo motor
- LED Bar
- External 5 V power supply
Part A: Servo Motor Interfacing
Objective
To interface a servo motor with NodeMCU ESP8266 and control its angular position using a programmed control signal.
Circuit Diagram
Servo Motor Pin Connections
| Servo Motor Pin / Connection | Connection Details |
|---|---|
| Signal / Data | Connect to NodeMCU D5 (GPIO14) |
| GND | Connect to NodeMCU GND |
| VCC | Connect to the positive (+) terminal of the external 5 V power supply |
| External Power Supply GND | Connect to NodeMCU GND to provide a common ground |
| Power Adapter DC Jack | Connect the DC jack pin of the adapter to the DC jack provided on the kit |
Important: Use the external 5 V supply to power the servo motor. The NodeMCU GND and external power-supply GND must be connected together to provide a common reference for the servo control signal.
Working Principle
A servo motor is an actuator that can rotate its shaft to a specified angular position.
The NodeMCU generates a PWM-based control signal on D5. The servo interprets this signal and moves its shaft to the corresponding angular position.
In this experiment, the servo is programmed to move as per the angle given by the user via serial monitor. The user can specify the angle between 0° to 180°.
Experiment Code for Servo Motor
// © 2026, Cognifront. Member of The IoT Kits Family.
// Experiment: Servo Motor Interfacing with NodeMCU
// Board: NodeMCU ESP8266
#include <Servo.h>
// Create servo object
Servo myServo;
// Servo signal connected to D5
#define SERVO_PIN D5
void setup() {
// Start Serial Monitor
Serial.begin(9600);
// Attach servo with pulse range
myServo.attach(SERVO_PIN, 500, 2400);
// Set initial position
myServo.write(0);
Serial.println("SG90 Servo Control");
Serial.println("Enter angle (0-180):");
}
void loop() {
// Check if a value is entered in Serial Monitor
if (Serial.available() > 0) {
// Read the angle
int angle = Serial.parseInt();
// Make sure angle is within range
if (angle >= 0 && angle <= 180) {
// Move servo
myServo.write(angle);
// Display current angle
Serial.print("Servo moved to: ");
Serial.print(angle);
Serial.println(" degrees");
} else {
Serial.println("Enter an angle between 0 and 180.");
}
// Clear remaining Serial data
while (Serial.available() > 0) {
Serial.read();
}
}
}
Important Note
The program uses the Servo library.
Try compiling the code normally without edit first, if servo moves as expected no need for external library as while we install the NodeMCU in Arduino IDE, some basics libraries we get preinstalled, one of them is Servo.h 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 to as per the ange specified by the user
- The servo movement is controlled by the NodeMCU through D5.
Result
The servo motor was successfully interfaced with NodeMCU ESP8266 and controlled to move to different angular positions.
Conclusion
This experiment demonstrates the interfacing and control of a servo motor using NodeMCU ESP8266. The NodeMCU generates the required control signal and the servo motor responds by moving to the programmed angular positions.
Part B: LED Interfacing
Objective
To interface a LED with NodeMCU ESP8266 and control the LED using a digital output signal.
Circuit Diagram
Working Principle
A LED is an electronic device used to produce an audible sound when an electrical signal is applied to it.
The NodeMCU controls the LED through D1 using a digital output signal.
When the output signal is HIGH, the LED is activated. When the output signal is LOW, the LED is deactivated.
In this experiment, the LED is programmed to:
- Turn ON for 2 seconds.
- Turn OFF for 2 seconds.
- Repeat continuously.
LED Pin Connections
| LED Connection | Connection Details |
|---|---|
| Data | Connect to NodeMCU D1 |
| GND | Connect to NodeMCU GND |
Experiment Code for LED
// © 2026, Cognifront. Member of The IoT Kits Family.
// Experiment: LED Interfacing with NodeMCU
// Board: NodeMCU ESP8266
int LEDPin = D1;
void setup() {
// Set LED pin as output
pinMode(LEDPin, OUTPUT);
// Turn LED OFF initially
digitalWrite(LEDPin, LOW);
}
void loop() {
// Turn LED ON
digitalWrite(LEDPin, HIGH);
delay(2000);
// Turn LED OFF
digitalWrite(LEDPin, LOW);
delay(2000);
}
Testing the LED
- Connect the LED Signal pin to D1.
- Connect the LED GND pin to NodeMCU GND.
- Connect the NodeMCU to the computer using the USB cable.
- Select the NodeMCU board and the appropriate COM port in Arduino IDE.
- Upload the program to the NodeMCU.
- Observe the LED operation.
- The LED should turn ON for approximately 2 seconds.
- The LED should turn OFF for approximately 2 seconds.
- The process repeats continuously.
Observation
- The LED remains OFF initially.
- The LED turns ON for approximately 2 seconds.
- The LED turns OFF for approximately 2 seconds.
- The LED continuously switches between ON and OFF states.
Result
The LED was successfully interfaced with NodeMCU ESP8266 and controlled using a digital output signal.
Conclusion
This experiment demonstrates the interfacing and digital control of a LED using NodeMCU ESP8266. The LED is controlled by the NodeMCU through D1 using a digital output signal.