Hi,
My code sample some voltage data from a sensor via Pin A0. But It only displays zero insteat of a negative number when the voltage is negative.
why?
my code is as the following:
int led =13;
void setup(){
//initialize serial communication at 4800bit per second;
Serial.begin(4800);
pinMode (led,OUTPUT);
}
void loop(){
//read the input on analog pin A0;
int voltageValue = analogRead(A0);
float voltage = voltageValue * (5.0 / 1023.0);
if (voltage>=0.5||voltage<=-0.5){
digitalWrite(led,HIGH);
}
else{
digitalWrite(led,LOW);
}
// Serial.println("voltage = ");
Serial.println(voltage);
}