reading 3 analog inputs. Help plz

Hi, Im brand new to this and to the forum. Im trying to get a project up and work on it as I learn. Ill paste in the code that Ive got so far. My first problem is that I want to read all 3 inputs and when I open up the serial window, I only get 1 thats reporting to the window. I'm not sure what I am doing wrong, but I'm a beginner so Ive probably got everything all jacked up lol. Ill be asking more questions with this project as I go on, so I'm pleading for patients with me :).

void setup()
// put your setup code here, to run once;

{Serial.begin(9600);}
int sensorValue0 = analogRead(A0);
int sensorValue1 = analogRead(A1);
int sensorValue2 = analogRead(A2);

void loop() {
// put your main code here, to run repeatedly;
//Read the input in pin 0;

int sensorValue0 = analogRead(A0);
int sensorValue1 = analogRead(A1);
int sensorValue2 = analogRead(A2);
//Convert the analog reading (value is 0-1023 / 0-5vdc;

float voltage0 = sensorValue0* (0.0048);
float voltage1 = sensorValue1* (0.0048);
float voltage2 = sensorValue2* (0.0048);

//prints the value;
Serial.println(voltage0);
Serial.println(voltage1);
Serial.println(voltage2);}

If the above is your code then it won't even compile. Post code in code tags!

Copy and paste the output of the Serial monitor.

Mark

You should identify which output is which or it'll just be a bunch of numbers.

char b[30];
sprintf(b, "V0 = %f", voltage0);
Serial.println(b);
sprintf(b, "V1 = %f", voltage1);
Serial.println(b);
sprintf(b, "V2 = %f", voltage2);
Serial.println(b);

it compiles just fine and works. Im just only showing the reading from 1 pin on serial. I attached a screenshot . the one pin that shows on screen does transition smoothly with turning the pot. i'm learning so I realize that I'll get the (asshat) replies. But thanks for anyone that is actually trying to help.

Also, I'm not sure what "tag" is. If you could tell me I can comply

I only get 1 thats reporting to the window.

How do you know?
What is connected to these inputs?

I'm not sure what "tag" is. If you could tell me I can comply

Read the sticky post how to use this forum.

I was going to suggest the following to make the serial output easier to read, and perhaps (with respect) more n00b friendly than Boltar's 8)

Instead of (and please note use of the code # just above the :sweat_smile: )

 //prints the value;
  Serial.println(voltage0);
  Serial.println(voltage1);
  Serial.println(voltage2);

Try: (note only last print is a println, so they are side by side)

  //prints the value;
  Serial.print(voltage0);
  Serial.print("   ");
  Serial.print(voltage1);
 Serial.print("   ");
  Serial.println(voltage2);

Grumpy_Mike:

I only get 1 thats reporting to the window.

How do you know?
What is connected to these inputs?

I'm not sure what "tag" is. If you could tell me I can comply

Read the sticky post how to use this forum.

I have pots hooked to the pins, run from board supplied 5vdc and grd.
I am reading the "sticky" now

Grumpy_Mike:

I only get 1 thats reporting to the window.

How do you know?
What is connected to these inputs?

I'm not sure what "tag" is. If you could tell me I can comply

Read the sticky post how to use this forum.

What's connected to them is irrelevant.
I noticed you deleted a post you made that gave incorrect information just now.

@OP just use
[code]
...
put code here
...
...
[/code]

JimboZA:
I was going to suggest the following to make the serial output easier to read, and perhaps (with respect) more n00b friendly than Boltar's 8)

Instead of (and please note use of the code # just above the :sweat_smile: )

 //prints the value;

Serial.println(voltage0);
  Serial.println(voltage1);
  Serial.println(voltage2);




Try: (note only last print is a println, so they are side by side)

You doushe lol. even laughing at me :blush: I got ya. I used an example and built from there lol.




//prints the value;
  Serial.print(voltage0);
  Serial.print("   ");
  Serial.print(voltage1);
Serial.print("   ");
  Serial.println(voltage2);

@Boltar

I noticed you deleted a post you made that gave incorrect information just now.

So what the f*ck do you expect me to do with a post that gives the wrong information?
The poor layout of the code lead me to think it would not compile, on further study I found it would. So I deleted the post and looked again. Personally I think that is responsible, you obviously do not.

What's connected to them is irrelevant

No it is not.
We know it is a pot but not the value, when switching high impedance inputs the the A/D you can get cross talk. That is why it matters.

Just finished replying to you on another thread. I don't think you will fit in here with your attitude.
Calm down or ship out.

It was stated that I should identify the pins or I would get crazy numbers. I thought I did at the top of the sketch. Just wondering if you could look at the input assignments again for me and tell me if that is way out of the ballpark.

The C compiler can be fuzzy about mixed type arthritic.
Try:-

 float voltage0 = (float)sensorValue0* (0.0048);
  float voltage1 = (float)sensorValue1* (0.0048);
  float voltage2 = (float)sensorValue2* (0.0048);

Also try printing out the raw value first.

Are the pots 10K or smaller?

JimboZA:
I was going to suggest the following to make the serial output easier to read, and perhaps (with respect) more n00b friendly than Boltar's 8)

Instead of (and please note use of the code # just above the :sweat_smile: )

 //prints the value;

Serial.println(voltage0);
  Serial.println(voltage1);
  Serial.println(voltage2);




Try: (note only last print is a println, so they are side by side)

Awsome Jimbo, thanks. Now I just need to try and understand what the " " stand for so I can make some connections in my brain to remember. Im showing 3 lines now..




//prints the value;
  Serial.print(voltage0);
  Serial.print("   ");
  Serial.print(voltage1);
Serial.print("   ");
  Serial.println(voltage2);

Grumpy_Mike:
The C compiler can be fuzzy about mixed type arthritic.
Try:-

 float voltage0 = (float)sensorValue0* (0.0048);

float voltage1 = (float)sensorValue1* (0.0048);
  float voltage2 = (float)sensorValue2* (0.0048);



Also try printing out the raw value first.

Are the pots 10K or smaller?

Yes they are. They are the small cheapos that come with starter kits. I'll try your way also. I am seeing that there is more than one way to skin a cat with C on any given task, which is quite interesting.

Well print makes the next print appear on the same line as the current, while println sticks a line feed in. The " " is just a bunch of spaces to leave a gap.

So whereas your code would give:

voltage1
voltage2
voltage3
voltage1
voltage2
voltage3
voltage1
voltage2
voltage3

Mine would give:

voltage1   voltage2   voltage3
voltage1   voltage2   voltage3
voltage1   voltage2   voltage3
voltage1   voltage2   voltage3

Ahhh, that makes perfect sense now jimbo!. i'm Jim too by the way. So do parenthisees in general when used in other areas do the same thing?.

I am now working on adding 2 PWM inputs to the scheme and ohhh God, here we go, an SD card to try and log to in a graph. Already pulling out my hair. Im sure I will be back with my tail dragging on the ground looking for help.

Boltar:
You should identify which output is which or it'll just be a bunch of numbers.

char b[30];

sprintf(b, "V0 = %f", voltage0);
Serial.println(b);
sprintf(b, "V1 = %f", voltage1);
Serial.println(b);
sprintf(b, "V2 = %f", voltage2);
Serial.println(b);

We'll just have to assume you haven't tried that, Boltar.

Some pot/servo test code that prints to the serial monitor (you don't have to have servos to try).

//zoomkat multi pot/servo test 3-23-13
//includes dead band for testing and limit servo hunting
//view output using the serial monitor

#include <Servo.h> 
Servo myservo1;  //declare servos
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;

int potpin1 = 0;  //analog input pin A0
int potpin2 = 1;
int potpin3 = 2;
int potpin4 = 3;
int potpin5 = 4;

int newval1, oldval1;  //pot input values
int newval2, oldval2;
int newval3, oldval3;
int newval4, oldval4;
int newval5, oldval5;

void setup() 
{
  Serial.begin(9600);  
  myservo1.attach(2);  
  myservo2.attach(3);
  myservo3.attach(4);
  myservo4.attach(5);
  myservo5.attach(6);
  Serial.println("testing multi pot servo");  
}

void loop()
{ 
  newval1 = analogRead(potpin1);           
  newval1 = map(newval1, 0, 1023, 0, 179); 
  if (newval1 < (oldval1-2) || newval1 > (oldval1+2)){ //dead band 
    myservo1.write(newval1); //position the servo
    Serial.print("1- ");
    Serial.println(newval1); //print the new value for testing 
    oldval1=newval1; //set the current old value
  }

  newval2 = analogRead(potpin2);
  newval2 = map(newval2, 0, 1023, 0, 179);
  if (newval2 < (oldval2-2) || newval2 > (oldval2+2)){  
    myservo2.write(newval2);
    Serial.print("2- ");    
    Serial.println(newval2);
    oldval2=newval2;
  }

  newval3 = analogRead(potpin3);           
  newval3 = map(newval3, 0, 1023, 0, 179); 
  if (newval1 < (oldval1-2) || newval3 > (oldval3+2)){  
    myservo1.write(newval3);
    Serial.print("3- ");
    Serial.println(newval3);
    oldval3=newval3;
  }

  newval4 = analogRead(potpin4);           
  newval4 = map(newval4, 0, 1023, 0, 179); 
  if (newval1 < (oldval1-2) || newval4 > (oldval4+2)){  
    myservo1.write(newval4);
    Serial.print("4- ");
    Serial.println(newval4);
    oldval4=newval4;
  }

  newval5 = analogRead(potpin5);           
  newval5 = map(newval5, 0, 1023, 0, 179); 
  if (newval1 < (oldval1-2) || newval5 > (oldval5+2)){  
    myservo1.write(newval5);
    Serial.print("5- ");
    Serial.println(newval5);
    oldval5=newval5;
  } 
  delay(50);  //to slow loop for testing
}
Servo myservo1;  //declare servos
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;

int potpin1 = 0;  //analog input pin A0
int potpin2 = 1;
int potpin3 = 2;
int potpin4 = 3;
int potpin5 = 4;

If you find yourself writing code like this with variable names with fixed suffixes, and blocks of identical, or near identical code, it's a pretty clear indication that you should read up on arrays and for loops.
It'll reduce the effort in writing code, reduce the size of your code and make debugging easier.