Forgive the newbie question here, I only started using the program yesterday, I'm sure I'm overlooking something trivial.
I'm attempting to writing a code to that would require multiple (2 or 3) 5v inputs to then send signal to a relay controlling a 12v system. I'm running into an issue with the (if) statement. It appears the code is being read as (or) where my (if) statement is. To further elaborate, If I put 5 volts to either port I have set as an input, I get power to the output. Whereas I would like to have it set to only give output when I have signal to ALL inputs.
int out1 = 7;
int in1 = A0;
int in2 = A5;
int in3 = A2;
int threshold = 900;
void setup() {
pinMode(out1, OUTPUT);
pinMode(in1, INPUT);
pinMode(in2, INPUT);
pinMode(in3, INPUT);
digitalWrite(out1, HIGH);
Serial.begin(9600);
}
void loop() {
int analogValue1 = analogRead(in1);
int analogValue2 = analogRead(in2);
if ((analogValue1 > threshold) && (analogValue2 > threshold)){
digitalWrite(out1, HIGH);
} else {
digitalWrite(out1, LOW);
}
Serial.println(analogValue1);
delay(1);
Serial.println(analogValue2);
delay(1);
}
If possible you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it's OK to add it as an attachment. In this case, it's nowhere near the 9000 characters limit.
If I put 5 volts to either port I have set as an input, I get power to the output. Whereas I would like to have it set to only give output when I have signal to ALL inputs.
How are the inputs wired ? Are they in a known state at all times or are they floating at an unknown value ?
Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Thanks everyone for the input so far, I've reviewed the guidelines and will be sure to adhere to them from here on out. Sorry for the slow response as I've been in class all day. I spent an hour trying to get the fritzing program to run without success, so instead I've attached two photos of the setup I have. The brown and white wires running out of the picture frame from A0 and A5 are my 5v inputs. Thanks again!
I'm working on a diagram at the moment, I apologize as I'm much better at reading electrical diagrams than I am at writing them. The sources are switched 12v sources that are stepped down to 5v using L7805 regulators. Both sources are open when not activated, I've tried changing the pins to see if that's the issue with no avail.
And John, the regulators are currently grounded to the chassis of the car. However I would like to utilize a ground pin off of the arduino if at all possible.