Biofeedback Butterfly Using Arduino + MAX30102
by mariiahruntes in Circuits > Arduino
206 Views, 1 Favorites, 0 Comments
Biofeedback Butterfly Using Arduino + MAX30102
Modern students spend most of their time surrounded by screens, deadlines, notifications, and constant pressure. Instead of slowing down and taking breaks, many people ignore stress until it becomes overwhelming.
The Biofeedback Butterfly is a wearable robotic butterfly designed as a calming biofeedback device. The butterfly reacts to the user’s heart rate in real time: when the heart beats faster, the wings flap more rapidly; as the user relaxes, the wings slow down and eventually stop.
This project was created as a “useless machine” for a robotics course. Rather than improving productivity, the goal of the device is to encourage mindfulness and relaxation through wearable kinetic interaction.
Supplies
Electronics
- Arduino Uno (ArduinoUno)
- MAX30102 (max30102)
- SG90 Micro Servo (SG90)
- Jumper wires
- Breadboard (board)
Mechanical Parts
- Thin cardboard / plastic sheets
- Paper wings or lightweight foam
- Glue
- Thin wire / paperclips (linkages)
- Screws (3x)
Software
- Arduino IDE
- SparkFun MAX30102 Library (git.hub.library)
Wiring the Heart Rate Sensor
Connect the MAX30102 sensor to the Arduino Nano using the following connections:
VCC - 3.3V
GND - GND
SDA - A4
SCL - A5
Common issue: Some MAX30102 modules require 3.3V power. Using 5V may damage the sensor depending on the breakout board.
Testing the MAX30102 Sensor
First things first - before building the butterfly mechanism, first verify that the heart-rate sensor is working correctly.
Instructions:
- Install the SparkFun MAX30102 Library (git.hub.library)
- Open: File → Examples → MAX3010x → "Example5_HeartRate"
- Wire Sensor to the Arduino board: -5V = 5V / -GND = GND / -SDA = A4 (or SDA) / -SCL = A5 (or SCL) / -INT = Not connected
- Upload the example code to the Arduino Uno
- Open the Serial Monitor
- Check: If the sensor powers on correctly, a red LED should become visible. (foto 1 - sensor off; foto 2 - sensor on)
- Place your finger gently on the sensor. Do not press too hard, as excessive pressure may reduce reading quality.
- After a few seconds, BPM values should begin appearing in the Serial Monitor (If you cannot see any data, check that the Serial Monitor is open and the baud rate is set correctly in the bottom-right corner).
Testing the Servo Motor
The servo motor controls the butterfly wing motion. Before integrating it into the mechanism, test that it rotates correctly.
Instructions:
- Connect the servo signal wire
Signal (orange wire) - D9
VCC (red wire) - 5V
GND - GND
- Open new file in Arduino and load test Code:
#include <Servo.h>
Servo myServo;
void setup() {
myServo.attach(9);
}
void loop() {
for (int pos = 0; pos <= 180; pos += 5) {
myServo.write(pos);
delay(20);
}
for (int pos = 180; pos >= 0; pos -= 5) {
myServo.write(pos);
delay(20);
}
}
- Upload code to the Arduino Uno. Expected result: The servo should smoothly rotate back and forth.
Building the Final Circuit
Now combine the heart-rate sensor and servo motor into one circuit.
Instructions:
- Plug in you sensor and motor to Arduino board (like it shown on the diagram)
- Upload the final Arduino code (provided below)
What the code does:
- Reads BPM data from the MAX30102
- Smooths the heart-rate readings
- Maps BPM to servo speed
- Controls butterfly wing movement in real time
- Place your finger on the sensor and wait until it starts recognizing your pulse data (sometimes this can take up to 2 minutes).
- Check the Serial Monitor output in Arduino IDE - you should see values such as BPM, Avg, Current, and Step Size.
- Expected result: the motor rotates slower or faster depending on your heart rate.(Example output: BPM=58.37, Avg=35, Current=152, Step Size=1)
!! Troubleshooting !!
If your motor is not moving, it could be:
1.In the output line:
- If your BPM = 0 (there is no input coming from the sensor), you have to wait until it starts recording. You can also try to breathe faster or place another finger on the sensor :)
- Low BPM (for example BPM=9.96, Avg=0, Current=10, StepSize=0)
-> in the code:
if (bpmToUse < 20)
stepSize = minStepSize;
So all BPM values under 20 produce no motion. You have to wait until your heart rate goes up.
2.On the board:
- your wire connection is not stable (check wires)
- your wire connection is false (check the circuit one more time)
Downloads
3D Printing the Butterfly Mechanism
We designed a lightweight mechanism that creates natural butterfly wing motion.
Instructions:
- Open the provided 3D model files and print the parts using the following settings:
Printing Settings:
- Nozzle: 0.4 mm
- Infill: 15%
- Material: PETG
*Transparent PETG was used to create a lightweight and delicate visual effect.
Downloads
Assembling the Mechanism
Instructions:
- Insert the servo motor into the printed "housing"
- Assemble the wing linkage system
- Attach the butterfly wings
- Secure all moving parts carefully
Final Assembly
Time for action! You are almost done. Now combine the electronics and the butterfly mechanism into one wearable system.
Instructions:
- Attach the butterfly to the wrist strap and connect the servo and sensor to the Arduino.
- Place your finger on the sensor and watch the butterfly react to your heartbeat in real time. Enjoy!
Conclusion
Biofeedback Butterfly combines wearable robotics, biofeedback, and kinetic art into a small interactive object designed to encourage mindfulness in stressful environments.
Although intentionally “useless” in a practical sense, the project explores how technology can create emotional experience rather than purely productive ones.