I am currently having problems with school project I am working on. The project consists mainly of a motor and 2 momentary pushbuttons, plus other electrical components to handle the load of the motor. The push buttons are suppose to perform a specific motor function when pressed. However, when I plug my arduino Uno in, all I get is the first motor function (i.e. first button press function) to continuously cycle, even if no button is pressed. If anyone could help me get these buttons to work right it would be greatly appreciated. Thanks
(BTW I'm sort of new with the Arduino coding environment)
The first thing people in here will tell you is you need to post your code or nobody can help.
I thought it was just people being arrogant but I understand it now.
I have my code posted as an attachment, I'm not quite sure how to post my code like everyone else does haha, sorry its my first time posting to the Forum.
So are you saying that I should delete the lines that say delay(delay time*10)?
LarryD~
I have the switches wired with external pull-up resistors. One terminal of the switch is wired to 5V, while the other is wired to the digital pin on the arduino and a resistor to ground. So when the button is pressed, 5V should be read.
So are you saying that I should delete the lines that say delay(delay time*10)?
LarryD~
I have the switches wired with external pull-up resistors. One terminal of the switch is wired to 5V, while the other is wired to the digital pin on the arduino and a resistor to ground. So when the button is pressed, 5V should be read.
I'm not saying that at all. I'm just letting you know that delays aren't benign. They have a global effect.
Yeah as Larry just posted, we's need to see the wiring.
Ok you posted in the meantime that you have pullUPs?- if so the pin will be high until you press the button... Post your wiring...
I see you have a Serial.print for button 1.... what does it say? Because if you have the wiring such that button1 is high even when it's not pressed, then that would explain why it's working thru the code like it is.
Suggestion: put Serial.prints inside each leg of the "if", that way you'll see where the flow is going.
if (buttonState1 == HIGH) {
Serial.println("I'm in the button 1 high leg....."); //<<<<<<<<<<<<<<<<<<, new
analogWrite(motorPin, 220);
delay(delaytime/5);
//
else if (buttonState2 == HIGH) {
Serial.println("I'm in the button 2 high leg....."); //<<<<<<<<<<<<<<<<<<, new
analogWrite(motorPin, 220);
delay(delaytime/5);
analogWrite(motorPin, 100
I have the switches wired with external pull-up resistors. One terminal of the switch is wired to 5V, while the other is wired to the digital pin on the arduino and a resistor to ground. So when the button is pressed, 5V should be read.
Not following what you a saying.
Is it ?
+5V----/////----Switch contact ------Switch contact, arduino pin, ------//////------ground
Servo test code with a button setup that does not use resistors. You can try the code without servos and see if you get output to the serial monitor when the button pins are connected to ground. Connect a wire to ground and then touch wire to pins 5 and 6 to test.
//zoomkat servo button sweep test 12-23-2013
// Powering a servo from the arduino usually *DOES NOT WORK*.
#include <Servo.h>
int button1 = 6; //button pin, connect to ground to move servo
int press1 = 0;
int button2 = 5; //button pin, connect to ground to move servo
int press2 = 0;
Servo servo1;
int pos = 90; // variable to store and set the servo position
void setup()
{
Serial.begin(9600);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
servo1.attach(7);
servo1.write(pos); //starting position
digitalWrite(6, HIGH); //enable pullups to make pin high
digitalWrite(5, HIGH); //enable pullups to make pin high
Serial.println("servo button sweep test 12-23-2013");
}
void loop()
{
press1 = digitalRead(button1);
if (press1 == LOW)
{
pos=(pos+1);
if(pos>180) pos=180; //limit upper value
Serial.println(pos); //for serial monitor debug
servo1.write(pos); // tell servo to go to position in variable 'pos'
delay(150); // waits 150ms to slow servo movement
}
press2 = digitalRead(button2);
if (press2 == LOW)
{
pos=(pos-1);
if(pos<0) pos=0; //limit lower value
Serial.println(pos); //for serial monitor debug
servo1.write(pos); // tell servo to go to position in variable 'pos'
delay(150); // waits 150ms to slow servo movement
}
}
I changed the 100k resistors to 10k but still nothing. The value of the button state is not displaying in the serial monitor either.... This is frustrating because I had it working perfectly two nights before and now it doesn't work....
Hahahahha figured out the problem, most rookie mistake ever. I first upload the code onto an Arduino Micro and never switch the board to the Uno before uploading the sketch so the proper code was never even running! Man i feel dumb haha. Thanks to everyone in this posting who answered and helped out. I greatly appreciate everything from everyone!!