Go Down

Topic: why cant i get this second button to work? (Read 1 time) previous topic - next topic

Xone

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 :(
 {
  myservo.writeMicroseconds(1000);
 }
}

doc_norway

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

Try this :)

Xone


PaulS

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.

pluggy

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.
http://pluggy.is-a-geek.com/index.html

Xone

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?

PaulS

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.

Xone

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

Xone

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

PaulS

Quote
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.

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview