Back to Parent

// system that will sense when my head has lifted off of my pillow, check the bathroom for
// a temperature reading, and turn the heater on if it's below 65 degrees F

// define which pins I'm going to use here
int pillowPin = A0;
int pillowReading = 0;
int ledPin = D0;
int tempPin = A1;

//and the starting temps for the temperature sensor
double temperature = 0.0;
double temperatureF = 0.0;

void setup ()
{
  pinMode (ledPin, OUTPUT);
  pinMode (tempPin, INPUT);
  pinMode (pillowPin, INPUT);

//libraries to use
  Spark.variable("force", &pillowReading, INT);
  Spark.variable("temperature", &temperature, DOUBLE);
  Spark.variable("temperatureF", &temperatureF, DOUBLE);
}

void loop ()
  {
    //has to check the bathroom over and over
    bathroomtemp();
  }

void blinkLED()
  {
    digitalWrite(ledPin, HIGH);
    delay (1000);
    digitalWrite(ledPin, LOW);
    delay (1000);
  }

void bathroomtemp()
  {
    //Read the PILLOW SENSOR
    //read pressure sensor, low pressure turns on bathroom temperature sensor
    pillowReading = analogRead(pillowPin);

    //BATHROOM TEMP SENSOR
    //bathroom heater only turns on if bathroom is below 65 degrees Fahrenheit
    int reading = analogRead(tempPin);
        //this calculates the voltage from the sensor reading
        double voltage = (reading * 3.3 / 4095.0);

        //then calculate the temperature and update the static variable
        temperature = (voltage - 0.5) * 100;

        //then this converts the temp to Fahrenheit
        temperatureF = ((temperature * 9.0) / 5.0) + 32.0;

    if( temperatureF < 85 && pillowReading < 500 ){
      // turn on the heater
      blinkLED();
    }
    else{
      // leave the heater off
      digitalWrite(ledPin, LOW);
    }
  }
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0