i want to output HIGH on an LED if the analog input receives < 0.20volts and LOW if it receives > 0.20v…meaning if 0.10 or 0.15 or 0 is inputted on the analog input…the LED in pin13 will light up…i have read somewhere that 40 is the equivalent voltage for 0.20v

i got that 0.20v from a comparator, lm339 to be exact… it outputs 0.20v or 4.2v…and that output from the comparator is inputted to the analog input of arduino…ive tried the code below…when i use potentiometer as the input in arduino it works however when the output from the comparator is used it wont work…

this is the code…

``````int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;       // value output to the PWM (analog out)
void setup() {
Serial.begin(9600);
}

void loop() {
Serial.println(sensorValue, DEC);
delay(0);
if(sensorValue > 41){
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(0);        }
if(sensorValue < 41){
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(0);         }

}
``````

anyone?..

How have you got it wired up? Have you measured the output from the comparator?

What are the symptoms with the comparator input?
What are the results you get for ‘sensorvalue’?
What action is to happen if sensorvalue ==41? (i.e., not > and not <)?
You should change one of the if’s to >= or <= to cover that.

If you are using 5V for the analog reference, thats 4.88mV for each increase by 1 step, so 41 makes sense there.
If you are using the Internal reference, 1.1V, thats 1mV increase per step. So 0.2V would be a reading of more like 200.

What do you have ARef connected to? 5V? Or nothing?