Pages: [1]   Go Down
Author Topic: why cant i get this second button to work?  (Read 1217 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Oslo, Norway
Offline Offline
Full Member
***
Karma: 6
Posts: 126
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Try this smiley
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

still not workin  smiley-sad
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Lancashire, UK
Offline Offline
Edison Member
*
Karma: 9
Posts: 1991
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: