Help with a dc motor circuit

Hello, I am wiring a vertical lift bridge system for my students and am unsure of the circuit I have built. I have 4 dc motors with transistors and diodes working off 1 push button and the arduino. The code I have seems to be fine and the arduino is happy with it, but the mechanics won't work.

These are the circuits I combined to run the motors in series:
![3 motors with arduino|599x500](upload://dUTsKa4d9XgK8brIDwTWKXdtucg.png)


This is the code I have:

const int buttonPin = 2; //Change this pin as per your wiring
const int motorPins[] = {6,7,8,9}; // Change this pin as per your wiring
const int numMotors = 4;

int buttonState = 0;
int lastButtonState = 0;

void setup() {
// put your setup code here, to run once:
for (int i = 0; i <numMotors; i++) {
pinMode (motorPins[i], OUTPUT);
}
pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
// put your main code here, to run repeatedly:
buttonState = digitalRead (buttonPin);

if (buttonState != lastButtonState) {
if (buttonState == LOW) {
//Toggle the state of all motors
for (int i = 0; i < numMotors; i++) {
digitalWrite (motorPins[i], !digitalRead(motorPins[i]));
}
}
delay (50); //Debounce delay
}

lastButtonState = buttonState;
}



Pictures of the circuit
![0221240844|375x500](upload://8rBWkIaJ19L3c6ABagmGjGVQxvq.jpeg)
![0221240845a|375x500](upload://c1L3Ms4Ljqi663g4Rf3i7cL8u3q.jpeg)

![0221240846|666x500](upload://14O5NkSTdxZpZ91CI8i5BsZItmO.jpeg)

Please edit and fix your post.

Your code goes inside the code tags.

Your words go outside the code tags.

Please post a schematic.

Please post some pictures of the lift/bridge and it's motors.

Please explain what "won't work" means.

1 Like

Paul,

I followed those guidelines when I created the post, I do not know why it displayed incorrectly. For someone who is new to the forum seeking help and guidance a little leeway and grace should be given.

The "won't work" means the code seems fine, and downloaded to the arduino okay, but the motors will not turn on and spin when I push the button.

Have you verified that your code properly detects when the button is pushed?

I don't know how to do that.

Perhaps using serial.Print() to show a message when you detect that the button has been pushed!

Which I did. Instead of ignoring your post and moving on to someone else's problem, because you didn't correctly follow forum guidelines, I took the trouble and time to explain what was wrong and what was missing. I even said "please" 4 times!

I notice in the photos you posted that you are using a 9V PP3 size battery. This probably won't run 1 motor, let alone 4.

To run 4 motors at once you will need a much more significant battery, or an external PSU. Perhaps 3x or 4x C size cells would do it.

What is the stall current of the motors?

Thank you Paul.

I'm a high school engineering teacher trying to incorporate programming into my curriculum. I know a little bit, enough to get things started but not enough to troubleshoot and get things running.

By the time you are done, you will have learnt a variety of troubleshooting methods.

In addition to using copious serial print statements to watch the flow of your code and prove it is being informed by the values of key variables and inputs…

a trick for motors is to temporarily remove the motors and replace them with LEDs and series current limiting resistors. LEDs should do what you want the motors to do.

Next see if you can make a motor spin by directly hooking what once went to an output pin on the Arduino to ground and then to Vcc (5 volts).

Motors are often problematic due to power supply inadequacy or dodgy wiring.

By testing the software with LEDs and confirming your transistor circuit with direct injection of the logic voltage you expect the Arduino to put out, you have employed the very best troubleshooting method for these kindsa projects:

Divide and conquer.

HTH

a7

Thank you for the work around. I'll give it a try and look for a better power source for the motors.

I see the diodes connected to ground, which is wrong. The diodes go across the motor, not across the transistor. The transistors are hopefully logic level mosfets. Because no base resistors on bjt transistors will burn the Arduino pins. Mosfets should also have (two) resistors.
Better put that 9volt battery back in the smoke alarm. A pack of AA batteries is much better suited to power motors.
Leo..

Your first image, with one motor, looks reasonable. The second image has 3 motors connected 3 different ways, so bound to cause problems.

It would be better if you drew a schematic on paper and posted a photograph or scan of it.

Edit:
Here is a tutorial to help you with a schematic:

1 Like

Dont see any gear reduction on the motors either...like trying to push shit uphill with a toothpick.

I know how to draw a schematic. I don't know how these particular components should be wired in the circuit.

plain, ole, simple dc motors. direct drive with a pulley system.

I have 4 dc motors that I want to program with an arduino to run a vertical lift (bridge elevator essentially). I do not have a motor controller unit so I am using transistors. I need to control this system with a push button to activate and reverse the system. I found the images and code online to get me started but never found close to what I need. I found two images that were close to what I need and tried to integrate them.

I am not a coder, nor do I do much with electronics, as a teacher I don't have a lot of time to tinker with these. I am trying to learn these two new careers in order to teach my students and just need some help and direction.

As per my reply, the single motor circuit looks okay so far as I can see. The 3 motor circuit is wrong, again, so far as I can see. Compare the two, look for the mistakes then do a corrected schematic and post that.

@Wawa has pointed out at least one mistake.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.