Back to Parent

int tempPin1 = A0;
int tempPin2 = A7;

// Create a variable that will store the temperature value
double temperature = 0.0;

void setup()
{
  // Register a Spark variable here
  Spark.variable("temperature", &temperature, DOUBLE);

  // Connect the temperature sensor to A0 & A7 and configure it
  // to be an input
  pinMode(A0, INPUT);
  pinMode(A7, INPUT);
}

void loop()
{
  int reading = 0;
  double voltage = 0.0;

  // Keep reading the sensor value so when we make an API
  // call to read its value, we have the latest one
  reading = analogRead(A0,A7);

  // The returned value from the Core is going to be in the range from 0 to 4095
  // Calculate the voltage from the sensor reading
  voltage = (reading * 3.3) / 4095;

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

  // write to the appropriate pin
  digitalWrite(A7, state);

  // condition: only if the temperature is 100, the A0 sensor will record the data
  if (A0)state > 35;

  // write to the appropriate pin
  digitalWrite(A0, state);
}
Click to Expand

Content Rating

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

0