Design and Programming help - 0-10VDC input with 0-5VDC output

Hello everybody. I am new with these Arduino boards and just playing around with how to program them. I am looking for some help on a design and program.

I am looking to take a 0-10VDC signal as my input signal and convert that into a 0-5VDC output signal that is inversely related to the input. So if I have 10VDC in I need 0VDC out and 0VDC input would give me a 5VDC output. As the input rises the output falls within these ranges.

I have looked into various circuit designs but can't seem to come up with anything on this so far. I was wondering if using a small board would work with a little programming to tell it how to relate the voltages.

Any help or ideas would be great.


Run the 0-10V thru 2 5K resistors:

| analog input pin, 0-5V input
V Gnd

analogInput = analogRead(analogPin); // reading will be 0 to 1023.

Divide the result by 4:
PWMoutput = analogInput>>2;

now result is in range 0 to 255
Invert it:
invertOutput = 255 - PWMoutput;

and send it out
analogWrite(PWMpin, invertOutput);

Put lowpass filter (resistor, capacitor) on PWM pin to smooth it out.

Thanks. The only thing I don't quite understand is the input pins and the way you have the resistors. You have analog input pin, 0-5VDC. I have a 0-10VDC signal input

The resistors wired in series from 10V to Gnd make a voltage divider. You feed the analog signal from the junction into the arduino. Vin : resistor R1 : Vout at junction : resistor R2 : Gnd.

Vout = (Vin * R2)/(R1 + R2)

Vout = (10V * 5000)/(5000 + 5000) = 5V

Connect all Gnd's together.

Ok that makes sense now that I think about it that way. I see what we are doing with it now.

I just want to say thank you for all your post, I have read it from top to bottom and learned so many things. It's a very helpful thing to come across with this kind of work online because you will be able to know things that are beyond your skilss outside world. Thanks anyway. :)

For some reason my output is not inverting. It seems to be following the input. Here is my code:

//Converter Board

int analogInput = A0; //Sets input pin A0
int invertOutput = 3; //Sets output pin 3
int PWMoutput;
int analogValue;

void setup()
pinMode(analogInput, INPUT);
pinMode(invertOutput, OUTPUT);

void loop()
analogValue = analogRead(analogInput);
PWMoutput = analogValue >> 2;
invertOutput = 255 - PWMoutput;


So you're saying it does not invert? Lets work thru an example. You connect 5V, do a reading, get 1023 as a result. Shift right twice (>>) to divide by 4. Result is 255. 255 - 255 = 0; analogWrite(0); should give 0V out. Assumes the output is going thru a lowpass RC filter to smooth it out and not be the square wave that it actually is.

Say you put in 2.5V, do a reading, get 511 as a result. Shift right twice (>>) to divide by 4. Result is 127. 255-127 = 128 analogWrite(128); should give out ~2.5V.

Say you put in 1.25V, do a reading, get 256 as a result. Shift right twice (>>) to divide by 4. Result is 64. 255-64 = 191 analogWrite(191); should give out ~3.75V.

How are you wired up?