Go Down

### Topic: voltage measurement code? (Read 337 times)previous topic - next topic

#### afrim

##### Feb 08, 2018, 10:15 pmLast Edit: Feb 08, 2018, 10:24 pm by afrim
how to write the code in arduino one if i need to do some measurements of voltage A0, A1,12, A3, at the same time and these measurements take you to the serial plotter,
thanks for your help and understanding?
if you can help me pls do not hesitate.

#### anwofis

#1
##### Feb 08, 2018, 11:21 pm
Maybe read this first:

#### jremington

#2
##### Feb 08, 2018, 11:30 pm
The Arduino has only one analog to digital converter, so you have to make one measurement after another.

After switching channels, it is usually a good idea to make a measurement, ignore it, and make another to use.

For example:
Code: [Select]
`int x1,x2;x1 = analogRead(A1);x2 = analogRead(A2); //discard this valuex2 = analogRead(A2);`

#### afrim

#3
##### Feb 09, 2018, 02:15 pm
can I help someone write the code in arduino one for some maths only read analog voltage, but the same ones in the serial plot I write the code only for a measurement but how to write if more than measure A0, A1, A2 , A3, void setup () {
Serial.begin (9600);}
void loop ()
{
int sensorValue = analogRead (A0);
float voltage = sensorValue * (5.0 / 1023.0);
Serial.println (voltage);
}
THANK YOU

#4
##### Feb 09, 2018, 10:34 pm

@afrim, please do not cross-post.  Threads merged.

#### DVDdoug

#5
##### Feb 09, 2018, 11:24 pmLast Edit: Feb 09, 2018, 11:56 pm by DVDdoug
I don't know how you plot more than one voltage.  You might have to write a program on the computer for that.  But, if you want to display it as text you can do that.

This code is untested:
Code: [Select]
` void setup() {   Serial.begin(9600);   int ADCreading;   float Voltage;}void loop() {  ADCreading = analogRead(A0);  Voltage =ADCreading * (5.0 / 1023.0);    Serial.print("A0 = ");                        Serial.println(Voltage);  ADCreading = analogRead(A1);     // Extra read for ADC settling time.  ADCreading = analogRead(A1);  Voltage =ADCreading * (5.0 / 1023.0);    Serial.print("A1 = ");  Serial.println(Voltage);}`

(You may not need the extra read since it takes some time to print between reads.)

...If you want, you can "simplify" some of your code by combining functions & expressions and eliminating the "temporary" variables.  But it makes it harder to read/understand -

Again, this is untested and I left out the setup()
Code: [Select]
`     Serial.print("A1 = ");  Serial.println(analogRead(A1) * (5.0 / 1023.0));    `

Go Up