Smart Pillow

Made by Menghan Zhang

Found in DioT 2019: Augmented Objects

A smart pillow that can record your sleep time and wake you up at the right time.

0

Problem

The target audience of this IoT appliance is my husband. As we talked about the problems he had when staying at home, he mentioned he had three pain points for sleep:

  • It’s hard to get up in the morning (especially in winter like this…).
  • He wants to know if he has slept for enough/too long/too short time.
  • Alarms on the phone can’t wake him up. Sometimes he just snoozes or turns off the alarms unconsciously, and then get up late.
0

Goal

A smart pillow that can record how much time you have slept and wake you up at the time you set.

0

Process

Step1: Define basic logic



Step2: Get familiar with the FSR sensor



Step3: Record sleep start and end status

Detect sleep start and end status, and publish the events to the Particle Cloud.



Step4: Sleep data persistence

Since the data on Particle console is temporary, I decided to transfer sleep data from Particle to Google Cloud to make it long-term. I referred to tutorials in Particle docs (https://docs.particle.io/tutorials/integrations/google-cloud-platform/) and here are my main steps:

  1. Add Google Cloud Platform integration on Particle console.
  2. Transfer data from Particle to Google Cloud Pub/Sub.
  3. Store data from Pub/Sub in Google Cloud Datastore.



Step5: Use IFTTT to tell the pillow when to buzz

  1. Create a new applet on IFTTT with two services: Data&Time and Particle.
  2. Wire the buzzer to the circuit.
  3. Define and register a function called "alarm" to Particle Cloud so that IFTTT can call it directly.



Step6: Play the music!

I referred to a tutorial on Arduino (https://www.arduino.cc/en/Tutorial/ToneMelody) to learn how to code music for the buzzer.


0

Outcome


List of Parts:

  • 1 Breadboard
  • 1 Particle Argon
  • 1 FSR Sensor
  • 1 Buzzer
  • 1 LED Light
  • 2 Resistors
  • 1 USB Micro B Cable
  • 8 Jumper Wires
0
// Alarm music related code is inspired by https://www.arduino.cc/en/Tutorial/ToneMelody
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494

// Notes in the melody:
int melody[] = {
    NOTE_C4, NOTE_F4, NOTE_F4, NOTE_F4, NOTE_E4, NOTE_D4, NOTE_C4, 0
};

// Note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
    4,8,8,8,8,4,4,4
};


// Define a pin for FSR
// The FSR will monitor if anyone is on the pillow, so we can track the sleeping time
int fsrPin = A0;

// Create a variable to hold the FSR reading
int fsrReading = 0;

// Create a variable to hold the last FSR reading, so we can compare the current reading to it
int lastFsrReading = 0;

// Define a pin for LED
// the LED will light up when someone is on the pillow
int ledPin = D2;

// Deine a flag that denotes whether to alarm to wake up someone
// 0 means no need to alarm, and 1 means need to alarm
int needAlarm = 0;


void setup() {
    pinMode(ledPin, OUTPUT);

    // Create a cloud variable so that we can monitor the change in console
    Particle.variable("force", &fsrReading, INT);
    
    // Create a cloud function so that IFTTT can call it
    Particle.function("alarm", alarmPlease);
}


void loop() {
    //If there is an alarm and someone is on the pillow, then play music, otherwise don't
    if (needAlarm == 1 && lastFsrReading > 100) {
        playMusic();
    } else {
        needAlarm = 0;
    }
  
    // Use analogRead to read the force 
    // This gives us a value from 0 to 4095
    fsrReading = analogRead(fsrPin);
  
    // Set a rough 100 threshold to detect if anyone is on the pillow
    if (fsrReading > 100 && lastFsrReading <= 100) {
        // Sleep starts
        Particle.publish("sleepStart");
        // Light up LED
        analogWrite(ledPin, 255);
    } else if (fsrReading <= 100 && lastFsrReading > 100) {
        // Sleep ends
        Particle.publish("sleepEnd");
        // Turn off LED
        analogWrite(ledPin, 0);
    }
    lastFsrReading = fsrReading;

    // Wait a second and then loop
    delay(1000);
}


// This function is meant to be call by IFTTT
// Users can set an alarm on IFTTT, and the applet will call this function to make the pillow play music 
int alarmPlease(String command) {
    // Set flag to 1 to play alarm music
    needAlarm = 1;
    return 1;
}


void playMusic() {
    // Iterate over the notes of the melody:
    for (int thisNote = 0; thisNote < 8; thisNote++) {
        // To calculate the note duration, take one second divided by the note type.
        //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
        int noteDuration = 1000 / noteDurations[thisNote];
        tone(8, melody[thisNote], noteDuration);

        // To distinguish the notes, set a minimum time between them.
        // The note's duration + 30% seems to work well:
        int pauseBetweenNotes = noteDuration * 1.30;
        delay(pauseBetweenNotes);
        // Stop the tone playing:
        noTone(8);
    }
}
Click to Expand
0

Next Steps
  • All the sleep data currently are stored in Google Cloud, and the next step would be data visualization and to make the data more accessible to the user on a day to day basis.
  • One feedback I got from my husband is that the "music" of the buzzer is a bit annoying, so in the next iteration, I may replace the buzzer with vibrators so that the waking up experience can be more "friendly".
  • Waking up is hard, so is falling asleep! Inspired by Headspace, I am considering integrating medication guide for sleep to the smart pillow to help relax the body and mind and increase the sleep quality.


0

Reflection

For the current prototype, I roughly count all the time a user spends on the pillow as sleep time, which might not be very accurate. I did some research on how to detect if a person is asleep or awake. A common method used by sleep monitor apps like Sleep Cycle is using the accelerometer inside the phone (the part that knows when you turn it sideways) to detect the movements as you sleep. To make the Smart Pillow smarter, I still need to do more experiments with different sensors to find out the best and most accurate way to collect information.

x
Share this Project

Courses

49713 Designing for the Internet of Things

· 18 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.


Focused on
About

A smart pillow that can record your sleep time and wake you up at the right time.

Created

January 31st, 2019