Simple Arithmetic Problem on Serial Monitor

3.3 V is the maximum voltage value, I know AnalogRead only outputs an integer between 0 -1023. Im trying to convert from the outputs (0-1023 integer) onto the scale from 0 to 3.3V.

Here's my code: void loop() { temp_val0 = analogRead(analogPin0); // read the input pin temp_val1 = analogRead(analogPin1); val0= (3.3*temp_val0)/1023; val1=(3.3*temp_val1)/1023;

Serial.println("Voltage Analog Pin 0:"); Serial.print(val0); Serial.println("Voltage Analog Pin 1:") ; Serial.print(val1); // debug value }

Here's the problem: every output val0 and val1 produces "0". That's wrong. Help?

Posting your code would help.
Between code tags preferably.

I did post my code. See above. There's a problem with the way the C language handles arithmetic operations. I dont get why the output is always "0".

There's a problem with the way the C language handles arithmetic operations

No, there's a problem with the way you expect the very strict rules of how C handles arithmetic to behave. Might be an idea to print the values you read from the analogue inputs.

Post your code. All of it. Between code tags.

Here's the problem: every output val0 and val1 produces "0". That's wrong.

val0= (3.3*temp_val0)/1023;

If val0 and temp_val0 are ints, and temp_val0 contains a value like 250, the 3,3 * 250 is 825. 825 divided by 1023 is 0.

Since you didn't post all of your code, it is only an assumption on my part that val0 and temp_val0 are ints.

3.3 V is the maximum voltage value

Based on what? None of my Arduinos is limited to 3.3V. Mine are all 5V.

This is the output on the serial monitor: "114Voltage Analog Pin 0: 161Voltage Analog Pin 1: 113"

The format of the output is messed up. I want "Voltage Analog Pin 0: value" all on 1 line. How do I do that?

You're right that all the variables are ints. Do I need to change them into other variable types like float?

The 3.3V maximum is the 3.3V/Amp ratio that the stepper motor outputs on a current-sensing channel through the Arduino motor drier shield.

The format of the output is messed up.

The format is exactly as you defined it. You are using println() to print the text, and print() to print the value. Perhaps you need to (re)read the documentation on print() and println() to determine the differences between the two functions. Or, simply experiment.

I understand how to use the carriage return. However, I declared the variables incorrectly. What do I need to declare them as? They should not be int.

Well, if you want them to support the decimal part of the number then there is really only one choice isn't there.

Clown_of_God: I understand how to use the carriage return. However, I declared the variables incorrectly. What do I need to declare them as? They should not be int.

http://arduino.cc/en/Reference/Float

Well, if you want them to support the decimal part of the number then there is really only one choice isn't there.

There's one simple obvious choice, but no, it isn't the only one.