Controlling motors with pushbuttons (2 pin)

hi guys, i'm trying to control 2 dc motors with 4 pushbuttons (front-back-right-left).I'm using arduino R3 and the buttons are these wellknown classic buttons :

https://www.google.gr/search?q=pushbutton+2+pin&espv=2&tbm=isch&imgil=ZB3o9Se-wQtrXM%253A%253BE8EEFoTiBmqUXM%253Bhttp%25253A%25252F%25252Fwww.gravitech.us%25252Fmipubusw2qt4.html&source=iu&usg=__1gXp_UEs5G2djkn7teZrvkpBzTs%3D&sa=X&ei=vHn0U9edM6Oy0QXowoCQCw&ved=0CCEQ9QEwAA&biw=1366&bih=667#facrc=_&imgdii=_&imgrc=w8i9XTXNI_tpoM%253A%3BE8EEFoTiBmqUXM%3Bhttp%253A%252F%252Fep.yimg.com%252Fay%252Fyhst-27389313707334%252Fmini-push-button-switch-2-pin-qty-4-3.gif%3Bhttp%253A%252F%252Fwww.gravitech.us%252Fmipubusw2qt4.html%3B1452%3B1122

the code im using for one button is:

int inPin_Forward = 10;

void setup()

pinMode(10, INPUT);

void loop()

if(digitalRead(10)==Low)

the problem is that even though i give logic 1 or logic 0 as an input thearduino doesnt change its output

the code im using for one button is:

not really the rubbish I posted here. Help me anyway.

I think not.

Have you wired a resistor with each switch? Why? Use the internal pullup resistors, and simplify the (undefined) wiring.

Please post your complete program. The snippets that you have posted are no use at all in diagnosing the problem.

How is the pushbutton wired ? Does it have a pullup or pulldown resistor so that the voltage on the input pin is at a known voltage at all times ? If not then consider usingpinMode(inPin_Forward, INPUT_PULLUP);to activate the built in pullup resistor.

ok sorry i was trying to cut some stuff to get the post smaller:
#include <Stepper.h>

int inPin_Forward = 10; // choose the input pin (for a pushbutton)
int inPin_Reverse = 11;
int inPin_Right= 12;
int inPin_Left= 13;

Stepper steppermotor(4, 2, 3, 4, 5);
Stepper steppermotor2(4,6,7,8,9);

void setup() /----( SETUP: RUNS ONCE )----/
{
Serial.begin(9600);

pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);
pinMode(13, INPUT);
}

void loop()
{

steppermotor.step(0);
steppermotor.setSpeed(3000);
steppermotor2.step(0);
steppermotor2.setSpeed(3000);

if (digitalRead(10) == LOW) {
steppermotor.step(10000);
steppermotor.setSpeed(3200);
steppermotor2.step(10000);
steppermotor2.setSpeed(3200);
}
if (digitalRead(11) == LOW){
steppermotor.step(10000);
steppermotor.setSpeed(3200);
steppermotor2.step(10000);
steppermotor2.setSpeed(3200);
}

if (digitalRead(12) == LOW){
steppermotor.step(10000);
steppermotor.setSpeed(3200);
steppermotor2.step(0);
steppermotor2.setSpeed(3200);
}

if (digitalRead(13) == LOW){
steppermotor.step(0);
steppermotor.setSpeed(3200);
steppermotor2.step(10000);
steppermotor2.setSpeed(3200);
}
}
/* ( THE END ) */

The motors im using now is dc,back then they were stepper motors,so ill just have to change the code a bit if we find a solution…

Changing the motors is not going to affect how the switches are wired, which you STILL haven't explained. So, we are still going to assume that they are not wired correctly, and that that is the source of your problem.

  int inPin_Forward = 10;   // choose the input pin (for a pushbutton)
  int inPin_Reverse = 11;
  int inPin_Right= 12;
  int inPin_Left= 13;

Why bother giving the input pins names when you never subsequently use them ? While you are at it I suggest that you make them bytes instead of ints to save space and make them const because the pin numbers are not going to change when the program is running.

PaulS: Changing the motors is not going to affect how the switches are wired, which you STILL haven't explained. So, we are still going to assume that they are not wired correctly, and that that is the source of your problem.

i've put one pin on the (gnd) and the other goes to arduino..for each button.. also ive tryied wire the pin to 5 volts and the other on arduino input and still i have what i want (low or high) as input but not the output i need.i am not using any resistors,somewhere i read they re not required.

If each button has one pin to ground and one to an Arduino input that's configured as INPUT_PULLUP it should be working. If not use a multimeter to track down the problem.

Much more importantly you may want to sense WHEN the button is pressed, not IF it is currently pressed - look at the StateChangeDetection example (in 02.Digital).

Otherwise you'll get continuing activation if you hold down the button - I can't tell your intention though.

If each button has one pin to ground and one to an Arduino input that's configured as INPUT_PULLUP it should be working

But, the pinMode is NOT INPUT_PULLUP. It is simply INPUT, which does NOT enable the internal pullup resistors, and digitalWrite() is not being used, either.

So, the switches are NOT wired correctly. Changing the mode to INPUT_PULLUP would fix that. Leaving the mode INPUT, and adding digitalWrite(thePin, HIGH); to turn on the internal pullup resistor would also fix it.

My statement began with “if”…

please help me understand,leaving the project,assuming tha we want to press the button and turn on the LED pin(13) one pin of the button to the ground and one on the arduino pin 10,so the code must be :

int LED = 13; int inPin_button= 10;

void setup(){ pinMode (LED,OUTPUT); pinMode(inPin_button,INPUT_PULLUP); } void loop(){ if (digitalRead (10)==LOW){ digitalWrite (13,HIGH); }

so the code must be

Yes, but you might also want to deal with the case of the switch not being pressed.

wich means practically…in the code please

if (digitalRead(10) == LOW)
{
  digitalWrite(13, HIGH);
}
else
{
  //put code here to be run if the button is not pressed 
}

UKHeliBob: if (digitalRead(10) == LOW) {   digitalWrite(13, HIGH); } else {   //put code here to be run if the button is not pressed }

ok great thank you