Back to Parent

const int tempPin = A0;
const int photoCell = A1;
const int ledPinG = D0;
const int ledPinR = D1;
const int photoCellReading = 0;
const int tempPinon = 0;
int lightlevel, high = 0, low = 4095;

double temperature = 0.0;
double temperatureF = 0.0;

void setup()
{
  pinMode(tempPin, INPUT);
  pinMode(ledPinG, OUTPUT);
  pinMode(ledPinR, OUTPUT);
// Register a Spark variable here
Spark.variable("temperature", &temperature, DOUBLE);
Spark.variable("temperatureF", &temperatureF, DOUBLE);
Spark.variable("light", &lightlevel, INT);


}


void loop() {
// Use analogRead to read the photo cell reading
// This gives us a value from 0 to 4095
lightlevel = analogRead(photoCell);

  if (lightlevel < 50)
  {
    // Keep reading the sensor value so when we make an API
  // call to read its value, we have the latest one
  int reading = analogRead(tempPin);
  // The returned value from the Core is going to be in the range from 0 to 4095
  // Calculate the voltage from the sensor reading
  double voltage = (reading * 3.3) / 4095.0;
  // Calculate the temperature and update our static variable
  temperature = (voltage - 0.25) * 100;
  // Now convert to Farenheight
  temperatureF = ((temperature * 9.0) / 5.0) + 32.0;

  // -----------------
  // Read temperature
  // -----------------
  // Define the Pin the Temperature sensor is on
  // Create a cloud variable of type integer
  // called 'light' mapped to photoCellReading
  if (temperature < 37)
    {digitalWrite(ledPinG, HIGH);
      delay (5000);
    digitalWrite(ledPinG, LOW); }
  if (temperature > 37)
    {digitalWrite(ledPinR, HIGH);
      digitalWrite(ledPinG,LOW);
      delay (5000);
      digitalWrite(ledPinR, LOW);
      }
  }
Click to Expand

Content Rating

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

0