• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

I2C OLED , ESP8266 nodemcu and Pulse Sensor

Q&A Forum › Category: ESP8266 › I2C OLED , ESP8266 nodemcu and Pulse Sensor
0 Vote Up Vote Down
wael elsisi asked 4 years ago

I’m using I2C OLED , ESP8266 nodemcu and Pulse Sensor.
I get the wrong reading Every time I put my finger on top of the pulse sensor.
Also, the sensor keeps displaying reading without touch the sensor. 
Could you help me?

#include <Adafruit_SSD1306.h>
#define OLED_Address 0x3C // 0x3C device address of I2C OLED. Few other OLED has 0x3D
Adafruit_SSD1306 oled(128, 64); // create our screen object setting resolution to 128×64

int a=0;
int lasta=0;
int lastb=0;
int LastTime=0;
int ThisTime;
bool BPMTiming=false;
bool BeatComplete=false;
int BPM=0;
#define UpperThreshold 550
#define LowerThreshold 500

void setup() {
oled.begin(SSD1306_SWITCHCAPVCC, OLED_Address);
oled.clearDisplay();
oled.setTextSize(2);
}

void loop()
{
if(a>127)
{
oled.clearDisplay();
a=0;
lasta=a;
}

ThisTime=millis();
int value=analogRead(0);
oled.setTextColor(WHITE);
int b=60-(value/16);
oled.writeLine(lasta,lastb,a,b,WHITE);
lastb=b;
lasta=a;

if(value>UpperThreshold)
{
if(BeatComplete)
{
BPM=ThisTime-LastTime;
BPM=int(60/(float(BPM)/1000));
BPMTiming=false;
BeatComplete=false;
//tone(8,1000,250);
}
if(BPMTiming==false)
{
LastTime=millis();
BPMTiming=true;
}
}
if((value<LowerThreshold)&(BPMTiming))
BeatComplete=true;

oled.writeFillRect(0,50,128,16,BLACK);
oled.setCursor(0,50);
oled.print(“BPM:”);
oled.print(BPM);

oled.display();
a++;
}

3 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
Can you show me the pulse sensor that you’re using?
Did you try a sample sketch for the sensor?
I’ve tried a pulse sensor once and it worked incredibly bad. Maybe it is something related with the hardware and not the software itself.
Regards,
Sara

0 Vote Up Vote Down
Hamish Low answered 4 years ago

The sensor output is noisy and those threshold values need to be adjusted dynamically by your code to identify the pulse signal within the output analog values.  More explanation can be seen at https://www.circuitstoday.com/pulse-sensor-arduino. When no finger is on the sensor it can ‘detect’ the 50Hz/60hz  pulse of the room lights from the AC mains supply ! 

0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi Hamish.
Thanks for clarifying that.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.