forked from dttaylo2/Sensor_Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSample_Analog_Reading
More file actions
95 lines (73 loc) · 2.57 KB
/
Sample_Analog_Reading
File metadata and controls
95 lines (73 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//make sure the port the arduino is assigned to in the IDE matches correctly
const int analogIn0 = 0; //used to select which pin to read from
const int analogIn2 = 2; //used to select which pin to read from
const int analogIn5 = 5; //used to select which pin to read from
int rawBuffer0[10];
float voltageBuffer0[10];
int rawBuffer2[10];
float voltageBuffer2[10];
int rawBuffer5[10];
float voltageBuffer5[10];
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop() {
//this loop takes 10 raw data readings and stores them in buffer
for (int i = 0; i<10 ;i ++){
rawBuffer0[i] = analogRead(analogIn0);
voltageBuffer0[i] = rawBuffer0[i] * (5.0 / 1023.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
rawBuffer2[i] = analogRead(analogIn2);
voltageBuffer2[i] = rawBuffer2[i] * (5.0 / 1023.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
rawBuffer5[i] = analogRead(analogIn5);
voltageBuffer5[i] = rawBuffer5[i] * (5.0 / 1023.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
}
//this loop prints the stored raw data readings
for (int j = 0; j<10 ; j++){
Serial.print(rawBuffer0[j]);
Serial.print(", ");
delay(100);
}
Serial.println(""); //new line for next print sequence
delay(1000);
//this loop prints the stored converted data readings
for (int k = 0; k<10 ; k++){
Serial.print(voltageBuffer0[k]);
Serial.print("V, ");
delay(100);
}
Serial.println(""); //new line for next print sequence
delay(2000);
//this loop prints the stored raw data readings
for (int j = 0; j<10 ; j++){
Serial.print(rawBuffer2[j]);
Serial.print(", ");
delay(100);
}
Serial.println(""); //new line for next print sequence
delay(1000);
//this loop prints the stored converted data readings
for (int k = 0; k<10 ; k++){
Serial.print(voltageBuffer2[k]);
Serial.print("V, ");
delay(100);
}
Serial.println(""); //new line for next print sequence
delay(2000);
//this loop prints the stored raw data readings
for (int j = 0; j<10 ; j++){
Serial.print(rawBuffer5[j]);
Serial.print(", ");
delay(100);
}
Serial.println(""); //new line for next print sequence
delay(1000);
//this loop prints the stored converted data readings
for (int k = 0; k<10 ; k++){
Serial.print(voltageBuffer5[k]);
Serial.print("V, ");
delay(100);
}
Serial.println(""); //new line for next print sequence
delay(2000);
}