For midterm project:

On class: Managing the thermistor and connect the sound and the thermistor

We tried the thermistor and found that its approximate range is 510 to 590, so we set the corresponding "correct" and "incorrect" thresholds according to this range. Between 510 and 550, the temperature is relatively low and will give the "wrong" signal; as the user rubs the crystal ball, the temperature increases and will give the "right" signal when it reaches about 550.

Saturday: choosing and buying materials: a globe and feathers

Sunday: sound for correct and wrong answer

On class we tried a few frequency to represent right and wrong sounds. In order to give more accurate signals that people would understand easily, we found some sounds for correct and wrong answers online, and guidance for notes frequencies, trying to reproduce the sound effect with the speaker by adjusting different frequencies and delays.

void setup() {
  pinMode(7, OUTPUT);
}

void loop() {
  tone(7,440,100);
  delay(100);
  tone(7,659,100);
  delay(100);
  tone(7,880,200);
  delay(2000);

  tone(7,105,1500);
  delay(3000);
}

right and wrong sounds.mp4

Monday: adding each part together

Athena found a library that fits our heart rate sensor so we still use heart rate and temperature as input. We want to make the temperature a threshold so the participant should rub the ball first, and when it reaches a certain degree, it would give a signal based on the heart rate. The signals are LEDs and sounds. When the heart rate is high, it shows nervous and unconfident, then it shows signals for ‘no’, which are red led light and a sound of wrong made by 2 speakers; when it’s low, it sort of means confident and calm, then the answer would be ‘yes’, which is represented by green light and a sound of right.

In order to allow the participants to test the heartbeat while rubbing the ball, we desoldered the sensor and soldered it with 4 long wires.

521666056628_.pic.jpg

After trying the ball and putting in the feathers, we found that one LED was not enough, so we added two for each color to make it look brighter through the feathers. We also added a speaker so it would sound louder. Additionally, we adjusted the threshold of temperature when the thermistor was put in the ball with the breadboard.

501666056587_.pic.jpg

481666056145_.pic.jpg

We also tried using a smaller breadboard to put it inside the ball, but it didn’t fit as well as the original one.

511666056599_.pic.jpg

49_1666056563.mp4

Here’s the code:

int redLED1 = 2;

int redLED2 = 3;

int redLED3 = 4;

int greenLED1 = 5;

int greenLED2 = 6;

int greenLED3 = 7;

int speaker = 8;

 

#include <Wire.h>

#include "MAX30105.h"

#include "heartRate.h"

 

MAX30105 particleSensor;

 

const byte RATE_SIZE = 4; //Increase this for more averaging. 4 is good.

byte rates[RATE_SIZE]; //Array of heart rates

byte rateSpot = 0;

long lastBeat = 0; //Time at which the last beat occurred

 

float beatsPerMinute;

int beatAvg;

 

// int temperature = analogRead(A0);

 

void setup()

{

  pinMode(redLED1, OUTPUT);

  pinMode(redLED2, OUTPUT);

  pinMode(redLED3, OUTPUT);

  pinMode(greenLED1, OUTPUT);

  pinMode(greenLED2, OUTPUT);

  pinMode(greenLED3, OUTPUT);

  pinMode(speaker, OUTPUT);

  delay(5000);

 

 

  Serial.begin(115200);

  Serial.println("Initializing...");

 

  // Initialize sensor

  if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed

  {

    Serial.println("MAX30105 was not found. Please check wiring/power. ");

    while (1);

  }

  Serial.println("Place your index finger on the sensor with steady pressure.");

 

  particleSensor.setup(); //Configure sensor with default settings

  particleSensor.setPulseAmplitudeRed(0x0A); //Turn Red LED to low to indicate sensor is running

  particleSensor.setPulseAmplitudeGreen(0); //Turn off Green LED

}

 

void loop()

{

  long irValue = particleSensor.getIR();

 

  if (checkForBeat(irValue) == true)

  {

    //We sensed a beat!

    long delta = millis() - lastBeat;

    lastBeat = millis();

 

    beatsPerMinute = 60 / (delta / 1000.0);

 

    if (beatsPerMinute < 255 && beatsPerMinute > 20)

    {

      rates[rateSpot++] = (byte)beatsPerMinute; //Store this reading in the array

      rateSpot %= RATE_SIZE; //Wrap variable

 

      //Take average of readings

      beatAvg = 0;

      for (byte x = 0 ; x < RATE_SIZE ; x++)

        beatAvg += rates[x];

      beatAvg /= RATE_SIZE;

    }

 

    if (analogRead(A0) >= 530) {

      if (beatAvg >= 70 && irValue >= 50000) {

      digitalWrite(redLED1, HIGH);

      digitalWrite(redLED2, HIGH);

      digitalWrite(redLED3, HIGH);

      digitalWrite(greenLED1, LOW);

      digitalWrite(greenLED2, LOW);

      digitalWrite(greenLED3, LOW);

      tone (8, 105, 1500);

      delay(500);

      } else if (beatAvg < 70 && irValue >= 50000) {

      digitalWrite(redLED1, LOW);

      digitalWrite(redLED2, LOW);

      digitalWrite(redLED3, LOW);

      digitalWrite(greenLED1, HIGH);

      digitalWrite(greenLED2, HIGH);

      digitalWrite(greenLED3, HIGH);

      tone (8, 440, 100);

      delay(100);

      tone(8, 659, 100);

      delay(100);

      tone(8, 880,200);     

     delay(500);

     }

     else{

      digitalWrite(redLED1, LOW);

      digitalWrite(redLED2, LOW);

      digitalWrite(redLED3, LOW);

      digitalWrite(greenLED1, LOW);

      digitalWrite(greenLED2, LOW);

      digitalWrite(greenLED3, LOW);

      tone (8, 0, 1000);

     }

    } else {

      digitalWrite(redLED1, LOW);

      digitalWrite(redLED2, LOW);

      digitalWrite(redLED3, LOW);

      digitalWrite(greenLED1, LOW);

      digitalWrite(greenLED2, LOW);

      digitalWrite(greenLED3, LOW);

      tone (8, 0, 1000);

    }

    

    

    

  }

 

  Serial.print("IR=");

  Serial.print(irValue);

  Serial.print(", BPM=");

  Serial.print(beatsPerMinute);

  Serial.print(", Avg BPM=");

  Serial.print("Avg BPM=");

  Serial.print(beatAvg);

 

if (irValue < 50000)

    Serial.print(" No finger?");

 

  Serial.println();

 

}