Converting integer value to voltage value

Hello everyone,

For my next project i want to log a battery while under load and other conditions etc. I have a voltage divider that will supply a voltage well under the 5v max (the voltage divider being divide 2).

What i want to do is print out the reading in voltage form not integer form. eg if i have a 6 volt source going through the divider and into the ADC port i want it to sense that it is 3 volts and multiply by two and display 6.

Once i have an understanding of how to convert the integer form into a voltage the rest is easy math in the program.

Thanks

Joker94_ic

The analog reading is an int between 0 and 1023, where 0 is 0V and 1023 is 5V.

Here is an example sketch from the book 'Programming Arduino: Getting Started with Sketches' that illustrates this:

//sketch 06-08

int analogPin = 0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  int reading = analogRead(analogPin);
  float voltage = reading / 204.6;
  Serial.print("Reading=");
  Serial.print(reading);
  Serial.print("\t\tVolts=");
  Serial.println(voltage);
  delay(500);
}

The Arduino has a reference voltage, typically 5.0V. The value returned by analogRead() is the measured voltage divided by the reference voltage multiplied by 1023, and truncated.

Simply reverse the process to get the measured voltage.

int val = analogRead(somePin);
float measuredVoltage = val * 5.0 / 1023.0;

Thanks for your help guys, knowing that should make it simple to get the program to do what I want it to do.

Cheers

Joker94

Si:
The analog reading is an int between 0 and 1023, where 0 is 0V and 1023 is 5V.

Here is an example sketch from the book 'Programming Arduino: Getting Started with Sketches' that illustrates this:

//sketch 06-08

int analogPin = 0;

void setup()
{
 Serial.begin(9600);
}

void loop()
{
 int reading = analogRead(analogPin);
 float voltage = reading / 204.6;
 Serial.print("Reading=");
 Serial.print(reading);
 Serial.print("\t\tVolts=");
 Serial.println(voltage);
 delay(500);
}

Hi,
I am new to Arduino and almost everything digital. However I am finding "Programming Arduino" very helpful. One question... in sketch 6-08. What is the purpose of the letter t in the line Serial.print("\t\tVolts=");

Thank you!