Motors turn off at the press of 4 buttons

Hello there,

I was wondering if you could please help me ?

I am using Processing 2 software to control the direction of rotation of 6v motors connected to a Motor Shield v1.2 on an Arduino Uno.

I want to turn off (RELEASE) the motor when only all 4 push buttons are pressed. However it doesn’t work!

I have made a series circuit of all the push buttons with a resistor and a signal line coming from one of the pins on the push button to signal when they are all pushed and a HIGH signal is sent to Pin 2 on the motor shield.

This is the code :

#include <AFMotor.h>

const int buttonPin = 2;
int buttonState = 0;

const int PressureSensor1 = 1;
int val= 0;
const int TURNOFFPRESSURE1 =754;
int incomingByte;
AF_DCMotor motor(1, MOTOR12_64KHZ); // create motor #2, 64KHz pwm

//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println(“Motor test!”);

//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

void loop() { //

pinMode(buttonPin, INPUT);

if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();

Serial.println(val);
if (incomingByte == ‘w’) {

Serial.print(“extension”);
val = analogRead(PressureSensor1);
if (val <TURNOFFPRESSURE1)
{
motor.run(FORWARD); // turn it on going forward
}
else {

motor.run(RELEASE); // stopped
}

}

if (incomingByte == ‘s’) {
motor.run(RELEASE);
}

if (incomingByte == ‘x’) { // This is the problem area!!!
Serial.print(“retraction”);

buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
if (buttonState == HIGH) {

digitalWrite(ledPin, HIGH);
motor.run(RELEASE);
}
else {
motor.run(BACKWARD);
}

}

}

}
#include <AFMotor.h>

const int buttonPin = 2;
int buttonState = 0;
const int ledPin = 13;

const int PressureSensor1 = 1;
int val= 0;
const int TURNOFFPRESSURE1 =754;
int incomingByte;
AF_DCMotor motor(1, MOTOR12_64KHZ); // create motor #2, 64KHz pwm

// const int PressureSensor2 = 1;
// int val2= 0;
// const int TURNOFFPRESSURE2 =754;
// int incomingByte2;
// AF_DCMotor motor2(4, MOTOR12_1KHZ); // create motor #2, 64KHz pwm

//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println(“Motor test!”);

motor.setSpeed(255); // set the speed to 200/255
// motor2.setSpeed(255); // set the speed to 200/255
}

//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
void loop() { ///hg4

pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);

if (Serial.available() > 0) { //ws2
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();

Serial.println(val);
if (incomingByte == ‘w’) { //df1

Serial.print(“extension”);
val = analogRead(PressureSensor1);
if (val <TURNOFFPRESSURE1)
{
motor.run(FORWARD); // turn it on going forward
}
else { //gf2

motor.run(RELEASE); // stopped
} //gf2

} //df1

if (incomingByte == ‘s’) { //h12
motor.run(RELEASE);
} //h12

if (incomingByte == ‘x’) { //po8
Serial.print(“retraction”);

buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
if (buttonState == HIGH) { //5R5

digitalWrite(ledPin, HIGH);
motor.run(RELEASE);
} //5R5
else { //D411
motor.run(BACKWARD);
} //D411

} //po8

} //ws2

} //hg4

Any help would be much appreciated !

Thank you

Calum

You only sense the button at the exact moment the 'x' is read - is that the intention?

BTW please edit your post to use // code tags - the icon to the left of the
quote icon... Then I might be able to follow your indentation even!

I am using Processing 2 software to control the direction of rotation of 6v motors connected to a Motor Shield v1.2 on an Arduino Uno.

I want to turn off (RELEASE) the motor when only all 4 push buttons are pressed. However it doesn't work!

Are these buttons on your PC screen or are they hardware buttons directly connected to your Arduino?

...R

Hi,

Can you please post a copy of your sketch, using code tags?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

Please use code tags.. See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom.... :slight_smile: