0

I am relatively new to adruino and this whole space. I am currently trying to power a DC motor using an ESP12E motor shield and an ESP8266 Module

Motor Shield - https://www.amazon.com/gp/product/B078CPZDW1/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

ESP8266 - https://www.amazon.com/gp/product/B010O1G1ES/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

DC Motor - https://www.amazon.com/gp/product/B07MTT7B88/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

Here is my code

#define DIRA 0
#define PWMA 5
#define LED 2

void setup() {
  Serial.begin(9600);
  Serial.println();
  Serial.println("Starting...");


  Serial.println("Preparing motor...");
  pinMode(DIRA, OUTPUT);
  pinMode(PWMA, OUTPUT);
  analogWrite(PWMA,0);
  digitalWrite(DIRA,1);
  delay(5000);

  Serial.println("Starting motor...");
  analogWrite(PWMA,5);
  delay(5000);

}

void loop() {
}

Here is how I have wired it up

schematic

Note: This setup is similar to what I have but not exactly, I have 4 AA batteries connected and only 2 motors

I am expecting the motor to start once I upload this code but nothing is happening. If I change the analogWrite to digitalWrite, the motor runs but I want to be able to control the speed, rather than just having it run at one speed.

I have tested using analogWrite by changing the intensity of an LED and it was working, although the output pin was not the same as the one I use for the motor.

Would greatly appreciate any help as I have already gone through pages of google searches without any luck. I have been using this example as a reference, https://hackaday.io/project/8856-incubator-controller/log/29291-node-mcu-motor-shield.

| improve this question | | | | |
  • 1
    5 is nowhere near big enough to get the motor out of its stalled state. – Majenko Oct 22 '19 at 11:35
  • You've connected 2 Motors to the output and drive these two motors with about 2% of the full Voltage. As @Majenko stated, that's not enough power to start two motors. I do not know your Max Voltage ( two batteries but are these normal 1.2 Volt accus or ~4 Volt LiPos or ...). Say you have max 8 Volt, your motor starts with 1.5 Volt then you need at least 5-6 % better 10% of the max Voltage which you can regulate with the PWM duty cycle. You used analogWrite(PWMA,5); I would suggest analogWrite( PWMA, 25 );. – Peter Paul Kiefer Oct 22 '19 at 12:46
  • @PeterPaulKiefer I tried with 4 1.5v AA batteries with two motors and one motor. This picture isn't my exact setup but pretty close, only difference is the number of batteries I have attached (4) and the number of motors (2). My mistake for not pointing that out, I have updated the details. I also tried analogWrite(PWMA, 10), analogWrite(PWMA, 50), analogWrite(PWMA, 100) but still nothing – Ameya Savale Oct 23 '19 at 5:05
  • Sorry I made a mistake. The max value for analogWrite is 1023 not 255. You powered the shield with about 6 Volts. To be sure, you should uses at least 3 Volts to drive the motors. Use a duty cycle of 50% `analogWrite(PWMA, 512);. A value of 100 is just 10% (i.e. a mean voltage of about 0.6 Volts.) If this is still not enough, try if the motors run if you connect them to 2 or 3 of your batteries directly. If not, you batteries might be discharged or the motor is defect. If the motor runs with direct connected batteries, the shield might be defect. Have you tried the 2nd motor too? – Peter Paul Kiefer Oct 23 '19 at 8:59
  • @PeterPaulKiefer you were right! Once I increased the analogWrite to 512 the motor started spinning. Thank you so much! – Ameya Savale Oct 28 '19 at 4:50
0

This answer is the summary of the comments of the question. The idea of the solution was originally mentioned by @Majenko.

You powered the shield with about 6 Volts. The statement analogWrite(PWMA, 5); gives you (5/1024) ~ 0.5% of this 6 Volts at the output pin PWMA. This 0.03V are not enough to drive the motor.

You should use at least 3 Volts to drive the motor (as of the specs). This can be achieved by using a duty cycle of the PWM signal of about 50%. analogWrite(PWMA, 512); should do the trick.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.