Dc motor speed control with esp8266

Hi there,

I made a basic arduino sketch to control a dc motor and it works perfectly. here’s the code:

const int motor = 3;
const int potPin = A0;
void setup() {
  // put your setup code here, to run once:

pinMode(potPin, INPUT);
pinMode(motor, OUTPUT);

void loop() {
  // put your main code here, to run repeatedly:
int potVal = analogRead(potPin);
int motorSpeed = map(potVal,0,1023,0,255);

analogWrite(motor, motorSpeed);
Serial.print("potVal: ");
Serial.print(" ");
Serial.print("motor speed: ");

And here is my circuit:

Now i would like to use the same circuit, and connect the gate of the mosfet to my esp8266 12-E, and control it with blynk.
I tried doing it and setup a slider in the app and it went very very slow, i only got about 10% of the usual speed.


Hi @shmilylauber,
At least 3 things to take into consideration from my point of view:

-1: Is the Mosfet able to run at 3.3V?
-2: Change from

int motorSpeed = map(potVal,0,1023,0,255)


int motorSpeed =potVal;

The range for the ESP is (if you don’t change it…) from 0 to 1023, not 255 like the boring Arduino.

-3: Feed the Potenciometer to 3.3V!

1 Like