-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathbasic_plotter.ino
More file actions
48 lines (41 loc) · 1.36 KB
/
basic_plotter.ino
File metadata and controls
48 lines (41 loc) · 1.36 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
/*
* Basic Arduino Serial Plotter Example
*
* This sketch generates sample data compatible with the Web Serial Plotter.
* It outputs multiple data series in CSV format with headers.
*
* Data Format:
* - Header line starts with '#' followed by series names
* - Data lines contain comma-separated values
* - Each line represents one time sample across all series
*
* Compatible with Web Serial Plotter at:
* https://github.com/your-repo/web-serial-plotter
*/
void setup() {
Serial.begin(115200);
// Wait for serial connection
while (!Serial) {
delay(10);
}
Serial.println("# Temperature,Humidity,Pressure,Light");
// Small delay to ensure header is processed
delay(100);
}
void loop() {
// Generate sample sensor data
float temperature = 20.0 + 15.0 * sin(millis() / 5000.0) + random(-100, 100) / 100.0;
float humidity = 50.0 + 20.0 * cos(millis() / 3000.0) + random(-200, 200) / 100.0;
float pressure = 1013.25 + 10.0 * sin(millis() / 8000.0) + random(-50, 50) / 100.0;
float light = 500.0 + 300.0 * sin(millis() / 2000.0) + random(-1000, 1000) / 100.0;
// Output as comma-separated values
Serial.print(temperature, 2);
Serial.print(",");
Serial.print(humidity, 2);
Serial.print(",");
Serial.print(pressure, 2);
Serial.print(",");
Serial.println(light, 2);
// Sample rate: 10 Hz (100ms interval)
delay(100);
}