why cant i get this second button to work?

i have a pressure sensor hooked up to A0, a servo hooked up to pin 9, and two buttons, each should make the servo do what i tell it. the first button works but the second one doesn't?? i know someone can help.

#include <Servo.h>

int sensorPin = A0; // sensor connected to pin A0
int SensorValue = 0; // variable storing the sensor value
int buttonPin = 4; // "scramble boost"
int buttonState = 0;
int buttonStateII = 0;
int buttonPinII = 3; // overide open wastgate
Servo myservo;

void setup()
{
myservo.attach(9);
pinMode(buttonPinII, INPUT);
pinMode(buttonPin, INPUT);
}

void loop()
{
buttonState = digitalRead(buttonPin); // reads unlimited pressure button "scramble boost"..
buttonStateII = digitalRead(buttonPinII);
SensorValue = analogRead(sensorPin); // reads boost sensor pressure..
if (SensorValue < 800 || buttonState == HIGH) // wastegate stays closed if pressure is under preset or if scramble boost is activated.
{
myservo.writeMicroseconds(2000);
}
else if (SensorValue > 800 | buttonStateII == HIGH) // why doesnt this button work :frowning:
{
myservo.writeMicroseconds(1000);
}
}

else if (SensorValue > 800 |[glow]|[/glow] buttonStateII == HIGH)

Try this :slight_smile:

still not workin :frowning:

Can you connect the Arduino to the PC with the other stuff attached? if you, you can add Serial.begin() to setup, and Serial.print(ln)() statements to loop.

Print out the value of the sensor, Print out the two switch states. See if the switch states actually change the way you expect them to. See if the sensor output is what you think it should be.

In the absence of facts, you are just guessing at whether the hardware is working and which path through the if test should be followed.

Is your pressure sensor wired as a voltage divider ? If its just wired in series between 5v and the analog pin, it is probably behaving as a floating input and whether it gives a high or low is a complete lottery.

ok ill explain futher. this is a code to control the servo i have mounted on a turbo charger. the pressure sensor reads the amount of boost and opens and closes the waste gate using the servo. the servo only moves if the turbo has reached the desired pressure of 25psi. the two buttons im talking about act like over rides i guess you could call them. no matter what the pressure is i want the buttons to make the servo go to the position i programed on them. now the weird thing is, one of the buttons work but when i push the other on it doesnt do anything and i used the same method as i did programing the first one?

I sense that you are frustrated that you program/hardware is not working. But, it isn't helping your situation if you don't answer the questions that are asked.

Do you know what range of readings you are actually getting from the pressure sensor? Is a value over 800 reasonable?

Do you know that the switches are wired correctly? Not because you have looked at the wiring 1000 times, but because you have printed data to the serial port, and the data is consistent with the state of the switches.

wait im confused what are you guys talking about printing data to the serial

sorry im kinda new at this but im a fast learner.

are you guys talking about printing data to the serial

Yes, I'm suggesting that if connecting a cable between the USB port on the Arduino and a PC is on option, that you can use Serial.print as a debugging tool.