ESP32: DIY Motor Driver With ESP32 Controller
by TechMartian in Circuits > Microcontrollers
18381 Views, 42 Favorites, 0 Comments
ESP32: DIY Motor Driver With ESP32 Controller
![WMOXsFpcS32R2tNPvcRHGw_thumb_75e.jpg](/proxy/?url=https://content.instructables.com/FV4/LQ4U/J6IEXMQ3/FV4LQ4UJ6IEXMQ3.jpg&filename=WMOXsFpcS32R2tNPvcRHGw_thumb_75e.jpg)
![DC Motor Driver with ESP32](/proxy/?url=https://content.instructables.com/FXN/J0CT/J6IEWWFQ/FXNJ0CTJ6IEWWFQ.jpg&filename=DC Motor Driver with ESP32)
This is the simplest motor driver that could possibly be built using only one NPN transistor, which is controlled and driven by the ESP32 micro controller board.
Materials and Tools
![lc6KUZ6NQLmWwAOBrtacgg_thumb_757.jpg](/proxy/?url=https://content.instructables.com/F64/73G0/J6IEWX5C/F6473G0J6IEWX5C.jpg&filename=lc6KUZ6NQLmWwAOBrtacgg_thumb_757.jpg)
- ESP32 Microcontroller
- DC motor
- NPN Transistor -- BC337
- 100Ω resistor
- Diode -- N4148 General Purpose
- Breadboard wires
- Breadboard'
- 2x jumper wire
Connecting the Signal
![vQomk3pyQQmhTBsGCj%+NA_thumb_758.jpg](/proxy/?url=https://content.instructables.com/FWD/5XOR/J6IEWX63/FWD5XORJ6IEWX63.jpg&filename=vQomk3pyQQmhTBsGCj%+NA_thumb_758.jpg)
Connect a 100Ω resistor to the base (middle) pin of the NPN transistor to protect the EPS32 board from overvoltage, then connect it in series to D5
Connecting the Power Supply
![WP5gXyLaQn+oVn8r84n2OQ_thumb_759.jpg](/proxy/?url=https://content.instructables.com/FSM/IBK1/J6IEWX9G/FSMIBK1J6IEWX9G.jpg&filename=WP5gXyLaQn+oVn8r84n2OQ_thumb_759.jpg)
![nwoKjYsNTt6G2vyW0EI3gg_thumb_75a.jpg](/proxy/?url=https://content.instructables.com/FAK/QPXE/J6IEWX5O/FAKQPXEJ6IEWX5O.jpg&filename=nwoKjYsNTt6G2vyW0EI3gg_thumb_75a.jpg)
- Connect the collector (right) pin to ground.
- Connect the emitter (left) pin to the positive pin of the general purpose diode.
- Connect the negative pin of the general purpose diode to 3.3V.
Connect the DC Motor
![SG7nXBrbSyWGvXGr2H2OeQ_thumb_75b.jpg](/proxy/?url=https://content.instructables.com/F9P/PS4Q/J6IEWX62/F9PPS4QJ6IEWX62.jpg&filename=SG7nXBrbSyWGvXGr2H2OeQ_thumb_75b.jpg)
- Connect either one of the pins to either end of the diode.
Order does not matter, it only changes rotation which is arbitrary and can be coded as active high or active low.
Coding
![Screen Shot 2017-08-18 at 11.14.17 PM.png](/proxy/?url=https://content.instructables.com/FT4/1AOV/J6IEWYW8/FT41AOVJ6IEWYW8.png&filename=Screen Shot 2017-08-18 at 11.14.17 PM.png)
Choose ESP32 as the board under tools, and plug it in. Choose the corresponding USB port that is labeled ESP32, then upload the following code to the board.
const int motorPin = 5;
void setup() { //set motorPin as OUTPUT pinMode(motorPin, OUTPUT); }
void loop() {
motorOnThenOff();
}
// This function turns the motor on and off like the blinking LED. // Try different values to affect the timing. void motorOnThenOff() { // milliseconds to turn the motor on int onTime = 3000; // milliseconds to turn the motor off int offTime = 3000;
// turn the motor on (full speed) digitalWrite(motorPin, HIGH); // delay for onTime milliseconds delay(onTime); // turn the motor off digitalWrite(motorPin, LOW); // delay for offTime milliseconds delay(offTime); }