Maker Pro
Maker Pro

beginner- Arduino Uno DC motor h-gate problems

CD_

May 19, 2023
4
Joined
May 19, 2023
Messages
4
Hi, I'm a beginner to electronics and have an Arduino. I want to control the rotation and speed of a DC motor using an h gate.

The problem is- the motor doesn't rotate when I power the Arduino (via my computer) so yeah

I don't know if it is a code problem or a setup problem, so I will post images of both.
IMG_20230519_172717256.jpg
IMG_20230519_172751427.jpg
IMG_20230519_172732682.jpg


Screenshot_20230519-162932-840.png


IMG_20230519_172554420_HDR.jpg
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,182
Joined
Nov 17, 2011
Messages
13,182
From the images it is next to impossible to recognize your circuit. Please post a schematic circuit diagram. Including the connections from the driver IC to the Arduino.
Please also post a link to the datasheet of the driver IC or at least teh type of IC you are using.

With respect to your code I have the following observations (may be more or less valid depending on the type of driver IC you use):
  • to make the code better accessible for us, please insert as textt in a code box (</> symbol, see screenshot), not as an image. See the code box I inserted below.
    1684516931449.png
  • The variable rotdirection is never used.
  • You use analogWrite() to control the enable pin of the driver. This can be done but is illogical. EnA is a logic pin and shoud be controlled by a digital logic signal using digitalWrite().
    Or use analogWrite() when using PWM for speed control, but there's no speed control in your code. Your commenting is very sparse and doesn't help others understanding what it is you want the code to do.
  • You define in1 and in2 as inputs, then you try to use these as outputs by writing a logic state to this input, This won't work. You need to define in1 and in2 as outputs (these are outputs from the Arduino to inputs of the driver IC).
    This is possibly the main issue here and changing in1 and in2 from inputs to outputs may all that is needed to fix it.
    Note that acc. to the Arduino reference that prior to Arduino 1.0.1, it was possible to configure the internal pull-ups by writing a logic High to an input. This is obsolete and will not work as you expect in yopur circuit.
  • Before you change the state of the in1 and in2 pins, you should disable the driver, then enable it once the states are set. Like so:
    C:
    digitalWrite(enA, LOW);
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);
    digitalWrite(enA, HIGH); // or use analogWrite if you use PWM
    This is not exactly necessary but it is imho good practice to do so.
 

CD_

May 19, 2023
4
Joined
May 19, 2023
Messages
4
Hi Harald Kapp,

Thank you for getting back to me so quickly, I really appreciate it!

1) After I read your message I fixed some of the problems with the code, here is log of it:

-in setup, set pin enA to LOW as suggested, then set it to HIGH in loop

-removed variable rotDirection, as it served no purpose and was a relic from a tutorial I was
watching that did use it

-changed in1 and in2 from INPUT to OUTPUTs
//no change when testing

I saw that you thought there is no speed control in the code, I was trying to use the enA pin for PWM for the motor speed (am I doing the syntax correctly for that?)

2) I am currently making a schematic for the circuit, I should have finished it by tomorrow, but am wondering if there is a free app/website you know of that I could use, as the software I am using is quite old

Also by IC, you mean the h-gate right? If so I've attached the datasheet of it.

I have also posted the code in text below (sorry for not seeing that option):

C++:
#define enA 6
#define in1 2 //when in1 HIGH and in2 LOW, motor should turn, and vice versa (but rot direc changes)
#define in2 3


void setup() {
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);

  //init power low
  analogWrite(enA, 0); //PWM speed control, is this how to do it?
 
  //init rot direction
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
}

void loop() {
   analogWrite(enA, 255); //PWM speed control, is this how to do it?

   //basic test code to see if it works (this is correct right?)
   digitalWrite(in1, LOW);
   digitalWrite(in2, HIGH);
 
   delay(1000);

   digitalWrite(in1, HIGH);
   digitalWrite(in2, LOW);

   delay(1000);

}

Once made, I will post the schematic, I just wanted to reply to keep the thread going and let you know I'm still here
Many thanks,
Charlie
 

Attachments

  • sn754410.pdf
    524.1 KB · Views: 4

Bluejets

Oct 5, 2014
6,329
Joined
Oct 5, 2014
Messages
6,329
The problem is- the motor doesn't rotate when I power the Arduino (via my computer)
You cannot power the motor via the arduino.
Likely you have fried the regulator in the Arduino or your PC usb trying to do so.
Motor must be via separate supply.
 

CD_

May 19, 2023
4
Joined
May 19, 2023
Messages
4
Hi Bluejets,

Is that so? Because previously I had powered even 2 motors (without any IC) from my pc via the Arduino.

Also why is that if it is the case?
 

Bluejets

Oct 5, 2014
6,329
Joined
Oct 5, 2014
Messages
6,329
Is that so?
Told you the problem, now you want to argue about it.
Suggest you go on Arduino forum for answer.
My bet is the first answer will be the same.

When approaching them, make certain you have your code included as well as a circuit diagram of your whole arrangement to save time (they will ask for it first up as well)
No fritzing of "pictures " of your circuit as it does not help in the least.
 

CD_

May 19, 2023
4
Joined
May 19, 2023
Messages
4
I'm not saying you're wrong I just want to learn why it wouldn't work. You have 6000 messages so I thought you knew.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,182
Joined
Nov 17, 2011
Messages
13,182
You cannot power the motor via the arduino.
Lacking a schematic (work in progess) but looking at the breadboard it seems the motor gets its power from the driver IC and this iC gets power from the supply rails of the breadboard. That looks o.k.
Of course one can not draw the power from the Arduino's internal 5 V power.

-in setup, set pin enA to LOW as suggested, then set it to HIGH in loop
That is not what I suggested, see this code snippet:

C:
void loop() {
   analogWrite(enA, 255); //PWM speed control, is this how to do it?

   //basic test code to see if it works (this is correct right?)
   analogWrite(enA, 0); // disable driver
   digitalWrite(in1, LOW);
   digitalWrite(in2, HIGH);
   analogWrite(enA, 255); // enable driver

   delay(1000);

   analogWrite(enA, 0); // disable driver
   digitalWrite(in1, HIGH);
   digitalWrite(in2, LOW);
   analogWrite(enA, 255); // enable driver

   delay(1000);

}
In analogWrite() use any value between 0 (=off) and 255 (=full speed) to control the speed.
 

bidrohini

Feb 1, 2023
84
Joined
Feb 1, 2023
Messages
84
Hello, I suggest you test your H-gate IC with a separate power supply directly. Disconnecting from the Arduino.
 

danadak

Feb 19, 2021
408
Joined
Feb 19, 2021
Messages
408
Just a recommendation but the ground buss normally used is blue on your proto board,
the power buss red. Helps with reducing errors when using the breadboard.

Also I do not see any capacitors on your protoboard, something like a 100 uF electrolytic
in parallel with a .1 uF ceramic. Good chance that would affect Arduino trying to run code
if you dont insure motor transients do not affect 5V buss.

How mjuch current does motor use ? bidrohini's recommendation probably an excellent idea.

Power available thru USB ports :

1684575767580.png



Regards, Dana.
 
Last edited:

Bluejets

Oct 5, 2014
6,329
Joined
Oct 5, 2014
Messages
6,329
Lacking a schematic (work in progess) but looking at the breadboard it seems the motor gets its power from the driver IC and this iC gets power from the supply rails of the breadboard. That looks o.k.
Look again...the rails are supplied from the Arduino 3v3 terminal.
 

hevans1944

Hop - AC8NS
Jun 21, 2012
4,827
Joined
Jun 21, 2012
Messages
4,827
Look again...the rails are supplied from the Arduino 3v3 terminal.
More importantly, @CD_ look at Figure 7, Typical Application Schematic, on page 10 of the datasheet for suggested wiring information. There are NO connections visible in your pictures shown in post #1 for pins 9 through 16 on the quad half-bridge h-driver chip, SN754410. Pin 16 is supposed to be connected to the positive logic supply, not left "floating" in space. As @danadak mentioned, it is wise to use both moderate-valued (100 µF or so) electrolytic capacitors in parallel with medium valued (0.1 µF or so) plastic- or dipped mica-dielectric capacitors to "noise bypass and filter" the power supply rails. Also, until you know wtf you are doing, try to avoid using solderless breadboards except to "try out" new or novel circuits, after which time you should transfer those circuits to soldered components on either perforated board or a printed circuit board (PCB). The Chinese can make PCBs very inexpensively, but there is a steep learning curve concerning what documentation is required and how to prepare and send it to the PCB manufacturer.

As @Bluejets has already mentioned, there should be a separate power supply, completely independent of the Arduino power supply, for the PMDC (Permanent Magnet Direct Current) motor. This is COMMON PRACTICE when driving high-current, reactive loads such as motors or solenoid coils, where the switching current controlled from the Arduino PWM outputs can cause a ground-loop that injects switching transients into the logic circuits. The PWM current pulses have fast rise and fall times that can play havoc with supporting logic-level circuits if the currents produced have a common path back to digital common. ALWAYS keep power, analog, and logic commons separate until the commons are joined at ONE location.

Hi, I'm a beginner to electronics and have an Arduino.
Well, good for you. And welcome to the Maker Pro (formerly ElectronicsPoint) forums. As a beginner, you should be aware of some things about this community. Many who post here have many years of experience and training in the ART as well as the SCIENCE of electronics. If someone like @Bluejets offers advice, it behooves you to accept it at face value without delving into long-winded arguments or asking uninformed questions.

We understand that you want to learn, but everyone here offers their assistance in the forums free of charge. Our time is valuable to us. We don't want to waste it on argumentative trolls, or lecturing newbies who haven't a clue. So, first of all, READ and UNDERSTAND the damned datasheet: ALL of it! If there is something that you don't understand, you may ask questions here.

Second, if you are new to Arduino and are programming this open-source marvel for the first time with a new, un-debugged, application program, please visit the Arduino forum and lurk there for awhile before posting. The world-wide Arduino community is HUGE, and most of us are willing to help beginners who demonstrate a willingness to learn.

Third, we were all beginners once upon a time. I started down this path in 1953 at age nine, but you have to run like hell just to keep up in electronics. I have been running for a very long time. With electronics, it helps to expand your horizons to include physics, chemistry, optics and electro-optics, and the principles of mechanics. Never stop learning! Do some research using library books, a somewhat heavy and cumbersome collection of printed paper pages held together with string, glue, and stiff covers, conveniently arranged on shelves and sorted by subject matter... usually available for borrowing without a lending fee. Get to know your local librarians. They can help point you in the right direction for learning. Beware of ANYTHING you "discover" on the Internet. Always fact-check your sources of information.

Fourth, start a laboratory journal where you record with writing and photographs what you are doing, what you have learned, and what mistakes you have made in your journey of learning about electronics. If insanity is defined as doing the same thing over and over and expecting different results each time, then a good journal will help preserve your sanity. Journal keeping will also allow you to easily and quickly incorporate your new-found knowledge into your latest projects.
 
Last edited:

Delta Prime

Jul 29, 2020
509
Joined
Jul 29, 2020
Messages
509
Is that so? Because previously I had powered even 2 motors (without any IC) from my pc via the Arduino
I am not that presumptuous as to speak for the thread starter. It behooves me to adhere too...
Empirical evidence is impeachable.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,182
Joined
Nov 17, 2011
Messages
13,182
Look again...the rails are supplied from the Arduino 3v3 terminal.
Looking closer I agree.
@CD_ : that's why we need a schematic diagram. So hard to find out what's going on from a photo of the actual wiring.
 
Top