Hi everyone,
I've recently started a school project where I have to create a moving load on a rail, using a servomotor (with an ASDA B2 driver). I've completed the motor part, but now I have to add button on each end of the track to stop the motor when the load goes too far.
So I've simply followed the Arduino tutorial to install a button and the same code, but something weird happens when trying the program. If I press the button, the motor (which is still wired in but not declared in anyway in the program) moves by a step. I can't find any solution to stop this behavior. I don't know if it's some kind of interference in the board (I'm using an Arduino Due).
I'm putting the code below but I don't think it will be of much help since it's just on included in the examples.
const int buttonPin = 4;
const int ledPin = 13;
int buttonState = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
As any of you encountered such issue ?
Tell me if I need to add any information.
Thanks for your help !