Opening a Door with ESP8266 NodeMCU and a Push Button

ESP8266 08-04-25
56 0

Tutorial plan

1- How Open a door with ESP8266 NodeMCU and push button ?

2- Required Components

3- Circuit Connections of system

4- Micropython program to control the door

 

 

How Open a door with ESP8266 NodeMCU and push button ?

Use a push button to control a servo motor, which acts as a door opener/closer. The ESP8266 NodeMCU controls the logic and updates the I2C LCD display to show the current door status.

1- When the button is pressed:

The ESP8266 sends a PWM signal to the servo motor to rotate to the "open" position (e.g., 20°).

The LCD I2C screen displays "Door Open".

2- When the button is pressed again:

The servo returns to the "closed" position (e.g., 90°).

The display updates to "Door Closed".

3- The state toggles with each press of the button.

 

Required Components

ESP8266 NodeMCU

The NodeMCU is a development board based on the ESP8266 Wi-Fi chip. It has multiple GPIO pins that can control various components such as servos and read sensors like buttons.

Role in the Project:

Acts as the central controller

Reads the push button input

Sends PWM signals to the servo motor

Sends data to the LCD display via I2C

Push Button

A momentary tactile switch that makes contact only when pressed.

Role in the Project:

Serves as user input to toggle the door state (open or close)

Connected to a GPIO pin and GND

When pressed, the NodeMCU detects a HIGH signal and reacts accordingly

Servo Motor (e.g., SG90)

A servo motor is a small electric motor with built-in control circuitry to rotate to a specific position between 0° and 180°.

Role in the Project:

Physically opens or closes the door

Receives angle commands (e.g., 0° to close, 90° or 180° to open) from the NodeMCU

LCD 16x2 with I2C Module

A 16-character by 2-line LCD display with an I2C adapter for easy wiring and communication.
Role in the Project:

Displays system status messages:

“The door opens”

“Door Open”

"The door closes"

“Door Closed”

10kΩ Resistor (Pull-down for Button)

Résistance

A fixed resistor used to ensure a known voltage level on a GPIO input pin when the button is not pressed.

Role in the Project:

Prevents floating values or false triggering from the push button

Ensures the input pin reads LOW (0V) when button is not pressed

Breadboard

Breadboard

The Breadboard mounts and connect components safely

Jumper wires

Jumper wires

The jumper wires establish connections between components and the NodeMCU

 

Circuit Connections of system

I2C LCD to ESP8266 NodeMCU connections

LCD I2C Screen Pin

ESP8266 NodeMCU Pin

VCC

VIN

GND

GND

SDA

GPIO 4 (D2)

SCL

GPIO 5 (D1)

Servo motor to ESP8266 NodeMCU connections

Servo motor

ESP8266 NodeMCU Pin

Red wire (+)

VIN

Brown wire (-)

GND

Yellow wire (Signal)

D5 (GPIO14)

Push button to ESP8266 NodeMCU connections

1- Connect one leg of the push button to pin D8 (GPIO 15) of ESP8266

2- Put a resistor between the same leg of the push button and the GND pin of ESP8266

3-Connect one leg of the push button to the 3V pin of ESP8266

 

Micropython program to control the door

Before running the code, install the necessary libraries:

- Servo (for servo motor)

- i2c_lcd and lcd_api for I2C LCD screen

0 comment

Leave a comment

Veuillez noter s'il vous plaît*

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Purpose of this website

Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.

Contact details

Zaouiet Kontech-Jemmel-Monastir-Tunisia

+216 92 886 231

medaliprof@gmail.com

Pictures of the articles

Robotic site created by MedAli-Teacher info