two inputs with states that controll two lights?

I'd love help fixing my program. I read the post about what to do before posting.

I have 2 sensors and two LEDs. I just want the two LEDs to go on if each sensor gets to a set value. My code works great for one sensor reaching a state and controlling one LED. I've added a second and tried to give them each unique values but now they are both operating partially in tandem. It seems like if either meets the individual threshold the LED comes on.

/* Conditionals - If statement

This example demonstrates the use of if() statements. It reads the state of a potentiometer (an analog input) and turns on an LED only if the potentiometer goes above a certain threshold level. It prints the analog value regardless of the level.

The circuit: * potentiometer connected to analog pin 0. Center pin of the potentiometer goes to the analog pin. side pins of the potentiometer go to +5V and ground * LED connected from digital pin 13 to ground

  • Note: On most Arduino boards, there is already an LED on the board connected to pin 13, so you don't need any extra components for this example.

created 17 Jan 2009 modified 9 Apr 2012 by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/IfStatement

*/

// These constants won't change: const int MotionDet = A0; // pin that the sensor is attached to const int LevelSensor = A1; // pin that the sensor is attached to const int Whiteled = 12; // pin that the LED is attached to const int Redled = 10; // pin that the LED is attached to const int Motionthreshold = 800; // an arbitrary threshold level that's in the range of the analog input const int Levelthreshold = 300; // an arbitrary threshold level that's in the range of the analog input

void setup() { // initialize the whiteLED pin as an output: pinMode(Whiteled, OUTPUT); // initialize the redLED pin as an output: pinMode(Redled, OUTPUT); // initialize serial communications: Serial.begin(9600); }

void loop() { // read the value of the Motion sensor: int analogValueMot = analogRead(MotionDet);

// read the value of the Level sensor: int analogValueLev = analogRead(LevelSensor);

// if the analog value is high enough, turn on the whiteLED: if (analogValueMot > Motionthreshold) { digitalWrite(Whiteled, HIGH); } else { digitalWrite(Whiteled, LOW); }

// if the analog value is high enough, turn on the redLED: if (analogValueLev > Levelthreshold) { digitalWrite(Redled, HIGH); } else { digitalWrite(Redled, LOW); }

// print the analog value: Serial.println(analogValueMot); delay(1000); // delay in between reads for stability }

Which LED comes on? Both?

What is your SerialMonitor displaying?

Sorry, in the sketch above I have the Motionthreshold set to 800 because I was tinkering. It should be set to 600.

That's because the serial port says 0 when there is no movement. When I put my hands in front of it, it reads 691 for a second or two and then back to 0. The output from that sensor is exactly what I want. I want the motion detector to trigger the white light only and the level detector to trigger the red light only.

Can one arduino board do this?

I want the motion detector to trigger the white light only and the level detector to trigger the red light only. Can one arduino board do this?

Yes.

Can you please prove a hand drawn schematic of how the leds are connected to the Arduino.

I think that the motion detector led will flicker briefly when motion is detected but i don’t see how the code is making them both come on at the same time.

Why not print analogValueLev as well and reduce delay to 300 so you can see what’s happening with both values?