Are you still in there?

Made by Savanthi Murthy

'Are you still in there?' is a time management system for the bathroom. It keeps track of how much time you spend in there, and plays music too! It's especially helpful when you have a busy day ahead and the bathroom is shared.

Created: January 29th, 2016



Preparing for early morning classes and appointments are quite stressful, even more so when you have to coordinate with a flatmate who has a similar schedule. Many people consider bath time a perfect time to relax and plan out their day, some even listen to music.  However,  there is a tendency to lose track of time.

My flatmate and I would both find it very convenient if there was some way of ensuring that we don't spend too much time in the bathroom every  morning so that we don't get ourselves and each other late.  She also suggested that an indication of whether the bathroom is occupied at any given point of time would help her organize her morning routine better. 



This device aims to optimize the time spent by a person in the bathroom by indicating to them when they have been in there for longer than 10 minutes. It plays music during this time to provide a relaxing experience.  The device also provides the status of bathroom occupancy to the others who share the bathroom. Further functionality in terms of an online spreadsheet that logs the number of minutes that the bathroom has been used has been provided. This can be used to keep a tab on the average time spent in the bathroom and re-calibrate the device if required. Users could use this to plan out a reward system among themselves.  



Components used:

2 - 1k ohm resistor

1- 1ok ohm resistor

1 - Photoresistor

1 - Green LED

1 - Red LED

1 - Piezospeaker

1 - Particle Photon and breadboard

The circuit was assembled as shown below:

Displaying IMG_8181.JPG  


1. The first part of the circuit that I assembled and coded was the LED output part. The red LED is the one in the bathroom. It blinks once as soon as the light is turned on to indicate that the timer has started. After the light remains on for more than 10 minutes, it blinks continuously. The green LED is outside the bathroom. It glows to signal that the bathroom is in use.

2. The next part of the circuit and coding is the light sensor. A photoresistor was connected to an analog pin as the input part of the circuit. I then calibrated the bathroom light in my house to determine the threshold value that would trigger presence/absence and complete the circuit.

3. The music circuit is an additional feature. A piezospeaker was connected to an analog pin and programmed to play a part of a song. The code for this was obtained from an online source: . Initially, I intended the device to connect to an internet radio service such as Spotify or play music through my iPhone. However, IFTTT does not allow this functionality yet.

4. The last part included connecting the device to the cloud so that the time spent in the bathroom could be logged into a spreadsheet on google drive.

// led1 in bathroom
int ledPin1 = D0;
// led2 outside (maybe in living room)
int ledPin2 = D1;
// to read from photoresistor
int photoCellPin= A0;
int photoCellReading=0;
// set threshold for turning on bathroom light
int threshold= 3000;
bool lightOn= false;
// store the time value since bathroom light was first switched on
long timeSinceThreshold = 0 ;
const int speakerPin = A4;
const int songLength = 18;
char notes[] = "cdfda ag cdfdg gf "; // a space represents a rest
// Beats is an array of values for each note and rest- quater, half and full notes
int beats[] = {1,1,1,1,1,1,4,4,2,1,1,1,1,1,1,4,4,2};
int play = 0;
int flag=0;
int m=0;
int frequency(char note)
  // returns corresponding frequency in Hz for the tone() function.
  int i;
  const int numNotes = 8;  // number of notes

  // The following arrays hold the note characters and their corresponding frequencies.
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523};

  // search through the letters in the array, and if found,it returns the frequency for that note.

  for (i = 0; i < numNotes; i++)
  {  // Step through the notes
    if (names[i] == note)

int tempo = 150;
void setup()
  //led as output
  pinMode( speakerPin , OUTPUT );
  //connect photoCellReading to cloud
  Particle.variable("light", &photoCellReading, INT);
  //Particle.variable("music",&m, INT );
  //to input/output through the usb - for checking

int timeIsUp()
  /*if difference between current time and start time is greater than 10 minutes, return true*/
  if ((millis()- timeSinceThreshold)> 600000)
   return 1;
   return 0;
void loop()
  // read from sensor
  photoCellReading= analogRead(photoCellPin);
  Serial.print ("Sensor reading is: ");
  //see if bathroom light is switched on
  //if light is on, blink inside led once to signal and then start counter for 10min
  //switch outside led on
  int timesUp = timeIsUp();
  if (photoCellReading>threshold && lightOn != true && timesUp == 0)
    //start counter
    Serial.println ("Flag ");
    timeSinceThreshold = millis();
    lightOn = true;
    //switch on outside led
    digitalWrite(ledPin2, HIGH);
    // Blink led in bathroom
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin1, LOW);
  else if (photoCellReading>threshold && lightOn == true && timesUp == 0)
    pinMode(speakerPin, OUTPUT);
    digitalWrite(ledPin2, HIGH);
    int i, duration;
    //Serial.println( "playing melody");
    for (i = 0; i < songLength; i++) // step through the song arrays
      duration = beats[i] * tempo;  // length of note/rest in ms
      if (notes[i] == ' ')          // is this a rest?
        //Serial.println( "rest melody");
        delay(duration);            // then pause for a moment
      else                          // otherwise, play the note
        //Serial.println( "play note melody");
        //Serial.println( duration );
        tone(speakerPin, frequency(notes[i]), duration);
        delay(duration);            // wait for tone to finish
        noTone( speakerPin );
      delay(tempo/10);              // brief pause between notes

  else if (photoCellReading>threshold && lightOn == true && timesUp == 1)
    for(int k=0;k<3;k++)
     digitalWrite(ledPin1, HIGH);
     digitalWrite(ledPin2, LOW);
     digitalWrite(ledPin1, LOW);
     digitalWrite(ledPin2, HIGH);
 if (photoCellReading<threshold)
   Serial.println ("checking flag ");
   digitalWrite(ledPin2, LOW);
   digitalWrite(ledPin1, LOW);
   int m =((millis()- timeSinceThreshold)/60000);
   if (flag==1){
     Particle.publish("Bathroom usage today:", String(m));
      flag = 0;
 Particle.variable("music",&play, INT );

Click to Expand


The video below shows how the device works. As soon as the light is switched on, both the LEDs indicate occupancy and the music starts playing. If the light is turned on for more than 10 minutes,the red LED inside the bathroom starts blinking and the music stops. When the bathroom light has been switched off, both the LEDs are off and the music stops playing. This also triggers a new entry into the online spreadsheet , which can be seen here:  


I had intended to use internet based music such as Spotify or Pandora as the source of music. However, I couldn't find any sample code or libraries which could help me do this. The Spotify and Soundcloud functionalities available on IFTTT were not suitable for playing songs. In spite of using code that plays a song on this speaker, I find that the music coming from the piezospeaker is more annoying than relaxing. I would like to improve on this feature.

I also faced issues in an initial version of my program which used a while loop and disconnected the device from wifi.  There were initials problems with the speaker as well, which was simply solved by changing its input pin from A0 to A4. This project has helped me understand the Particle Photon platform better and learn about the subtle factors that have to be considered while programming and building circuits for the Photon.

Share this Project


49-713 Designing for the Internet of Things

· 4 members

This course charts the emergence of the now "connected world" to explore the possibilities for future products and connected spaces.


'Are you still in there?' is a time management system for the bathroom. It keeps track of how much time you spend in there, and plays music too! It's especially helpful when you have a busy day ahead and the bathroom is shared.