BPM WiFi Server with ESP32

This tutorial will show you how to connect PulseSensor to an ESP32 WiFi module, and program it to serve a web page on your local network that updates BPM with every heartbeat.

This project is fully fleshed out in Chapter 10 of our new book,

Heartbeat Sensor Projects with PulseSensor: Prototyping Biofeedback Devices with PulseSensor!

Pick up your copy today on Amazon, or at Springer.

PulseSensor ESP32 WiFi

Here's a list of materials that we used for this project

  • ESP32-S2 WiFi Module
    • Any ESP32 module will work. We used the Adafruit Feather ESP32-S2
  • USB Cable for programming and power
  • Two LEDs
  • Two Resistors
    • 1K is a good value to start with
  • Phone, tablet, or computer to view the BPM update in browser

The hardware setup is quite simple. Connect the PulseSensor Red and Black wires to +V and GND, and the Purple wire to analog pin A0. The LEDs are connected to digital pins 13 and 5.

If you have not already installed the PulseSensor Playground library, follow this tutorial to make sure you have the latest and greatest.

You will also need to install the ESP32 board files. Open the Settings pane in Arduino IDE. For Windows, click File > Preferences. For Mac, click Arduino_IDE > Settings. Then click the button to add a board URL.

Paste the following link into a new line of the text window.

https://espressif.github.io/arduino-esp32/package_esp32_index.json

Make sure that you press OK when you close the Preferences window when you are done. This will tell Arduino to look for the ESP32 board files. The next step is to download those files. Click on the Board icon at the left panel of Arduino, and do a search for Espressif ESP32.

Install the latest version, and then click the Board icon to exit. Now, make sure that you select the right board for the code. Click on Tools > Board > ESP32 > Adafruit Feather ESP32-S2.

When you have the circuit built and the Arduino files downloaded, connect to your computer with USB, then open the Arduino IDE, and navigate to File > Examples > PulseSensor Playground > PulseSensor_ESP32Before you upload the code to your ESP32, you will have to change a couple of lines of code. We put placeholders in for the network credentials. In order for the ESP to serve the webpage, it will need to connect to your local network. Locate the lines in the code below, and change them to your local network credentials.

/* Replace with your network credentials */

const char* ssid = "SSID";

const char* password = "PASSWORD";

 After programming the ESP32, open up the Serial Monitor to see the message. It will look something like this. Once the ESP32 is connected to your local network, it will tell you the URL that it is serving at. You can also see that there is an option to send the character 'b' to start sending PulseSensor signal data over the serial port. This is so that you can see the PulseSensor waveform in the Serial Plotter if you need to troubleshoot the position and pressure of the PulseSensor. It will print the PulseSensor raw data without effecting the webserver performance.

ESP32 Serial Message

Open a browser window on your mobile or computer, and type the URL from the serial monitor. you will see the following simple webpage. The BPM value will update with every heartbeat!

BPM Web Page

 Have fun!