Pulsey the Pulse Sensor Lamp Robot
Pulsey the Pulse Lamp Robot is a robot that detects a human’s pulse and reacts by producing light from RGB LEDs accordingly. It uses two blink M RGB leds as its eyes. It uses the servo motor to represent the robots heart-shaped hair. Both the servo motor and the RGB leds react to the human pulse detected from the pulse sensor. Once a pulse is detected, the RGB LEDs fade to a shade of green (much like the green of the pulse sensor). The servo turns once a pulse is detected.
There are also two potentiometers. One is used to control the HSV of the eye LEDS when it does not detect a pulse. It can be rotated to make the eyes into diverse colors. The other potentiometer is used to adjust the brightness of the eyes therefore giving much more of the color palette. If the brightness is totally reduced, the robot will not light up its eye LEDs unless a pulse is detected.
#include "Wire.h" #include "BlinkM_funcs.h" //Servo Motor #include <Servo.h> Servo myServo; int noTurn = 90; int rightTurn = 95; int leftTurn = 70; //Blink M int sensorPin = 0; int ledPin = 13; int sensorValue = 0; int blinkm_addr = 0; int redVal = 0; int grnVal = 0; int bluVal = 0; // VARIABLES unsigned long time; unsigned long lastTime; int Sensor; int lastSensor; int Peak; int Trough; int beats[10]; int beatCounter = 0; int QuantifiedSelf; int drop; int fadeRate = 10; int Fade = 0; boolean falling = false; int PulseSensor = 0; void setup() { myServo.attach(2); myServo.write(noTurn); pinMode(ledPin, OUTPUT); BlinkM_beginWithPower(); BlinkM_stopScript(blinkm_addr); Serial.println("BlinkMSensor0 ready"); Serial.begin(115200); lastTime = millis(); } void loop() { Sensor = analogRead(PulseSensor); Serial.print("s"); Serial.println(Sensor); if (falling == false){ if (Sensor < lastSensor-1){ falling = true; Serial.print("P"); Serial.println(Peak); myServo.write(rightTurn); normalPulse(); } else if(Sensor > lastSensor){ Peak = Sensor; lastSensor = Sensor; } } if (falling == true){ if (Sensor > lastSensor){ falling = false; Serial.print("T"); Serial.println(Trough); drop = Peak - Trough; Peak = 0; if (drop > 4 && drop <60){ timeBeat(); Serial.print("d"); Serial.println(drop); myServo.write(leftTurn); greenPulse(); } } else if (Sensor < lastSensor){ Trough = Sensor; lastSensor = Sensor; } } delay(100); } void timeBeat(){ time = millis(); beats[beatCounter] = time - lastTime; lastTime = time; beatCounter ++; if (beatCounter == 10){ QuantifiedSelf = getBPM(); Serial.print("q"); Serial.println(QuantifiedSelf); beatCounter = 0; } } int getBPM(){ int dummy; int mean; boolean done = false; while(done != true){ done = true; for (int j=0; j<9; j++){ if (beats[j] > beats[j + 1]){ dummy = beats[j + 1]; beats [j+1] = beats[j] ; beats[j] = dummy; done = false; } } } for(int k=1; k<9; k++){ mean += beats[k]; } mean /=8; mean = 60000/mean; return mean; } void normalPulse(){ sensorValue = analogRead(sensorPin); Serial.println(sensorValue); grnVal = sensorValue/4; BlinkM_setFadeSpeed( blinkm_addr, 50); BlinkM_fadeToRGB( blinkm_addr, 255, 255, 255); delay(100); } void greenPulse(){ sensorValue = analogRead(sensorPin); Serial.println(sensorValue); grnVal = sensorValue/4; BlinkM_setFadeSpeed( blinkm_addr, 50); BlinkM_fadeToRGB( blinkm_addr, 0, grnVal, 20); delay(100); } void redPulse(){ sensorValue = analogRead(sensorPin); Serial.println(sensorValue); grnVal = sensorValue/4; BlinkM_setFadeSpeed( blinkm_addr, 50); BlinkM_fadeToRGB( blinkm_addr, grnVal, 0, 0); delay(100); }
There is also the BlinkM_funcs.h file that needs to be in the same folder.
This can be downloaded here
Reply