Update:
More focused issue found here.
The battery does supply 9V to the H bridge at pin 8, confirmed with multimeter
However the voltage supplied from the H bridge to the dc motor is only 2.5 volts.
Is there something wrong with the H bridge I'm using?
Hi guys, I'm a new arduino programmer here with only a few weeks of experience doing this. I've been doing the arudino starter projects in order and so far I've loved making these projects, seeing the results and sharing it with friends. However I've been stuck with the zoetrope for many days now. I tried ordering new components, replacing the H bridge and rewriting the code to no avail. I've also scoured the forums for solutions but turned up empty handed. Anyone who can solve this issue?
The issue: Pressing the buttons does not turn on the motor, none of the two buttons do anything, the motor is always just off
//constants for output and input pins
const int controlPin1 = 2;
const int controlPin2 = 3;
const int enablePin = 9;
const int directionSwitchPin = 4;
const int onOffSwitchStateSwitchPin = 5;
const int potPin = A0;
//variables for remembering program state
int onOffSwitchState = 0;
int previousOnOffSwitchState = 0;
int directionSwitchState = 0;
int previousDirectionSwitchState = 0;
//variables for controlling the DC motor
int motorEnabled = 0;
int motorSpeed = 0;
int motorDirection = 1;
void setup() {
//Set inputs and outputs for pins
pinMode(directionSwitchPin, INPUT);
pinMode(onOffSwitchStateSwitchPin, INPUT);
pinMode(controlPin1, OUTPUT);
pinMode(controlPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
//disable motor at start
digitalWrite(enablePin, LOW);
}
void loop() {
//read sensor information
onOffSwitchState =
digitalRead(onOffSwitchStateSwitchPin);
delay(1);
directionSwitchState =
digitalRead(directionSwitchPin);
motorSpeed = analogRead(potPin)/4;
//check if on/off sensor has changed
if(onOffSwitchState != previousOnOffSwitchState){
if(onOffSwitchState == HIGH){
motorEnabled = !motorEnabled;
}
}
//check to see if direction has changed
if(directionSwitchState != previousDirectionSwitchState){
if(directionSwitchState == HIGH){
motorDirection = !motorDirection;
}
}
//change pins to turn motor in the proper direction
if(motorDirection == 1){
digitalWrite(controlPin1, HIGH);
digitalWrite(controlPin2, LOW);
}
else{
digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, HIGH);
}
//PWM the motor if it is enabled
if (motorEnabled == 1){
analogWrite(enablePin, motorSpeed);
}
else{
analogWrite(enablePin, 0);
}
//save current state for next loop
previousDirectionSwitchState = directionSwitchState;
previousOnOffSwitchState = onOffSwitchState;
}
I also checked if the arduino uno was still working with the Pin 13 blinking test and had no issues.
I don't know what the issue you're having is but from what I see, your code looks the same as the one provided by Arduino and the wiring also seems correct. Here are some issues that you might have not checked yet:
faulty wire(s): use a multimeter and a continuity test
H-bridge upside down?
faulty components: test each component separately to make sure they all work (because even though you replace a component, that new component could also be faulty) eg. continuity test for button, simple LED and potentiometer circuit, etc...
dead battery???
faulty breadboard: use a multimeter to make sure that current is going where you intend/expect it to go
And then there's the usual check wire connections and code logic (assuming it compiles). We could definitely give you more help if you can give us more information on what your issue is!
It looks like you are trying to run a motor on the Arduino 5V or USB. Neither has the current capability for a motor of any size. And the inherent Voltage drop (2V to 4V) of the ancient and inefficient L293 does not help. Use an external power supply for the motor. Also consider a modern motor driver like the ones offered by Pololu. Choose a driver based on the motor supply voltage and stall current.
Hi there, I do have a 9V battery connected to the rightmost power rails, and the 9V node is connected straight to the bottom left pin on the H-bridge, so it should be recieveing the power it needs. I have tested connecting the battery straight to the motor and had no issues powering it.
That was the next troubleshooting I was planning to perform, I have tested some wires with the multimeter but not all yet.
Upside up, nothing wrong there.
Tested the motor and battery separately at least and they work fine, could try the potentiometer and the buttons next, I'll post updates on how it goes.
Battery is all juiced up
Have had no issues with the breadboard, an issue I might see is that the pins on the h-bridge is fairly short and the connections on the terminals are quite deep, it could be the hbridge is not reaching all the way down? Don't really see why that would be the case but it's the best I've got.
The new H Bridge I'm using is called L293DNE if that helps, the old one had the same code written on it but it is slightly different in design.
Gonna be busy tomorrow so I'll have another look at the issue on friday, again thanks for the reply.
It would help us a lot if you can tell us what the issue is? Are some lights not lighting up? Is motor not turning? Is the motor not reversing when you press the button? Is the motor not changing speed with the potentiometer? Or is nothing working at all?
Try placing (strategically) some Serial.prints (as I've attempted below) to see if the pushbuttons are working, what's going on there.
[code]
//constants for output and input pins
const int controlPin1 = 2;
const int controlPin2 = 3;
const int enablePin = 9;
const int directionSwitchPin = 4;
const int onOffSwitchStateSwitchPin = 5;
const int potPin = A0;
//variables for remembering program state
int onOffSwitchState = 0;
int previousOnOffSwitchState = 0;
int directionSwitchState = 0;
int previousDirectionSwitchState = 0;
//variables for controlling the DC motor
int motorEnabled = 0;
int motorSpeed = 0;
int motorDirection = 1;
void setup()
{
//Set inputs and outputs for pins
pinMode(directionSwitchPin, INPUT);
pinMode(onOffSwitchStateSwitchPin, INPUT);
pinMode(controlPin1, OUTPUT);
pinMode(controlPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
//disable motor at start
digitalWrite(enablePin, LOW);
Serial.begin(19200);
}
void loop()
{
//read sensor information
onOffSwitchState = digitalRead(onOffSwitchStateSwitchPin);
delay(1);
directionSwitchState = digitalRead(directionSwitchPin);
motorSpeed = analogRead(potPin)/4;
//check if on/off sensor has changed
if(onOffSwitchState != previousOnOffSwitchState)
{
if(onOffSwitchState == HIGH)
{
Serial.println("onOff H");
motorEnabled = !motorEnabled;
}
}
//check to see if direction has changed
if(directionSwitchState != previousDirectionSwitchState)
{
if(directionSwitchState == HIGH)
{
motorDirection = !motorDirection;
}
}
//change pins to turn motor in the proper direction
if(motorDirection == 1)
{
Serial.println("motDir H");
digitalWrite(controlPin1, HIGH);
digitalWrite(controlPin2, LOW);
}
else
{
Serial.println("motDir L");
digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, HIGH);
}
//PWM the motor if it is enabled
if (motorEnabled == 1)
{
analogWrite(enablePin, motorSpeed);
}
else
{
analogWrite(enablePin, 0);
}
//save current state for next loop
previousDirectionSwitchState = directionSwitchState;
previousOnOffSwitchState = onOffSwitchState;
}
[/code]
Okay have some time to try this again now.
Wrote in some serial.prints and serial.begin like the ones in yours. When I upload the sketch it starts immediately sending motDirH, pressing the southern button changes the direction back and forth between motDirL and motDirH as expected. When I press the northern most button the result is very unpredictable, when held down it rapildy switches between sending motDirH, OnOffH and motDirL, and when released it either keeps sending motDirH or motDirL at random.
Not sure what this result means, can someone help me here? It looks like the direction switch is working fine, but not the on off switch.
That could perhaps be it, I'm new to this so I'm still learning as I'm going. Why the arduino team did not have this battery issue though I don't understand, I will try and modify the current wiring some more first.
More focused issue found here.
The battery does supply 9V to the H bridge at pin 8, confirmed with multimeter
However the voltage supplied from the H bridge to the dc motor is only 2.5 volts.
Is there something wrong with the H bridge I'm using?