0-25V voltage sensor issue

I am using a simple 0-25V DC voltage sensor (it's just a 30k and 7.5k resistor) and no matter what I try I'm getting a voltage reading that is about 8-9V less than what it should be.

This is the sensor:
image

I have tried using an external reference voltage but the result was the same.

Device is a LoRa32u4. I am using nearly every pin. Details on what else is attached at the bottom of the email. There is one other analog (water level) sensor connected but I've tried disconnecting it and the result was the same.

Power source (currently a 19v DC adapter but will be a LiPo battery in final project - the reason I need a sensor) is wired to the GND/VCC pins. The power is also attached to a pair of step down converters (one is converting to 12V the other to 5V) which are powering sensors and motors.

The sensor is connected to the LoRa32_u4:

  • signal pin on sensor to an analog pin
  • ground to Arduino ground pin

Multimeter reads:
19.2v on the sensors GND/VCC pins
0.17v on the signal / - pins

Arduino reads:

  • IN: 10.84
  • OUT: 2.17
  • Pin Value: 444

I'm not sure what else to try / check so any advice on would be greatly appreciated.

Here is the code I'm currently using. I'd post all the code but I'm a professional programmer and this project was a little too complicated to put all my code in one sketch so I've got about a dozen classes I created for this project I'd have to post too. I'm happy to do that if need be.


float vOUT = 0.0;

float vIN = 0.0;

const float R1 = 30000.0;

const float R2 = 7500.0;

int value = 0;

-------------


value = analogRead(_voltageSensorPin);

    if (value > 0) {

        vOUT = (value * 5) / 1024.0;

        vIN = vOUT / (R2/(R1+R2));

        Serial.print(F("SensorDataCollector: Voltage reading, IN: "));

        Serial.println(String(vIN) + ", OUT: " + String(vOUT) + ", Pin Value: " + String(value));   

        return vIN;

    }

Also attached to the device:

  • 3 H-bridge motor drivers, using 3 analog pins and 6 digital pins - attached to external 5V power for board power and (external) 12V for the motors (which are not yet attached)
  • Relay - using an analog pin because I was out of digital pins
  • XY5300 Audio player (uses TX/RX pins 0/1) - powered off 5V external
  • Amplifier - powered off 5V external
  • Addressable LED strip (WS2812B) - using one digital pin, powered of 5V external
  • Servo controller - using SDL/SDA pins, powered off 5V external
  • Water level sensor - using 1 analog pin, powered off 5V external - tried disconnecting this - no change

You have the resistor network wired wrong. Show an image of the wiring.

read this, it might give some insightMeasuring Voltage with Arduino.

Start off by being very, very, very concerned about Common Ground.

And consider, should a negative voltage be applied to an Arduino input pin?

1 Like

Ok, I've got to lay this out nicely on a table to take a good picture that will be useful. There are a lot of wires. I will do that ASAP.

I'm assuming that by "be very, very, very concerned about common ground" you mean that everything should share a common ground. I will double check everything but that should be the case.

Can you please elaborate about applying a negative voltage? I'm not new to electronics but I'm not an expert either and I am not following how negative voltage would come in to play here.

From how I read that, a -.17v is being applied to the Arduino Uno Analog input. Which, I am sure, is outside the Analog input range for a Uno.

Also, it is clear there is a common reference (ground) issue.

Sorry, that's just a dash, meant as a bullet for the line - edited the original post

I suspected the likely culprit might be a grounding issue. I'll recheck everything. Thank you for your help! I'll report back. If I still have trouble I'll post a good pic of all of the wiring.

1 Like

Hi,
Have you got code that JUST reads the sensor, nothing else?
If so then please post this code and tell us what it reads.

Did you write your code in stages?
If so you should have some code already that JUST reads the sensor?

Have you got just the sensor connected and nothing else to prove your circuit?
Can you post a circuit diagram showing how you have the sensor connected to the Lora Controller?

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

Hi,

Can you provide a link to this, the Arduino IDE does not identify it as a controller.

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

This is the sensor:
https://www.ebay.com/itm/282623622844

The seller gives a test sketch - try it - just the uC and the sensor without anything else connected.
Too often we can get lost in the bigger project and stumble with the simple stuff.

Sorry for the delay in responding. I didn't notice the post notifications in my email.

Thanks to everyone for their help. The issue was not surprisingly a common ground issue as idahowalker suggested.

If that sensor is just a voltage divider , why are you measuring voltage with it , then using the same value resistors to DIVIDE it down again in software ??? Doh !

To get the original voltage multiply by (R1+R2)/R1

Or better still use the “map” function and calibrate your input .

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.