Hello,
it's me again, I still have problems with the book's example. This time with project 10 about the H-bridge =(
I am basically in the same situation than ludossin in this topic: I made the book's circuit, but when I press the buttons, nothing happens.
So, I've decided to make a simpler circuit first.
I read this page http://itp.nyu.edu/physcomp/Labs/DCMotorControl and tried to reproduce this last circuit, and modified it a bit so that it basically runs the motor when you press the button (forgetting, for the moment, the idea of making it spin in both directions).
But here again, nothing happens. The motor doesn't spin at all. I tried to connect directly the 9v battery and the motor and it works, so I don't think the problem comes from them.
The only problem I can think about is that the first time I tried the circuit, I noticed afterwards that I had put the H-bridge the wrong way around, so absolutely ALL the H-bridge's pins were connected to the wrong wire...
What would you say ? Could it damage the H-bridge so bad it simply doesn't work anymore ? I'd like to know what's your opinion on this problem before going and buy a new H-bridge... I use the H-bridge shipped with the starter kit and it's the only one...
I attached a photograph of my circuit. It is actually meant to be the same than the picture, except I've put the switch on the other side.
Here's also my code, although it is so simple there's probably no problem with it:
const int switchPin = 2;
const int motorPin1 = 3;
const int motorPin2 = 4;
const int enablePin = 9;
int buttonState;
void setup() {
Serial.begin(9600);
pinMode(switchPin, INPUT);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, LOW);
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(switchPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn motor on:
Serial.println("Button pressed");
digitalWrite(enablePin, HIGH);
}
else {
// turn motor off:
Serial.println("Button not pressed");
digitalWrite(enablePin, LOW);
}
}
I've put some serial prints to make some debug, but as I expected, pressing the button is detected, so the motor should turn on !
Thank you for your time and help