Documentation
Document your work on your blog, detail how your process of building the circuits and writing the code went. In addition, upload a video of your exercises in action. Any success? Any failures? What did you learn?
For recitation 10, I decided to use the heart sensor I’d be using for my final project. I wanted to display an image after the heart rate was above a certain number. To start, I wired it together, and used Opened IDE, and used the serial record library, in order to prepare to send the heart rate signal into processing. Also, Prof. suggested me to use an “avg” technique in order to have smoother readings. The code part for the processing can be found below:
Circuit Picture:
#define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most acurate BPM math. #include // Includes the PulseSensorPlayground Library. // Variables const int PulseWire = 0; // PulseSensor PURPLE WIRE connected to ANALOG PIN 0 const int LED13 = 13; // The on-board Arduino LED, close to PIN 13. int Threshold = 550; // Determine which Signal to "count as a beat" and which to ignore. // Use the "Gettting Started Project" to fine-tune Threshold Value beyond default setting. // Otherwise leave the default "550" value. PulseSensorPlayground pulseSensor; // Creates an instance of the PulseSensorPlayground object called "pulseSensor" void setup() { Serial.begin(9600); // For Serial Monitor // Configure the PulseSensor object, by assigning our variables to it. pulseSensor.analogInput(PulseWire); pulseSensor.blinkOnPulse(LED13); //auto-magically blink Arduino's LED with heartbeat. pulseSensor.setThreshold(Threshold); // Double-check the "pulseSensor" object was created and "began" seeing a signal. if (pulseSensor.begin()) { Serial.println("start"); //This prints one time at Arduino power-up, or on Arduino reset. } } void loop() { int BPM = pulseSensor.getBeatsPerMinute(); // Calls function on our pulseSensor object that returns BPM as an "int". // "BPM" hold this BPM value now. if (pulseSensor.sawStartOfBeat()) { // Constantly test to see if "a beat happened". Serial.println(" BPM "); // If test is "true", print a message "a heartbeat happened". Serial.print("BPM: "); // Print phrase "BPM: " Serial.println(BPM); // Print the value inside of myBPM. } delay(1); // considered best practice in a simple sketch. }
After, the Arduino part, I started the processing sketch, and added it to a folder, and created a data folder in order to put the image I wanted to load later on. After I set the serial receiver, I wrote the draw part, which included the display of the “bpm” sent from Arduino, I also set an if statement in order to show the image after reaching 90 bpm, but this value can be changed. The code & video can be found below.
To conclude, I believe that the heart rate was super inaccurate at first, however after consulting with professors, they suggested different methods, that I will definitely take into account when modelling for my final.
Picture and Video:
import processing.serial.*; import osteele.processing.SerialRecord.*; PImage photo; Serial serialPort; SerialRecord serialRecord; void setup() { fullScreen(); photo= loadImage("good.jpg"); String serialPortName = SerialUtils.findArduinoPort(); serialPort = new Serial(this, serialPortName, 9600); serialRecord = new SerialRecord(this, serialPort, 1); } void draw () { background(0); serialRecord.read(); int value1= serialRecord.values[0]; if (value1> 0 ) { fill(255); textSize(50); text("BPM:", 900,400); fill(255); textSize(50); text(value1, 900, 500); } if (value1 > 90) { photo.resize(400,300); image(photo,750, 600); } }
Leave a Reply