How to Read voltage +/-

Hi all

I am trying to read negative voltage I have found this link but the sketch is not clear for me can anyone help please

We can't see your circuit, we can't see your code.

See the problem?

1 Like

Can you share the sketch you do not understand as well as a wiring diagram?
Most people here do not like watching very boring YouTube videos...

1 Like

Reading negative voltage directly with an Arduino is not possible, because the Arduino's analog inputs can only measure voltages between 0V and the board's supply voltage (usually 5V or 3.3V). If you want to measure negative voltages, you will need to first shift the voltage level so that it falls within the range of the Arduino's analog inputs.

One way to do this is to use an op-amp circuit called an inverting amplifier. This circuit amplifies the input voltage by a fixed factor and inverts it so that the output voltage is positive and falls within the range of the Arduino's analog inputs. Here is a simple circuit diagram for an inverting amplifier:

+Vcc
|
Rf
|
Vin ---+---|_|--- Vout
| |
R1 |
| |
GND GND

In this circuit, R1 is the input resistor, Rf is the feedback resistor, Vin is the negative voltage that you want to measure, and Vout is the amplified and inverted output voltage. The gain of the amplifier is equal to Rf/R1. For example, if R1 = 10kΩ and Rf = 100kΩ, the gain would be 10.

To use this circuit with an Arduino, you would connect the Vout pin to one of the Arduino's analog inputs and read the voltage using the analogRead() function. Keep in mind that the Arduino's analog inputs have a resolution of 10 bits, so the voltage range is divided into 1024 levels. If you want to measure negative voltages with a high degree of precision, you may need to use a higher resolution analog-to-digital converter (ADC) external to the Arduino.

1 Like

Also note when using operational amplifiers the input voltage to it must be within the power supply rails. So that means if you have a -10V signal you must have at least a +12 / ground / -12V supply to the amplifiers. This is know. As a split supply.

1 Like

Your drawing is pretty unclear. Maybe you should put it in code tags (then all characters (including space) will have same width).

1 Like

There are opamps where + and - inputs can be higher or lower than rails voltage.

1 Like

Can you give me an example of such a device please.

Discussed here:

2 Likes

Thanks for that, very interesting, I did not know about these.

It is a pity they are only available in a small surface mount package.
Digikey have them in stock but only for a full reel at the price of £5,405.88, the cut tape are £3.82 each, but there is no stock on that.

I didn't know Beyond the Rails existed either. Thanks for sharing

An inverting op-amp is a solution as long as your voltage never swings positive. If your voltage can be positive or negative a simple resistor circuit will convert a bipolar signal to a unipolar signal.

The following circuit for example converts a -10V...+10V input to a 0V...+5V output. Resistors will be different for a different input range, output range, or second voltage source.

Bipolar

Once you have your circuit designed do a linear regression to account for resistor tolerance and voltage source tolerance. The results for my experiment from -9V ... +9V are shown below:

Bipolar Results

3 Likes

Hi all

And thanks for response I think now it's clear how the Arduino sketch work in the provided YouTube link

There is formula to calculate the resistor

I asked the YouTube creator and provided all explanation in the description

Hi

Yes great this is the same way provided in YouTube link

Image in post#14...

With +20volt and 5volt on analogue-in, only the bottom 1k is in circuit.
With -20volt and 0volt on analogue-in, only the top 1k is in circuit.

+20volt > Ratio lower R to ?k = 5volt:15volt = 1:3 > lower R = 1/3 of ?k
-20volt > Ratio top R to ?k = 5volt:20volt = 1:4 top R is 1/4 of ?k.

So if ?k is 100k, the divider should be 33.3k to ground and 25k to VCC (so not 1:1).
Leo..

Ditto. I also solved this for 100: 33.3: 25 resistor ratios.

Keep in mind you can also vary the DC offset to adjust the whole circuit. This may be helpful when you get really awkward resistor values. That's not really the case for your parameters but just by way of example, if i change the DC offset from 5V to 4V (easily done with a voltage divider) I now get:

100: 50: 20

for my resistor ratios.

That might be more appealing to me because I have 10,5,2K precision resistors in my cabinet.

However, look at my original test data. Notice the coefficients of 2.4796 and 0.2460. It does not take a huge leap to realize that those represent in a large part the fact that my "5V" DC offset is coming from a nominal "5V" rail which is actually 4.9 something volts.

The moral of the story is you don't have to get the numbers perfect, just calibrate at the end.

First, propose a solution and see what numbers you get. Next if you get very inconvenient resistor values try to tweak the various parameters. Next prototype and benchmark your best solution. Then build the final version, and finally benchmark and linear fit your actual final circuit and do the calibration in your MCU and you will get very good results.

Problem is that the 5volt reference is not always 5.000volt. For voltage measurements it's usually better to use one of the more stable internal reference voltages that most Arduinos have.
For an Uno I would switch to 1.1volt Aref in setup(), and calculate the divider for ~1volt.
Leo..

sorry for yesterday I was out of replies daily I can only make up to 25 replies. hope your issue get solved

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