#define ANALOG_IN_PIN A0
// Floats for ADC voltage & Input voltage
float adc_voltage = 0.0;
float in_voltage = 0.0;
// Floats for resistor values in divider (in ohms)
float R1 = 30000.0;
float R2 = 7500.0;
// Float for Reference Voltage
float ref_voltage = 5.0;
// Integer for ADC value
int adc_value = 0;
void setup()
{
Serial.begin(9600);
}
void loop(){
// Read the Analog Input
adc_value = analogRead(ANALOG_IN_PIN);
// Determine voltage at ADC input
adc_voltage = (adc_value * ref_voltage) / 1023.0;
// Calculate voltage at divider input
in_voltage = adc_voltage / (R2/(R1+R2)) ;
//rh calibration 0.6732
float x = (in_voltage*0.6732)*10;
//rh value
float rh;
rh = map(x, 0, 100, 0, 1000);
rh = rh/10;
Serial.print("Humidity=");
Serial.println(rh);
Serial.print("voltage=");
Serial.println(in_voltage);
Serial.print("adc_voltage=");
Serial.println(adc_voltage);
delay(1000);
}
i am using this to read an independent temp and humidity sensor that produces voltage corresponding to the hum and temp but the problem is when i tried to create a scenario that once the sensor suddenly turned off it would make an alarm go on when i tried to test it with no input to the voltage the sensor and still reading something i used a multimeter to confirm and no voltage reading
this is the sensor i used for the voltage meter.
this is the output on the serial monitor
18:54:30.269 -> Humidity=40.00
18:54:30.269 -> voltage=5.96
18:54:30.269 -> adc_voltage=1.19
18:54:31.301 -> Humidity=40.00
18:54:31.301 -> voltage=5.96
18:54:31.301 -> adc_voltage=1.19
18:54:32.301 -> Humidity=40.00
18:54:32.301 -> voltage=6.01
18:54:32.301 -> adc_voltage=1.20
18:54:33.305 -> Humidity=40.00
18:54:33.305 -> voltage=6.06
18:54:33.305 -> adc_voltage=1.21