Greetings All,
I am new to the Arduino world and I am starting a project using an UNO. I would like to be able to read several different analog inputs, which would correspond to a specific output (1 input = 1 output). I have it basically working as expected, but the results are intermittent. I feel like the issue resides in the "IF" statement in the code and the threshold crossing is being missed during the void loop cycle. I put the serial print in so I could see if the threshold was being crossed. I also think that is slowing down the code (by watching the TX LED on the board).
Is there a better way to do this? I am not a code guy, but this is all I have come up with so far. The analog input threshold crossing is going to be a quick event and I would like to see the output react consistently.
int analog01 = A0; // pin that the sensor is attached to
int analog02 = A1; // pin that the sensor is attached to
int led11 = 11; // pin that the LED is attached to
int led10 = 10; // pin that the LED is attached to
int threshold = 100; // an threshold level that's in the range of the analog input
int outOnTime=3000; //Declare outOnTime an int
int outOffTime=750; //Declare outOffTime an int
void setup() {
pinMode(led11, OUTPUT); // the LED11 pin as an output:
pinMode(led10, OUTPUT); // the LED10 pin as an output:
Serial.begin(9600);
}
void loop() {
int analogValue1 = analogRead(analog01); // read the value of A0
if (analogValue1 > threshold) { // if the analog value is high enough, turn on 11:
digitalWrite(led11, HIGH);
delay(outOnTime); //Leave on for outOnTime
} else {
digitalWrite(led11, LOW);
delay(outOffTime); //Leave off for outOffTime
}
int analogValue2 = analogRead(analog02); // read the value of A1
if (analogValue2 > threshold) { // if the analog value is high enough, turn on 10:
digitalWrite(led10, HIGH);
delay(outOnTime); //Leave on for outOnTime
} else {
digitalWrite(led10, LOW);
delay(outOffTime); //Leave off for outOffTime
}
Serial.println(analogValue1);
}
