pulseSensor.begin(); times out ESP8266 wifi shield

Hello, I am looking for some help with getting my Arduino Uno to work with my pulse sensor, https://pulsesensor.com/. Within the code, I tried to use pulseSensor.begin(), however, it times out. When I comment out that line, the code works just fine except for the pulse sensor. It is my first time posting so if there is anything wrong I apologize. Below I will include my code that I am working with and a screenshot of the timeout from the serial console. I have used the test code that pulse sensor have and it worked just fine sending the BPM to the serial console. This is the code for reference, Getting (Calculating) BPM: – World Famous Electronics llc.. Thank you in advance for any and all help.

TLDR: pulseSensor.begin() from PulseSensor Playground library times out the wifi shield. When commented out the code works just fine. Attached is the screenshot of the timeout and code.

//********************************Modify This********************************

#define WIFI_SSID "GUEST"                   // WiFi SSID
#define WIFI_PASS ""               // WiFi PASSWORD
#define AIO_USERNAME "NAME"             // Adafruit IO Username
#define AIO_KEY "KEY"                       // ADAFRUIT IO KEY


#define USE_ARDUINO_INTERRUPTS true    // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h>     // Includes the PulseSensorPlayground Library.   
#include <SPI.h>                                      // Include SPI Library
#include <dht.h>                                      // Include DHT11 Library
#include "Adafruit_MQTT.h"                            // Include Adafruit MQTT Library
#include "Adafruit_MQTT_Client.h"                     // Include Adafruit MQTT Client Library
#include "WiFiEsp.h"                                  // Include ESP8266 Library
#include "SoftwareSerial.h"                           // Include Software Serial Library
#define DHT11_PIN 2                                   // Connect DHT11 Data Pin to UNO Pin 2
#define PulseWire 0                                  // Connect Pulse Sensor Purple Pin to UNO Pin 14
#define AIO_SERVER "io.adafruit.com"                  // Adafruit Server
#define AIO_SERVERPORT 1883                           // Adafruit IO Port

dht DHT;                                              // DHT object creation
SoftwareSerial softserial(4, 5);                      // Using UNO Software Serial RX, TX
int status = WL_IDLE_STATUS;                          // ESP Status Initialization
int reqCount = 0;                                     // Request Received Count
WiFiEspClient client;                                 // WiFiEspClient creation
PulseSensorPlayground pulseSensor;  // Creates an instance of the PulseSensorPlayground object called "pulseSensor"

Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);                       // Connecting to Adafruit IO
Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/temperature");         // Temperature feed MQTT path for Adafruit IO
Adafruit_MQTT_Publish humidity = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/humidity");               // Humidity feed MQTT path for Adafruit IO
Adafruit_MQTT_Publish mod_temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/mod_temperature"); // Modified Temperature feed MQTT path for Adafruit IO
Adafruit_MQTT_Publish pulse = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/pulse");                     // Pulse feed MQTT path for Adafruit IO
Adafruit_MQTT_Publish mod_pulse = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/mod_pulse");             // Modified Pulse feed MQTT path for Adafruit IO

void MQTT_connect()
  int8_t ret;                                         // Declaring Variable
  if (mqtt.connected())                               // Check Connection Status
    return;                                           // Exit if already connected
  Serial.print("Connecting to MQTT ... ");            // Printing to serial monitor
  uint8_t retries = 3;                                // Declaring Variable
  while ((ret = mqtt.connect()) != 0)                 // Return 0 if connected
    Serial.println(mqtt.connectErrorString(ret));     // Printing to serial monitor
    Serial.println("Reconnect within 5 seconds ..."); // Printing to serial monitor
    mqtt.disconnect();                                // Disconnect MQTT connection
    delay(5000);                                      // Wait 5 seconds
    retries--;                                        // Decrease Retry Count
    if (retries == 0)                                 // Check Retries
      while (1);                                      // Stop here if MQTT Connection failed
  Serial.println("MQTT Connected!");                  // Printing to serial monitor

void setup()
  Serial.begin(9600);                                 // Setting up Arduino Serial Baud Rate
  pinMode(DHT11_PIN, INPUT);                          // Seeting up DHT11 as Input
  softserial.begin(115200);                           // Setting up ESP28266 Baud Rate
  softserial.write("AT+CIOBAUD=9600\r\n");            // Modifying ESP8266 Baud Rate
  softserial.write("AT+RST\r\n");                     // Resetting ESP8266
  softserial.begin(9600);                             // Setting up ESP8266 Baud Rate
  WiFi.init(&softserial);                             // Initialize ESP8266 Module

  if (WiFi.status() == WL_NO_SHIELD)                  // Check ESP Sheild Presence
    Serial.println("WiFi Shield Unavailable!");       // Printing to serial monitor
    while (true);                                     // Stop

  while ( status != WL_CONNECTED)                     // Checking WiFi Connection Status
    Serial.print("Connecting to: ");                  // Printing to serial monitor
    Serial.println(WIFI_SSID);                        // Printing to serial monitor
    status = WiFi.begin(WIFI_SSID, WIFI_PASS);        // Connecting to WiFi
  Serial.println("Connected to WiFi!");               // Printing to serial monitor

void loop()
  MQTT_connect();                                     // Calling MQTT_connect function
  int chk = DHT.read11(DHT11_PIN);                    // Read DHT11
  float h = DHT.humidity;                             // Reading Humidity
  float t = DHT.temperature;                          // Reading Temperature
  float mod_t = t + 20;                               // 20 Added with Measured Temperature
  //float p = analogRead(Pulse_PIN);                    // Reading Pulse Sensor Value
  float p = pulseSensor.getBeatsPerMinute();  // Calls function on our pulseSensor object that returns BPM as an "int".
  float mod_p = p + 20;                               // 20 Added with Measured Pulse
  Serial.print(F("\nTemperature:"));                  // Printing to serial monitor
  Serial.print(t);                                    // Printing to serial monitor
  Serial.print(F("\nModified Temperature:"));         // Printing to serial monitor
  Serial.print(mod_t);                                // Printing to serial monitor
  Serial.print(F("\nHumidity:"));                     // Printing to serial monitor
  Serial.print(h);                                    // Printing to serial monitor
  Serial.print(F("\nPulse:"));                        // Printing to serial monitor
  Serial.print(p);                                    // Printing to serial monitor
  Serial.print(F("\nModified Pulse:"));               // Printing to serial monitor
  Serial.print(mod_p);                                // Printing to serial monitor
  temperature.publish(t);                             // Publish Temperature to Adafruit IO
  mod_temperature.publish(mod_t);                     // Publish Modified Temperature to Adafruit IO
  humidity.publish(h);                                // Publish Humidity to Adafruit IO
  pulse.publish(p);                                   // Publish Pulse to Adafruit IO
  mod_pulse.publish(mod_p);                           // Publish Modified Pulse to Adafruit IO
  h = 0;                                              // Clearing variable h 
  t = 0;                                              // Clearing variable t
  mod_t = 0;                                          // Clearing variable mod_t
  p = 0;                                              // Clearing variable p
  mod_p = 0;                                          // Clearing variable mod_p
  delay(60000);                                       // Wait 1 Minute Before Next Publish

Timeout error screenshot below.

You have to provide much more information about what hardware you were using
what is the exact type if WiFi-module that you are using

if it is an ESP8266 or an ESP32 working with this AT-firmware is a big hassle.

You can eliminate the complete arduino by using a nodeMCU-esp32-board
You can connect the pulse-sensor to the ESP32 itself and send the data over WiFi
at the same time.

What maybe the cause is that you wired Tx and Rx the wrong way.

You should use a demo-code for a simple test that checks if you can comunicate with your WiFi-module in general.

best regards Stefan

Hello. The Wi-Fi module I am using is an ESP8266. I also verify that the TX and RX are correct. As stated in the post, I can communicate with my Wi-Fi module as it is sending Temp/Humidity to the Adafruit server just fine. The issue is when I implement the pulseSensor.begin() code, it immediately times out. Thank you for the response.


Were you able to resolve this issue? I am having similar issues with the pulse sensor not being compatible with the wifi.

What was your workaround?


using an ESP8266 through a serial connection with another microcontroller creates a new bottle-neck.

I recommend buying a ESP32 nodemcu

  • cheaper than an arduino ($6 to $10)
  • can execute almost every code that an Arduino can execute and even more
    this means the Arduino Uno becomes obsolete the ESP32 does it all
    DHT11, and pulsesensor and WiFi all at the same time ithout the bottleneck of a serial connection
    because everything is done internally
  • much more flash (ESP32 4 MB compared to Arduino Uno 0,032MB)
  • much more RAM (ESP32 320kB Arduino Uno 2kB)
  • faster (ESP32 120 MHz 32 bit Arduino Uno 16 MHz 8 bit)
  • WLAN onboard
  • more interrupt-capable IO-pins

best regards Stefan

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.