Back to Parent

// Define pins to place components on

int tempPin = A0;
int photoCellPin = A1;
int tempPin2 = A4; //for buzzer from Github
int ledPin = D0;
int photoCellReading = 0;
double temperature = 0.0;
double temperatureF = 0.0;

void setup(){
  //This section below is from the in class learning projects we
  //went over
  Spark.variable("temperatureF", &temperatureF, DOUBLE);
  pinMode(tempPin, INPUT);

  Spark.variable("light", &photoCellReading, INT);
  pinMode(ledPin, OUTPUT);

  Serial.begin(9600); //from Github
  pinMode(A4, OUTPUT);
}

void loop() {
  photoCellReading = analogRead(photoCellPin);
{
  digitalWrite(ledPin, HIGH); //this is from the HelloWorld sketch
  delay(1000); //that we did in class for the LED flashing light
  digitalWrite(ledPin, LOW);
  delay(1000);
}
  if(photoCellReading>1500) {//the point to turn on temperature sensor
    //this next section is from the Instructables tutorial on how to
    //make an Arduino night light and the in class temp sensor projects
    digitalWrite(3, HIGH);
    int reading = analogRead(tempPin);
    double voltage = (reading * 3.3) / 8190.0;
    temperature = (voltage - .05) * 100;
    temperatureF = ((temperature * 9.0) / 5.0) + 32.0;
  }
  else {
    digitalWrite(3, LOW);
}  // wait 1/10th of a second and then loop
  if(photoCellReading>1500) {
    analogWrite(A4, 2000); //this section for the buzzer was
    delay(100); //from Github
    analogWrite(A4, 0);
  }
  else {
    digitalWrite(3, LOW);
  }
  delay(100);
}
Click to Expand

Content Rating

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

0