Voltage sensor have voltage reading with no voltage input

#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

This description is too unprecise to analyse what is going on

Do you mean
I tried to test it with no input to the voltage-sensor
and then
you are still reading something values different from zero?

You should provide more detail-information
a link to the datasheet of your voltage-sensor

a hand-drawn schematic how your voltage-sensor is connected to your microcontroller
it is not really visible in your picture

best regards Stefan

there is no input to the sensor i disconnected.

image

this is the wiring diagram.

image

there is no spec sheet because it is just 2 resistors

and i am still reading input even thou nothing is connected

this is the link that i have copied the example

from vertically above
make a picture of your own setup

from vertically above makes it much easier to really see which wire is connected to what.

maybe taking two pictures
vertcially above but one slightly inclined to one side
vertcially above but one slightly inclined to the other side

A disconnected analog input reads random voltage, not zero.

Hi, @esojlem
Do you have a DMM?

As requested, a schematic, not a Fritzy, would be good.
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.

Some images would also help.

When you disconnect the input voltage, what do you do?

  1. disconnect the voltage source and leave the resistor module connected to the Nano?
  2. disconnect the resistor module from the Nano?

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

It is not really disconnected

So it really depends on what is still connected and what is not connected

Sorry, misread #3 "nothing is connected".

als



This is my setup just like the example on the link

This the connection to arduino

I have uploaded the picture of my setup and also a one with the digital multimeter

So to the input of the voltage-sesnor there is nothing connected
If output of the voltage-sensor is connected to your Arduino nano
and you connect the probes of your DMM your DMM measures 0,000 mV

If you just take away the DMM-probes
and to the voltage-sensor-input is nothing connected
but the output of the voltage-sensor is connected to your arduino-nano
and you run a code that prints the ADC-values of IO-pin A0 to the serial monitor
you see values much higher than zero?

To narrow down the problem you should exclude everything that could interfere with the reading of the analog input

The most simple code to test this is

void setup() {
  Serial.begin(115200);
  Serial.println("Setup-Start");
}

void loop() {
  Serial.print("A0=");
  Serial.println( analogRead(A0) );
  delay(1000);
}

and a more advanced version with more options for debugging

// MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START *
// a detailed explanation how these macros work is given in this tutorial
// https://forum.arduino.cc/t/comfortable-serial-debug-output-short-to-write-fixed-text-name-and-content-of-any-variable-code-example/888298

#define dbg(myFixedText, variableName) \
  Serial.print( F(#myFixedText " "  #variableName"=") ); \
  Serial.println(variableName);

#define dbgi(myFixedText, variableName,timeInterval) \
  { \
    static unsigned long intervalStartTime; \
    if ( millis() - intervalStartTime >= timeInterval ){ \
      intervalStartTime = millis(); \
      Serial.print( F(#myFixedText " "  #variableName"=") ); \
      Serial.println(variableName); \
    } \
  }

#define dbgc(myFixedText, variableName) \
  { \
    static long lastState; \
    if ( lastState != variableName ){ \
      Serial.print( F(#myFixedText " "  #variableName" changed from ") ); \
      Serial.print(lastState); \
      Serial.print( F(" to ") ); \
      Serial.println(variableName); \
      lastState = variableName; \
    } \
  }

#define dbgcf(myFixedText, variableName) \
  { \
    static float lastState; \
    if ( lastState != variableName ){ \
      Serial.print( F(#myFixedText " "  #variableName" changed from ") ); \
      Serial.print(lastState); \
      Serial.print( F(" to ") ); \
      Serial.println(variableName); \
      lastState = variableName; \
    } \
  }
// MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END *



//#include 
void PrintFileNameDateTime() {
  Serial.println( F("Code running comes from file ") );
  Serial.println( F(__FILE__) );
  Serial.print( F("  compiled ") );
  Serial.print( F(__DATE__) );
  Serial.print( F(" ") );
  Serial.println( F(__TIME__) );  
}


// easy to use helper-function for non-blocking timing
boolean TimePeriodIsOver (unsigned long &startOfPeriod, unsigned long TimePeriod) {
  unsigned long currentMillis  = millis();
  if ( currentMillis - startOfPeriod >= TimePeriod ) {
    // more time than TimePeriod has elapsed since last time if-condition was true
    startOfPeriod = currentMillis; // a new period starts right here so set new starttime
    return true;
  }
  else return false;            // actual TimePeriod is NOT yet over
}

unsigned long MyTestTimer = 0;                   // Timer-variables MUST be of type unsigned long
const byte    OnBoard_LED = 13;


void BlinkHeartBeatLED(int IO_Pin, int BlinkPeriod) {
  static unsigned long MyBlinkTimer;
  pinMode(IO_Pin, OUTPUT);
  
  if ( TimePeriodIsOver(MyBlinkTimer,BlinkPeriod) ) {
    digitalWrite(IO_Pin,!digitalRead(IO_Pin) ); 
  }
}


void setup() {
  Serial.begin(115200);
  Serial.println("Setup-Start");
  PrintFileNameDateTime();

}


void loop() {
  BlinkHeartBeatLED(OnBoard_LED,250);

  if ( TimePeriodIsOver(MyTestTimer,1000) ) {
    dbg("01:",analogRead(A0) );
  }  

}

So what results do you get if you run this code?

How do the results change is you disconnect the signal-wire from the screwport of your adapter?

How do the results change is you disconnect the GND-wire from the screwport of your adapter?

How do the results change is you unplug your arduino-nano from the srewterminal adapter-board?

best regards Stefan

yes theres is no connected input on the voltage sensor. when i run my code to simulate full disconnection,

this is the result of the first code:

23:26:25.710 -> Setup-Start

23:26:25.710 -> A0=399

23:26:26.717 -> A0=323

23:26:27.703 -> A0=277

23:26:28.696 -> A0=253

23:26:29.716 -> A0=242

23:26:30.696 -> A0=237

23:26:31.717 -> A0=243

23:26:32.721 -> A0=250

23:26:33.701 -> A0=261

a0= has a value and not going zero

23:29:08.147 -> "01:" analogRead(A0)=235

23:29:09.139 -> "01:" analogRead(A0)=242

23:29:10.152 -> "01:" analogRead(A0)=250

23:29:11.132 -> "01:" analogRead(A0)=253

23:29:12.135 -> "01:" analogRead(A0)=265

23:29:13.155 -> "01:" analogRead(A0)=266

23:29:14.137 -> "01:" analogRead(A0)=270

this from the second code, the value of the a0 is not zero, i have also tried to run it with out sensor so that i can pinpoint if the sensor is broken but it is still the same result with out the voltage sensor

Hi,
Can you run the first code in post #13.

  1. Remove the module and short A0 to gnd
    Then
  2. Connect the module with no battery connected.
    Then
  3. Connect the module with no battery and short the modules Vcc and gnd terminals together.

Please number your results as I have numbered the different experiments.

Did you solder the terminal PCB that the Nano plugs into?
Can you please post an image(s) of the underside of that PCB?

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:
PS. I'm off to bed... :sleeping: :sleeping: :sleeping: :sleeping: :sleeping: :sleeping:

What do you read between " S " and " - " with your Ohmmeter?

result No.1
I15:05:55.772 -> "01:" analogRead(A0)=0
15:05:56.805 -> "01:" analogRead(A0)=0
15:05:57.806 -> "01:" analogRead(A0)=0
15:05:58.792 -> "01:" analogRead(A0)=0
15:05:59.792 -> "01:" analogRead(A0)=0
15:06:00.809 -> "01:" analogRead(A0)=0
15:06:01.814 -> "01:" analogRead(A0)=0
15:06:02.811 -> "01:" analogRead(A0)=0
15:06:03.803 -> "01:" analogRead(A0)=0
15:06:04.789 -> "01:" analogRead(A0)=0
15:06:05.801 -> "01:" analogRead(A0)=0
15:06:06.801 -> "01:" analogRead(A0)=0
15:06:07.785 -> "01:" analogRead(A0)=0
15:06:08.814 -> "01:" analogRead(A0)=0
15:06:09.819 -> "01:" analogRead(A0)=0

Result No 2

15:12:10.796 -> "01:" analogRead(A0)=0

15:12:11.773 -> "01:" analogRead(A0)=0

15:12:12.770 -> "01:" analogRead(A0)=0

15:12:13.792 -> "01:" analogRead(A0)=0

15:12:14.792 -> "01:" analogRead(A0)=0

15:12:15.787 -> "01:" analogRead(A0)=0

15:12:16.793 -> "01:" analogRead(A0)=0

15:12:17.803 -> "01:" analogRead(A0)=0

15:12:18.804 -> "01:" analogRead(A0)=0

15:12:19.806 -> "01:" analogRead(A0)=0

15:12:20.796 -> "01:" analogRead(A0)=30

15:12:21.809 -> "01:" analogRead(A0)=58

15:12:22.772 -> "01:" analogRead(A0)=70

15:12:23.806 -> "01:" analogRead(A0)=69

15:12:24.805 -> "01:" analogRead(A0)=104

15:12:25.809 -> "01:" analogRead(A0)=101

Result No 3

15:13:53.554 -> "01:" analogRead(A0)=0

15:13:54.574 -> "01:" analogRead(A0)=0

15:13:55.576 -> "01:" analogRead(A0)=0

15:13:56.566 -> "01:" analogRead(A0)=0

15:13:57.572 -> "01:" analogRead(A0)=0

15:13:58.590 -> "01:" analogRead(A0)=0

15:13:59.586 -> "01:" analogRead(A0)=0

15:14:00.586 -> "01:" analogRead(A0)=2

15:14:01.584 -> "01:" analogRead(A0)=0

15:14:02.589 -> "01:" analogRead(A0)=0

15:14:03.593 -> "01:" analogRead(A0)=0

15:14:04.587 -> "01:" analogRead(A0)=0

15:14:05.588 -> "01:" analogRead(A0)=0

15:14:06.590 -> "01:" analogRead(A0)=0

15:14:07.594 -> "01:" analogRead(A0)=0

i have change board and the result is very different the one that i posted and as you can see that input now is = 0, is it possible that the first board is broken? even thou its brandnew?

please can you please post such serial output as code-sections.
This makes it easier to copy & paste for local examination in a texteditor

Do the tests for both boards
I suggest instead of naming it 1,2,3 use clear self-explaining names
so the titles look like this

Board 1: Test 1: voltage-sensor disconnected IO-pin A0 directly connected to gnd

Board 1: Test 2: DIS-connected battery voltage-sensor connected to arduino

Board 1: Test 3 DIS-connected battery, voltage-sensor connected to arduino and short the voltage-sensors Vcc and gnd terminals together.

repeat tests for board 2

Board 2: Test 1: voltage-sensor disconnected IO-pin A0 directly connected to gnd

Board 2: Test 2: DIS-connected battery, voltage-sensor connected to arduino

Board 2: Test 3 DIS-connected battery, voltage-sensor connected to arduino and short the voltage-sensors Vcc and gnd terminals together.

best regards Stefan

It sounds like it.

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

1 Like