@@ -287,49 +287,46 @@ The sketch will read the inputs on the analog pins A0, A1 and A2 and then print
287
287
288
288
``` arduino
289
289
void setup() {
290
- Serial.begin(9600);
291
- // 65535 is the max value with 16 bits resolution set by analogReadResolution(16)
292
- // 4095 is the max value with 12 bits resolution set by analogReadResolution(12)
293
- analogReadResolution(12);
290
+ Serial.begin(9600);
291
+ // 65535 is the max value with 16 bits resolution set by analogReadResolution(16)
292
+ // 4095 is the max value with 12 bits resolution set by analogReadResolution(12)
293
+ analogReadResolution(12);
294
294
}
295
295
296
296
void loop() {
297
-
298
- // read the input on analog input 1 corresponding to A0:
299
- int sensorValueA0 = analogRead(A0);
300
- float voltageA0 = sensorValueA0 * (3.0 / 4095.0)/ 0.3;
301
- // print out the value you read from o to the max value for the analog inputs resolution:
302
- Serial.print("I1 value: ");
303
- Serial.print(sensorValueA0);
304
- Serial.print(" corresponding to ");
305
- // print the voltage as a floating point number with 5 decimal digits
306
- Serial.print(voltageA0, 5);
307
- Serial.println("Volts");
308
-
309
- // read the input on analog input 2 corresponding to A1:
310
- int sensorValueA1 = analogRead(A1);
311
- float voltageA1 = sensorValueA1 * (3.0 / 4095.0)/0.3;
312
- // print out the value you read:
313
- Serial.print("I2 value: ");
314
- Serial.print(sensorValueA1);
315
- Serial.print(" corresponding to ");
316
- // print the voltage as a floating point number with 5 decimal digits
317
- Serial.print(voltageA1, 5);
318
- Serial.println("Volts");
319
-
320
- // read the input on analog input 3 corresponding to A2:
321
- int sensorValueA2 = analogRead(A2);
322
- float voltageA2 = sensorValueA2 * (3.0 / 4095.0)/0.3;
323
- // print out the value you read:
324
- Serial.print("I3 value: ");
325
- Serial.print(sensorValueA2);
326
- Serial.print(" corresponding to ");
327
- // print the voltage as a floating point number with 5 decimal digits
328
- Serial.print(voltageA2, 5);
329
- Serial.println("Volts");
330
- delay(1000);
297
+ // Read the input on analog input I1 corresponding to A0:
298
+ int sensorValueA0 = analogRead(A0);
299
+ float voltageA0 = sensorValueA0 * (3.0 / 4095.0)/ 0.3;
300
+
301
+ // Print out the value you read from I1 to the max value for the analog inputs resolution:
302
+ Serial.print("I1 value: ");
303
+ Serial.print(sensorValueA0);
304
+ Serial.print(" corresponding to ");
305
+ Serial.print(voltageA0, 5); // Print the voltage as a float with 5 decimal digits
306
+ Serial.println("Volts");
307
+
308
+ // Read the input on analog input I2 corresponding to A1:
309
+ int sensorValueA1 = analogRead(A1);
310
+ float voltageA1 = sensorValueA1 * (3.0 / 4095.0)/0.3;
311
+
312
+ Serial.print("I2 value: ");
313
+ Serial.print(sensorValueA1);
314
+ Serial.print(" corresponding to ");
315
+ Serial.print(voltageA1, 5); // Print the voltage as a float with 5 decimal digits
316
+ Serial.println("Volts");
317
+
318
+ // Read the input on analog input I3 corresponding to A2:
319
+ int sensorValueA2 = analogRead(A2);
320
+ float voltageA2 = sensorValueA2 * (3.0 / 4095.0)/0.3;
321
+
322
+ Serial.print("I3 value: ");
323
+ Serial.print(sensorValueA2);
324
+ Serial.print(" corresponding to ");
325
+ Serial.print(voltageA2, 5); // Print the voltage as a float with 5 decimal digits
326
+ Serial.println("Volts");
327
+
328
+ delay(1000);
331
329
}
332
- ```
333
330
334
331
You may notice from the output values that when the maximum value of 10V is reached, the corresponding numerical value is not 4095 as the max value with 12 bits resolution; this is because there is a precautional margin taken on the max voltage level applicable to the inputs to preserve the microcontroller.
335
332
0 commit comments