Phase Change Lab Code

/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); if(temp <= 80.00) { digitalWrite(greenBulb, HIGH); digitalWrite(yellowBulb, LOW); digitalWrite(redBulb, LOW); digitalWrite(BuzzerPin, LOW); } else if ((temp >= 80.01)&&(temp <=89.99)) { digitalWrite(greenBulb, LOW); digitalWrite(yellowBulb, HIGH); digitalWrite(redBulb, LOW); digitalWrite(BuzzerPin, LOW); } else if ((temp >= 90.00) && (temp <=99.99)) { digitalWrite(greenBulb, LOW); digitalWrite(yellowBulb, LOW); digitalWrite(redBulb, HIGH); digitalWrite(BuzzerPin, LOW); } else if (temp >= 100.00) { for (int counter = 0; counter <10; counter ++){ digitalWrite(BuzzerPin, HIGH); delay (100); digitalWrite(BuzzerPin, LOW); delay(100); } } }//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.