I'm trying to build a simple device to monitor my heart rate. The components are the following:
- A TFT 2.8" LCD screen to display relevant information for the user.
- 3 buttons for the user to interact with the device.
- A PPG sensor to acquire the user's heartbeat.
- An Arduino Uno.
- A breadboard to connect the components.
The setup of the device looks like this:
which is connected in the following way:
I haven't included the TFT screen here in the drawing of the circuit because I'm using Tinkercad and they don't have it in the components. The screen has the following ports:
The code that I'm using is the following:
// Heartbeat sensor libraries
#define USE_ARDUINO_INTERRUPTS true
#include <PulseSensorPlayground.h>
// TFT screen libraries
#include <TFT.h> // Arduino LCD library
// Heartbeat sensor variables
const int PulseWire = 0; // PulseSensor WHITE WIRE connected to ANALOG PIN 0
int Threshold = 550; // Determine which Signal to "count as a beat"
PulseSensorPlayground pulseSensor; // Creates an instance of PulseSensorPlayground
// TFT screen variables
#define cs 10
#define dc 9
#define rst 8
TFT TFTscreen = TFT(cs, dc, rst);
// Button variables
const int buttonUp = 2;
const int buttonDown = 3;
const int buttonOk = 4;
#define DELAY 1.0/64.0
void setup() {
Serial.begin(9600); // For Serial Monitor
pulseSensor.analogInput(PulseWire);
pulseSensor.setThreshold(Threshold);
pulseSensor.begin(); // Start heartbeat sensor
TFTscreen.begin(); // Start TFT screen
drawScreen(); // Draw content of the screen
// Buttons
pinMode(buttonUp, INPUT);
pinMode(buttonDown, INPUT);
pinMode(buttonOk, INPUT);
}
bool buttonUpPrev = false;
bool buttonDownPrev = false;
bool buttonOkPrev = false;
void loop(){
if(buttonUpPrev == HIGH && digitalRead(buttonUp) == LOW){
Serial.println("button up");
}
if(buttonDownPrev == HIGH && digitalRead(buttonDown) == LOW){
Serial.println("button down");
}
if(buttonOkPrev == HIGH && digitalRead(buttonOk) == LOW){
Serial.println("button ok");
}
buttonUpPrev = digitalRead(buttonUp);
buttonDownPrev = digitalRead(buttonDown);
buttonOkPrev = digitalRead(buttonOk);
//Serial.println(pulseSensor.getLatestSample());
delay(DELAY);
}
My problem is that when I press one of the buttons, the TFT screen flickers, as if less voltage gets to the screen. Also, sometimes I see "button down" in the Serial Monitor when nothing is being pressed. Overall the device works, but I wonder if I made a mistake.
My question is: Is there a problem with the cabling of this device? I've studied Computer Science and I just know the basics of electronics. Thank you!
delay(1.0/64.0);
, usedelayMicroSeconds(15);
.