GPS speedometer and clock
A bike or car speedometer that needs no wheel sensor: satellites do the measuring.
Shop by category
Shop all componentsA normal web page asks for data and waits. A WebSocket keeps a connection open so the ESP32 can push each new reading the moment it is measured. This project serves one HTML page from the ESP32 that opens a WebSocket and draws a line chart on an HTML canvas, using no outside libraries on the page. On the ESP32 side the 'WebSockets' library by Markus Sattler handles the connection. The BMP280 gives temperature and pressure.
Tick anything you already have and the total updates.
BMP280 temperature and pressure sensor
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB phone charger.
ws_graph.inoVerify & upload in Electrolark#include <WiFi.h>
#include <WebServer.h>
#include <WebSocketsServer.h>
#include <Wire.h>
#include <Adafruit_BMP280.h>
const char* WIFI_NAME = "YOUR_WIFI";
const char* WIFI_PASS = "YOUR_PASSWORD";
WebServer http(80);
WebSocketsServer ws(81);
Adafruit_BMP280 bmp;
const char PAGE[] PROGMEM = R"HTML(
<!doctype html><meta name=viewport content="width=device-width,initial-scale=1">
<body style="font-family:sans-serif;text-align:center"><h3>ESP32 live: <span id=v>--</span></h3>
<canvas id=c width=320 height=160 style="border:1px solid #999"></canvas>
<script>
var pts=[],c=document.getElementById('c'),g=c.getContext('2d');
var s=new WebSocket('ws://'+location.hostname+':81/');
s.onmessage=function(e){var d=JSON.parse(e.data);
document.getElementById('v').textContent=d.t.toFixed(1)+' C '+d.p.toFixed(0)+' hPa';
pts.push(d.t);if(pts.length>80)pts.shift();
var lo=Math.min.apply(0,pts)-0.5,hi=Math.max.apply(0,pts)+0.5;
g.clearRect(0,0,320,160);g.beginPath();
pts.forEach(function(y,i){var X=i*4,Y=150-(y-lo)/(hi-lo)*140;i?g.lineTo(X,Y):g.moveTo(X,Y)});g.stroke();};
</script></body>)HTML";
void setup() {
Serial.begin(115200);
Wire.begin(21, 22);
bmp.begin(0x76);
WiFi.begin(WIFI_NAME, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) delay(300);
Serial.print("Open http://"); Serial.println(WiFi.localIP());
http.on("/", []() { http.send_P(200, "text/html", PAGE); });
http.begin();
ws.begin();
}
unsigned long last = 0;
void loop() {
http.handleClient();
ws.loop();
if (millis() - last > 1000) {
last = millis();
String json = "{\"t\":" + String(bmp.readTemperature(), 2) + ",\"p\":" + String(bmp.readPressure() / 100.0, 1) + "}";
ws.broadcastTXT(json);
}
}
The WebSocket uses port 81. Make sure no firewall or VPN is blocking it, and that the browser and ESP32 are on the same network.
Try address 0x77 instead of 0x76, or run an I2C scanner.
The chart scales to the data, so a very steady reading looks flat. Breathe on the sensor to test.
A connection that stays open so either side can send data at any time, unlike a normal page request.
A few. The ESP32 can serve several browsers, but each adds load.
Not in this version. Add an SD card or send readings to MQTT to store them.
4 parts: ESP32-WROOM-32 38-Pin Development Board, BMP280-5V Temperature and Barometric Pressure Sensor Module, Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a advanced project and takes about 2 hours. The build on this page has 6 steps.
No. This page has the complete, tested code (ws_graph.ino).
About ₹543 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Serving a page and a WebSocket from one ESP32; Pushing JSON readings to a browser; Drawing a live chart on a canvas.
Ideas that reuse this build: ESP32 TFT sensor dashboard. They are listed under Take it further on this page.
A bike or car speedometer that needs no wheel sensor: satellites do the measuring.
Records where you went every five seconds, ready to open on a map.
Two boards, two radios: press the button at the gate and it rings indoors.
Check temperature, humidity and pressure from any phone on your Wi-Fi.
Learning project. Check every circuit and the datasheet of each part before you power it up.