Hello everyone, I am trying to make my DC motor flip directions on command without the use of a switch (trying to build a crappy RC car), and I didn't want to short-circuit or burn something, so I built it in Tinker anyway. When I tried compiling it, it did not work, and I don't know if the program is glitchy or it won't actually work, so can someone please explain it to me? I am new. Cheers.
You can't drive the motor directly from the Arduino. It will try to draw too much current and either damage your Arduino or not have enough power to do the motor's job.
You need a motor driver IC. Once you've selected a motor driver IC, read the data sheet. It has instructions on how to change the direction of the motor.
To make your DC motor flip directions, you need to reverse the polarity of the voltage applied to the motor - not something your Arduino alone can do.
The simplest and most common way to achieve this is by using an H-bridge circuit.
PS/ +1 of course on not powering the motor from the Arduino..
If you look at how you have wired this:
If you make either of the purple wires HIGH, the current will go straight to ground, rather than through the motor.
If you remove all 3 of those black wires, it would, in theory, work. If the upper purple wires i s HIGH and the lower one is LOW, the current would flow from the HIGH wire to the LOW wire through the motor, turning it one way. If you make the upper purple wire LOW and the lower one HIGH, the current would flow in the opposite direction and the motor would turn in the opposite direction. Make both purple wires HIGH or both LOW and no current would flow, stopping the motor.
As already mentioned, never do this with a real Arduino, you would destroy it. Not only would the current be too much, but when the motor stops, a reverse voltage gets generated, which could also cause damage.
PaulRB beat me to the for the sake of argument post.
To reverse the direction of most DC motors, simply reverse the two power leads, as suggested by @J-M-L. Based on your Fritzing diagram, I’d recommend purchasing a few extra Arduinos, as there’s a good chance you might damage them.
Here are some guidelines to help you avoid common issues:
- Always use a motor driver or H-bridge circuit to control the motor safely.
- Ensure proper power supply decoupling to prevent noise from affecting your Arduino.
- Double-check all connections and verify your circuit before powering it up.
Here are some guidelines to follow:
Gil's Crispy Critter Rules for Processor Hardware:
- Rule #1: An Arduino is NOT a Power Supply!
- Rule #2: Never connect anything inductive (motors, speakers) directly to an Arduino!
- Rule #3: Avoid connecting or disconnecting wires while the power is on.
- Rule #4: Do not apply power to any pin unless you are certain of what you're doing.
- Rule #5: Do not exceed the maximum voltage ratings.
- Rule #6: Many Arduinos cannot power transmitters directly.
- Rule #7: Before powering your project, take a break and double-check the wiring.
LaryD’s Corollaries:
- Coro #1: When starting out, add a 220Ω resistor in series with both input and output pins to protect against shorts.
- Coro #2: Invest in a Digital Multi-Meter (DMM) to measure voltages, currents, and resistance.
Note: Violating these rules can turn your Arduinos into crispy critters. For optimal performance, keep your wires under 25 cm (10 inches). Get a copy of the Arduino Cookbook and read it.
Tips:
- The L293 motor driver, though common, is inefficient as it can lose around 3V as heat when driving both legs of a motor. Consider using a motor driver with MOSFET outputs to reduce heat loss and conserve battery power.
- For more on powering Arduino boards, explore this guide: Powering Alternatives for Arduino Boards.
A microcontroller is a million, automated, switches. Is your "not a switch" switch to start/stop the DC motor or forward/reverse the motor?
Isn’t Christmas grand !
Introducing new users to the challenges and wonder of microcontrollers and electronics.
Thank you so much, kind sir. Now I can build my RC car without it being a total piece of crap.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.


