DIYables Web Apps Web Plotter

WebPlotter Example - Setup Instructions

Overview

The WebPlotter example creates a real-time data visualization interface accessible through any web browser. Designed for Arduino Uno R4 WiFi and DIYables STEM V4 IoT educational platform with enhanced data processing capabilities, real-time plotting features, and seamless integration with sensor monitoring systems. Perfect for visualizing sensor data, debugging algorithms, or monitoring system performance in real-time.

Arduino WebPlotter Example - Real-time Data Visualization Tutorial

Features

  • Real-time Data Plotting: Visualize sensor data as it streams from Arduino
  • Multiple Data Series: Plot up to 8 different data streams simultaneously
  • Auto-scaling: Automatic Y-axis scaling based on data range
  • Interactive Interface: Zoom, pan, and analyze data trends
  • WebSocket Communication: Instant updates with minimal latency
  • Responsive Design: Works on desktop, tablet, and mobile devices
  • Customizable Configuration: Adjustable plot titles, axis labels, and ranges
  • Platform Extensible: Currently implemented for Arduino Uno R4 WiFi, but can be extended for other hardware platforms. See DIYables_WebApps_ESP32

Hardware Preparation

1×Arduino UNO R4 WiFi
1×Alternatively, DIYables STEM V4 IoT
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×Recommended: Screw Terminal Block Shield for Arduino UNO R4
1×Recommended: Breadboard Shield for Arduino UNO R4
1×Recommended: Enclosure for Arduino UNO R4
1×Recommended: Power Splitter for Arduino UNO R4
1×Recommended: Prototyping Base Plate & Breadboard Kit for Arduino UNO

Or you can buy the following kits:

1×DIYables STEM V4 IoT Starter Kit (Arduino included)
1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Setup Instructions

Detailed Instructions

Follow these instructions step by step:

  • If this is your first time using the Arduino Uno R4 WiFi/DIYables STEM V4 IoT, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/DIYables STEM V4 IoT in the Arduino IDE.
  • Connect the Arduino Uno R4/DIYables STEM V4 IoT board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
  • Navigate to the Libraries icon on the left bar of the Arduino IDE.
  • Search "DIYables WebApps", then find the DIYables WebApps library by DIYables
  • Click Install button to install the library.
Arduino UNO R4 DIYables WebApps library
  • You will be asked for installing some other library dependencies
  • Click Install All button to install all library dependencies.
Arduino UNO R4 DIYables WebApps dependency
  • On Arduino IDE, Go to File Examples DIYables WebApps WebPlotter example, or copy the above code and paste it to the editor of Arduino IDE
/* * DIYables WebApp Library - Web Plotter Example * * This example demonstrates the Web Plotter feature: * - Real-time data visualization * - Multiple data series support * - Auto-scaling Y-axis * - Responsive web interface * - WebSocket communication for instant updates * * Hardware: Arduino Uno R4 WiFi or DIYables STEM V4 IoT * * Setup: * 1. Update WiFi credentials below * 2. Upload the sketch to your Arduino * 3. Open Serial Monitor to see the IP address * 4. Navigate to http://[IP_ADDRESS]/webplotter */ #include <DIYablesWebApps.h> // WiFi credentials - UPDATE THESE WITH YOUR NETWORK const char WIFI_SSID[] = "YOUR_WIFI_SSID"; const char WIFI_PASSWORD[] = "YOUR_WIFI_PASSWORD"; // Create WebApp server and page instances UnoR4ServerFactory serverFactory; DIYablesWebAppServer webAppsServer(serverFactory, 80, 81); DIYablesHomePage homePage; DIYablesWebPlotterPage webPlotterPage; // Simulation variables unsigned long lastDataTime = 0; const unsigned long DATA_INTERVAL = 1000; // Send data every 1000ms float timeCounter = 0; void setup() { Serial.begin(9600); delay(1000); // TODO: Initialize your hardware pins and sensors here Serial.println("DIYables WebApp - Web Plotter Example"); // Add home and web plotter pages webAppsServer.addApp(&homePage); webAppsServer.addApp(&webPlotterPage); // Optional: Add 404 page for better user experience webAppsServer.setNotFoundPage(DIYablesNotFoundPage()); // Configure the plotter webPlotterPage.setPlotTitle("Real-time Data Plotter"); webPlotterPage.setAxisLabels("Time (s)", "Values"); webPlotterPage.enableAutoScale(true); webPlotterPage.setMaxSamples(50); // Start the WebApp server if (!webAppsServer.begin(WIFI_SSID, WIFI_PASSWORD)) { while (1) { Serial.println("Failed to start WebApp server!"); delay(1000); } } // Set up callbacks webPlotterPage.onPlotterDataRequest([]() { Serial.println("Web client requested data"); sendSensorData(); }); Serial.println("\nWebPlotter is ready!"); Serial.println("Usage Instructions:"); Serial.println("1. Connect to the WiFi network"); Serial.println("2. Open your web browser"); Serial.println("3. Navigate to the Arduino's IP address"); Serial.println("4. Click on 'Web Plotter' to view real-time data"); Serial.println("\nGenerating simulated sensor data..."); } void loop() { // Handle web server and WebSocket connections webAppsServer.loop(); // Send sensor data at regular intervals if (millis() - lastDataTime >= DATA_INTERVAL) { lastDataTime = millis(); sendSensorData(); timeCounter += DATA_INTERVAL / 1000.0; // Convert to seconds } } void sendSensorData() { // Generate simulated sensor data // In a real application, replace these with actual sensor readings // Simulated temperature sensor (sine wave with noise) float temperature = 25.0 + 5.0 * sin(timeCounter * 0.5) + random(-100, 100) / 100.0; // Simulated humidity sensor (cosine wave) float humidity = 50.0 + 20.0 * cos(timeCounter * 0.3); // Simulated light sensor (triangle wave) float light = 512.0 + 300.0 * (2.0 * abs(fmod(timeCounter * 0.2, 2.0) - 1.0) - 1.0); // Simulated analog pin reading float analogValue = analogRead(A0); // Send data using different methods: // Method 1: Send individual values (uncomment to use) // webPlotterPage.sendPlotData(temperature); // Method 2: Send multiple values at once webPlotterPage.sendPlotData(temperature, humidity, light / 10.0, analogValue / 100.0); // Method 3: Send array of values (alternative approach) // float values[] = {temperature, humidity, light / 10.0, analogValue / 100.0}; // webPlotterPage.sendPlotData(values, 4); // Method 4: Send raw data string (for custom formatting) // String dataLine = String(temperature, 2) + " " + String(humidity, 1) + " " + String(light / 10.0, 1); // webPlotterPage.sendPlotData(dataLine); // Print to Serial Monitor in Serial Plotter compatible format // Format: Temperature Humidity Light Analog (tab-separated for Serial Plotter) Serial.print(temperature, 1); Serial.print("\t"); Serial.print(humidity, 1); Serial.print("\t"); Serial.print(light / 10.0, 1); Serial.print("\t"); Serial.println(analogValue / 100.0, 2); }
  • Configure WiFi credentials in the code by updating these lines:
const char WIFI_SSID[] = "YOUR_WIFI_NETWORK"; const char WIFI_PASSWORD[] = "YOUR_WIFI_PASSWORD";
  • Click Upload button on Arduino IDE to upload code to Arduino UNO R4/DIYables STEM V4 IoT
  • Open the Serial Monitor
  • Check out the result on Serial Monitor. It looks like the below
COM6
Send
DIYables WebApp - Web Plotter Example INFO: Added app / INFO: Added app /web-plotter DIYables WebApp Library Platform: Arduino Uno R4 WiFi Network connected! IP address: 192.168.0.2 HTTP server started on port 80 Configuring WebSocket server callbacks... WebSocket server started on port 81 WebSocket URL: ws://192.168.0.2:81 WebSocket server started on port 81 ========================================== DIYables WebApp Ready! ========================================== 📱 Web Interface: http://192.168.0.2 🔗 WebSocket: ws://192.168.0.2:81 📋 Available Applications: 🏠 Home Page: http://192.168.0.2/ 📊 Web Plotter: http://192.168.0.2/web-plotter ==========================================
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  
  • If you do not see anything, reboot Arduino board.
  • Take note of the IP address displayed, and enter this address into the address bar of a web browser on your smartphone or PC.
  • Example: http://192.168.0.2
  • You will see the home page like below image:
Arduino UNO R4 DIYables WebApp Home page with Web Plotter app
  • Click to the Web Plotter link, you will see the Web Plotter app's UI like the below:
Arduino UNO R4 DIYables WebApp Web Plotter app
  • Or you can also access the page directly by IP address followed by /web-plotter. For example: http://192.168.0.2/web-plotter
  • Watch as the Arduino generates simulated sensor data and plots it in real-time. You'll see multiple colored lines representing different data streams.

Creative Customization - Visualize Your Data Creatively

Transform the plotting interface to match your unique project requirements and create stunning data visualizations:

Data Source Configuration

Replace simulated data with real sensor readings:

Method 1: Single Sensor Reading
void sendTemperatureData() { float temperature = analogRead(A0) * (5.0 / 1023.0) * 100; // LM35 temperature sensor webPlotterPage.sendPlotData(temperature); }
Method 2: Multiple Sensors
void sendMultipleSensors() { float temperature = readTemperature(); float humidity = readHumidity(); float light = analogRead(A1) / 10.0; float pressure = readPressure(); webPlotterPage.sendPlotData(temperature, humidity, light, pressure); }
Method 3: Array of Values
void sendSensorArray() { float sensors[6] = { analogRead(A0) / 10.0, // Sensor 1 analogRead(A1) / 10.0, // Sensor 2 analogRead(A2) / 10.0, // Sensor 3 digitalRead(2) * 50, // Digital state millis() / 1000.0, // Time counter random(0, 100) // Random data }; webPlotterPage.sendPlotData(sensors, 6); }

Plot Customization

Custom Plot Appearance
void setupCustomPlot() { webPlotterPage.setPlotTitle("Environmental Monitoring Station"); webPlotterPage.setAxisLabels("Time (minutes)", "Sensor Readings"); webPlotterPage.setYAxisRange(0, 100); // Fixed Y-axis range webPlotterPage.setMaxSamples(100); // Show more data points }
Dynamic Configuration
void setupDynamicPlot() { webPlotterPage.setPlotTitle("Smart Garden Monitor"); webPlotterPage.setAxisLabels("Sample #", "Values"); webPlotterPage.enableAutoScale(true); // Auto-adjust Y-axis // Configure callbacks for interactive features webPlotterPage.onPlotterDataRequest([]() { Serial.println("Client connected - sending initial data"); sendInitialDataBurst(); }); }

Advanced Data Processing

Moving Average Filter
float movingAverage(float newValue) { static float readings[10]; static int index = 0; static float total = 0; total -= readings[index]; readings[index] = newValue; total += readings[index]; index = (index + 1) % 10; return total / 10.0; } void sendFilteredData() { float rawValue = analogRead(A0); float filteredValue = movingAverage(rawValue); webPlotterPage.sendPlotData(rawValue / 10.0, filteredValue / 10.0); }
Data Logging with Timestamps
void sendTimestampedData() { unsigned long currentTime = millis() / 1000; float sensorValue = analogRead(A0) / 10.0; // Send time and value as separate data series webPlotterPage.sendPlotData(currentTime, sensorValue); // Also log to Serial for debugging Serial.print("Time: "); Serial.print(currentTime); Serial.print("s, Value: "); Serial.println(sensorValue); }

Integration Examples

Environmental Monitoring
#include <DHT.h> #define DHT_PIN 2 #define DHT_TYPE DHT22 DHT dht(DHT_PIN, DHT_TYPE); void sendEnvironmentalData() { float temperature = dht.readTemperature(); float humidity = dht.readHumidity(); float lightLevel = analogRead(A0) / 10.0; if (!isnan(temperature) && !isnan(humidity)) { webPlotterPage.sendPlotData(temperature, humidity, lightLevel); Serial.print("T: "); Serial.print(temperature); Serial.print("°C, H: "); Serial.print(humidity); Serial.print("%, Light: "); Serial.println(lightLevel); } }
Motor Control Feedback
void sendMotorData() { int motorSpeed = analogRead(A0); // Speed potentiometer int currentDraw = analogRead(A1); // Current sensor int motorPosition = digitalRead(2); // Position sensor float speedPercent = (motorSpeed / 1023.0) * 100; float currentAmps = (currentDraw / 1023.0) * 5.0; float positionDegrees = motorPosition * 90; webPlotterPage.sendPlotData(speedPercent, currentAmps, positionDegrees); }
PID Controller Visualization
float setpoint = 50.0; float kp = 1.0, ki = 0.1, kd = 0.01; float integral = 0, previousError = 0; void sendPIDData() { float input = analogRead(A0) / 10.0; float error = setpoint - input; integral += error; float derivative = error - previousError; float output = (kp * error) + (ki * integral) + (kd * derivative); previousError = error; // Plot setpoint, input, error, and output webPlotterPage.sendPlotData(setpoint, input, error, output); }

Performance Optimization

Efficient Data Transmission
unsigned long lastPlotUpdate = 0; const unsigned long PLOT_INTERVAL = 100; // Update every 100ms void efficientDataSending() { if (millis() - lastPlotUpdate >= PLOT_INTERVAL) { lastPlotUpdate = millis(); // Only send data at defined intervals float value1 = analogRead(A0) / 10.0; float value2 = analogRead(A1) / 10.0; webPlotterPage.sendPlotData(value1, value2); } }
Conditional Data Sending
float lastSentValue = 0; const float CHANGE_THRESHOLD = 5.0; void sendOnChange() { float currentValue = analogRead(A0) / 10.0; // Only send if value changed significantly if (abs(currentValue - lastSentValue) > CHANGE_THRESHOLD) { webPlotterPage.sendPlotData(currentValue); lastSentValue = currentValue; } }

Project Ideas

Scientific Applications

  • Data Logger: Record temperature, humidity, pressure over time
  • Vibration Analysis: Monitor accelerometer data for mechanical systems
  • pH Monitoring: Track water quality in aquaponics systems
  • Solar Panel Efficiency: Monitor voltage/current output vs. sunlight

Educational Projects

  • Physics Experiments: Visualize pendulum motion, spring oscillations
  • Chemistry Lab: Monitor reaction rates and temperature changes
  • Biology Studies: Track plant growth sensors, environmental factors
  • Mathematics: Plot mathematical functions and algorithmic outputs

Home Automation

  • Energy Monitoring: Track power consumption patterns
  • Garden Automation: Monitor soil moisture, light levels
  • HVAC Control: Visualize temperature and humidity trends
  • Security System: Plot motion sensor activities

Robotics and Control

  • Robot Navigation: Plot position and orientation data
  • Motor Control: Monitor speed, torque, and efficiency
  • Sensor Fusion: Combine multiple sensor readings
  • Path Planning: Visualize robot movement algorithms

Troubleshooting

Common Issues

1. No data appearing on plot

  • Check WiFi connection status
  • Verify WebSocket connection in browser console
  • Ensure sendPlotData() is being called regularly
  • Check Serial Monitor for error messages

2. Plot appears jumpy or erratic

  • Implement data filtering (moving average)
  • Reduce data sending frequency
  • Check for sensor noise or connection issues
  • Verify power supply stability

3. Browser performance issues

  • Reduce maximum samples (setMaxSamples())
  • Lower data transmission rate
  • Close other browser tabs
  • Use hardware acceleration in browser

4. WebSocket connection drops

  • Check WiFi signal strength
  • Verify router settings (firewall, port blocking)
  • Implement reconnection logic in custom code
  • Monitor Arduino memory usage

Debug Tips

Enable Detailed Logging
void debugPlotterData() { Serial.println("=== Plotter Debug Info ==="); Serial.print("Free RAM: "); Serial.println(freeMemory()); Serial.print("Connected clients: "); Serial.println(server.getConnectedClients()); Serial.print("Data rate: "); Serial.println("Every " + String(DATA_INTERVAL) + "ms"); Serial.println("========================"); }
Test Data Generation
void generateTestPattern() { static float phase = 0; float sine = sin(phase) * 50 + 50; float cosine = cos(phase) * 30 + 70; float triangle = (phase / PI) * 25 + 25; webPlotterPage.sendPlotData(sine, cosine, triangle); phase += 0.1; if (phase > 2 * PI) phase = 0; }

Advanced Features

Custom Data Formatting

void sendFormattedData() { float temp = 25.5; float humidity = 60.3; // Create custom formatted data string String dataLine = String(temp, 1) + "\t" + String(humidity, 1); webPlotterPage.sendPlotData(dataLine); }

Integration with Other WebApps

void setupMultipleApps() { // Add multiple web applications server.addApp(new DIYablesHomePage()); server.addApp(new DIYablesWebDigitalPinsPage()); server.addApp(new DIYablesWebSliderPage()); server.addApp(&webPlotterPage); server.addApp(new DIYablesNotFoundPage()); // Configure interactions between apps webSliderPage.onSliderValueFromWeb([](int slider1, int slider2) { // Use slider values to control what gets plotted float scaleFactor = slider1 / 255.0; // ... plotting logic }); }

Real-time Control with Plotting

void controlAndPlot() { // Read control inputs int targetSpeed = analogRead(A0); // Control hardware analogWrite(9, targetSpeed / 4); // PWM output // Read feedback int actualSpeed = analogRead(A1); int motorCurrent = analogRead(A2); // Plot target vs actual webPlotterPage.sendPlotData( targetSpeed / 4.0, // Target speed actualSpeed / 4.0, // Actual speed motorCurrent / 10.0 // Current draw ); }

Next Steps

After mastering the WebPlotter example, explore:

  1. MultipleWebApps - Combine plotting with control interfaces
  2. WebMonitor - Add debugging capabilities alongside plotting
  3. Custom Applications - Build your own specialized plotting tools
  4. Data Analysis - Implement statistical analysis of plotted data

Support

For additional help:

  • Check the API Reference documentation
  • Visit DIYables tutorials: https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-diyables-webapps
  • Arduino community forums
  • WebSocket debugging tools in browser developer console

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!