/Libraries to be included
#include <OneWire.h>
#include <DallasTemperature.h>
//Declare a variable to notify the Arduino of sensor location
#define tempPin 8
//Declare an object from the OneWire library (class)
OneWire oneWire(tempPin);
//Pass this object to a second library to crunch some numbers
DallasTemperature tempSensor(&oneWire);
//Declare and initialize variables for your LED pins and Buzzer
int redBulb = 2;
int yellowBulb = 3;
int greenBulb = 4;
int BuzzerPin = 5;
void setup() //Anything typed in setup happens once
{
//Initialize (start) the serial port to read results
Serial.begin(9600);
Serial.println("State of Matter Lab");
//Initialize (start) the Temperature measurment library
tempSensor.begin();
//Declare LED variables as being OUTPUT devices
pinMode(redBulb, OUTPUT);
pinMode(yellowBulb, OUTPUT);
pinMode(greenBulb, OUTPUT);
pinMode(BuzzerPin, OUTPUT);
}//end of setup
void loop() //This part of your code runs repeatedly
{
//Call the method in the Dallas Temperature library to read sensor
tempSensor.requestTemperatures();
//Declare a variable that will store the value of the tempSensor
float temp = tempSensor.getTempCByIndex(0);
Serial.print("Temperature is: "); //Print a line to read temperature
Serial.print(temp);
Serial.println(" degrees C");
//Wait for 10 seconds before reading again...1000ms = 1sec
delay(10000);
}//end of code
Use this as a reference in the event you become completely lost during the phase change lab.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.