Model Scenery Tutorials

A Comprenshive Modeler's And Model Railroader's Guide

model scenery center

esp32 motor wiring guide

What’s In This Page

Page under construction

If you are using a phone, at the bottom of the page there are links to many  supplies for modelers. Otherwise those links are in the sidebar to the right. You can also find other information  by using the search function that is in the navigation bar above.

Also In Addition To What’s In This Page, What This Site Can Do For You

If you are a model train enthusiast, modeler, diorama maker, or interested in making Arduino projects the easy way, there is categorized information for you here. Click Here.

The Latest Information

Anything new and page updates are posted on X (formerly Twitter), Rumble and Facebook.

It is easy to keep up with the latest by following us on either of them.

Free Help

If you have questions, comments or need help with this ,or any other project, or animating your own diorama or train layout scene, either go to our Free Help page click on the button to the right.

 

Write a complete guide which includes equipment, wiring connections and programs for the following.

there are two esp32 i will call esp32-1 and esp32-2

on esp32-1 there is a potentiometer and a 3 way switch that at on off on and two leds one green and one red. when the motor runs forward, the green led lights and the red is off. when the motor runs in reverse, the red led lights and the green is off

on esp32 -2 there is a l239d that controls a 12v dc motor speed and direction
and two leds one green and one red. when the motor runs forward, the green led lights and the red is off. when the motor runs in reverse, the red led lights and the green is off.

esp32-1 and esp32-2 communicate using esp now

 

Complete Guide for ESP32 Communication and Motor Control Using ESP-NOW

Equipment Needed

ESP32 Development Boards (2 units)

Potentiometer (1 unit)

3-Way Switch (1 unit)

LEDs (4 units: 2 Green, 2 Red)

L293D Motor Driver (1 unit)

12V DC Motor (1 unit)

Resistors (4 units: appropriate value for LEDs, typically 220Ω)

Breadboard and Jumper Wires

Power Supply for 12V Motor (12V power adapter or battery)

Wiring Connections
ESP32-1 Setup

Potentiometer:

Connect the middle pin of the potentiometer to GPIO34 (analog input).

Connect the other two pins to 3.3V and GND respectively.

3-Way Switch:

Connect the common pin of the switch to GND.

Connect the two outer pins to GPIO25 and GPIO26.

LEDs:

Connect the anode (longer leg) of the green LED to GPIO14 via a resistor.

Connect the anode of the red LED to GPIO27 via a resistor.

Connect the cathodes (shorter legs) of both LEDs to GND.

ESP32-2 Setup

L293D Motor Driver:

Connect IN1 to GPIO18.

Connect IN2 to GPIO19.

Connect EN1 to GPIO23 (PWM control).

Connect OUT1 and OUT2 to the motor terminals.

Connect Vcc1 (pin 16) to 3.3V.

Connect Vcc2 (pin 8) to the 12V power supply.

Connect GND (pins 4, 5, 12, and 13) to the GND of the ESP32 and the 12V power supply.

LEDs:

Connect the anode of the green LED to GPIO32 via a resistor.

Connect the anode of the red LED to GPIO33 via a resistor.

Connect the cathodes of both LEDs to GND.

Instructions

Install Libraries: Ensure you have the necessary libraries installed in the Arduino IDE (ESP32 Board, ESP-NOW).

Upload Code: Upload the respective code to ESP32-1 and ESP32-2.

Connections: Make sure all wiring connections are securely made as per the instructions.

Power Up: Power up both ESP32 boards and the 12V motor power supply.

Control: Adjust the potentiometer and the 3-way switch on ESP32-1 to control the speed and direction of the motor on ESP32-2.

By following this guide, you should be able to control a 12V DC motor’s speed and direction using ESP-NOW communication between two ESP32 boards.

Additional Notes

MAC Address: Ensure you replace broadcastAddress in the ESP32-1 code with the MAC address of ESP32-2.

PWM Configuration: The ledcSetup and ledcAttachPin functions configure the PWM on ESP32. Channel 0 is used here with a frequency of 5 kHz and 8-bit resolution.

Library Imports: Ensure you have the necessary libraries installed in your Arduino IDE for the ESP32 (WiFi, esp_now).

By following this guide, you should be able to compile the code successfully and achieve the desired motor control using ESP-NOW communication between the two ESP32 boards.

Scroll to top