My favorite Chair with Reading and Meditation Mode

Allow your chair to adjust the reading light for you as it gets darker outside or as you meditate

Made by Hayley

This product will know when you have sat down in your favorite lounge chair, and then, has two modes: Reading Mode and Meditation Mode. For Reading Mode, based on the outside light available, the system will adjust the lighting by the chair so that you don’t have to get up and turn on a lamp as it gets dark. For Meditation Mode, the lighting will adjust to a pulsating blue-green light. Indication lights will show you what mode you are in, and the relative light level.

Created: January 28th, 2015

0

This product will know when you have sat down in your favorite lounge chair, and then, has two modes: Reading Mode and Meditation Mode. For Reading Mode, based on the outside light available, the system will adjust the lighting by the chair so that you don’t have to get up and turn on a lamp as it gets dark. For Meditation Mode, the lighting will adjust to a pulsating blue-green light. Indication lights will show you what mode you are in, and the relative light level.  (see below for a decision map).

1. Input = Force Sensor.

I used a force sensor to detect someone sitting on the chair to activate it.  Anything over 1000 will turn the light on, otherwise it stays off, though the indicator lights let you know it's active.

2. Input = Switch

A. If the switch is in Meditation Mode (LOW), the RGB light will pulse with the blue-green only (red = LOW).

B. If the switch is in Reading Mode (HIGH), the RGB light will be all on.

3. Input = Photoresistor

The RGB light is now controlled by the photoresistors, which is mapped to shine at the inverse of the light coming in to the photoresistors.  Ie, if the photoresistor is getting the max light, the RGB will be at the minimum level, and if the photoresistor is taking in no light, the RGB will be at the max level.

Finally, both sensor variables were available on the Spark Cloud (screenshot below)

Reflection:

For the pulsing GB light, I did not like a pulse pattern I used on a previous project, so I went looking for a smoother one.  I thought I found it in a sin wave-based function, found here:   https://www.sparkfun.com/tutorials/329

I did use that code, but I am still not happy with the rhythm of the pulse. I want it to feel more like it's breathing, so I will have to work on understanding how I can adjust that code or split it into 2 parts to give me the outcome I'm looking for.

I was, overall, quite happy with the outcome.  I took it to the Intermediate level, and if I were to go further, I believe I could achieve the advanced level challenge.

I also would, as a next-level challenge, add a third case to "Reading Mode" where the lamp would be off if the ambient light was above some level, and then otherwise would map from a mid-level range so that the light never got too dim (which is pointless).  Also, I believe that the lamp being on could cause the photoresistor to detect high light levels and turn off, thus initiating a blinking or pulsating lamp, so I would have to think how to avoid this.

Code used in addition to my own:

*Much from Darragh's tutorials

*Sin wave pulse from  https://www.sparkfun.com/tutorials/329

Tutorial used in addition to Darragh's:

*https://learn.sparkfun.com/tutorials/switch-basics



0
#include<math.h>

// name the pins
int redPin = A6; //Red
int greenPin = A5; //Green
int bluePin = A4; //Blue
int buttonPin = D2; //Switch
int forcePin = A7; //Force Sensor
int photoPin = A0; //Photo Resistor
int ledPin1 = D6; //indicator pin 1
int ledPin2 = D5; //indicator pin 2
int ledPin3 = D4; //indicator pin 3

int redValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int greenValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int blueValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255

int forceValue; //define variable to store force sensor reading
int photoValue; //define variable to store photo sensor reading

int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

// This routine runs only once upon reset
void setup()
{
   Spark.variable("light", &photoValue, INT); //creates online API to read variables
   Spark.variable("force", &forceValue, INT);

   // Configure the pins to be outputs
   pinMode(redPin, OUTPUT);
   pinMode(greenPin, OUTPUT);
   pinMode(bluePin, OUTPUT);
   pinMode(ledPin1, OUTPUT);
   pinMode(ledPin2, OUTPUT);
   pinMode(ledPin3, OUTPUT);

   pinMode(buttonPin, INPUT);
   pinMode(forcePin, INPUT);
   pinMode(photoPin, INPUT);

   // Initialize all the LEDs to be OFF
   analogWrite(redPin, redValue);
   analogWrite(greenPin, greenValue);
   analogWrite(bluePin, blueValue);

   //make the indicator LED's blink once to show the system is on
   digitalWrite(ledPin1, LOW);
   digitalWrite(ledPin2, LOW);
   digitalWrite(ledPin3, LOW);
   delay(500);
   digitalWrite(ledPin1, HIGH);
   digitalWrite(ledPin2, HIGH);
   digitalWrite(ledPin3, HIGH);
   delay(500);
   digitalWrite(ledPin1, LOW);
   digitalWrite(ledPin2, LOW);
   digitalWrite(ledPin3, LOW);
   delay(1500);
}



void loop()
{
  forceValue = analogRead(forcePin); //read from the force sensor
  photoValue = analogRead(photoPin); //read from the photoresistor
  buttonState = digitalRead(buttonPin); // read from the switch



  if (forceValue <500)
  {
    analogWrite(redPin, 255);
    analogWrite(bluePin, 255);
    analogWrite(greenPin, 255);

    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    delay(600);
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, HIGH);
    delay(600);

  }
  else
  {
    if (buttonState == LOW)
    {
      digitalWrite(ledPin1, HIGH);
      digitalWrite(ledPin2, HIGH);
      digitalWrite(ledPin3, HIGH);

      analogWrite(redPin, 255);

      float in, out;

      for (in = 0; in < 6.283; in = in + 0.0001)
        {
          out = sin (in) * 127.5 + 127.5;
          analogWrite(bluePin, out);
          analogWrite(greenPin, out);
        }
      }
      else
      {

    //for the part where the RGB goes up as the photoresistor goes down
        int redValue = map(photoValue,0, 4095, 0, 255);
        int greenValue = map(photoValue,0, 4095, 0, 255);
        int blueValue = map(photoValue,0, 4095, 0, 255);

        analogWrite( redPin, redValue);
        analogWrite( greenPin, greenValue);
        analogWrite( bluePin, blueValue);

        if(photoValue < 2000)
        {
          digitalWrite(ledPin1, HIGH);
          digitalWrite(ledPin2, LOW);
          digitalWrite(ledPin3, LOW);
        }

        else if(photoValue < 3000)
        {
          digitalWrite(ledPin1, HIGH);
          digitalWrite(ledPin2, HIGH);
          digitalWrite(ledPin3, LOW);
        }

        else
        {
          digitalWrite(ledPin1, HIGH);
          digitalWrite(ledPin2, HIGH);
          digitalWrite(ledPin3, HIGH);
        }

      }
  }

}
Click to Expand
0
x
Share this Project


About

This product will know when you have sat down in your favorite lounge chair, and then, has two modes: Reading Mode and Meditation Mode. For Reading Mode, based on the outside light available, the system will adjust the lighting by the chair so that you don’t have to get up and turn on a lamp as it gets dark. For Meditation Mode, the lighting will adjust to a pulsating blue-green light. Indication lights will show you what mode you are in, and the relative light level.