Sie sind auf Seite 1von 4

int Buzzer = 6 ; int Kipas_dan_Lampu_merah = 7 ; int Lampu_Hijau = 8 ; #include <LiquidCrystal.

h> LCD driver library bles float tempC = 0; holding Celcius temp (floating for decimal points precision) float tempf = 0; holding Fareghneit temp int tempPin = 0; e Analog input to be 0 (A0) of Arduino board. float samples[8]; d 8 samples for Average temp calculation float maxi = 0,mini = 100; erature variables with initial values. LM35 in simple setup only bove 0. int i; LiquidCrystal lcd(12, 11, 5, 4, 3, 2); e library with the numbers of the interface pins void setup() { Serial.begin(9600); port, sets data rate to 9600 bps lcd.begin(16, 2); D's number of columns and rows: lcd.setCursor(2, 0); r position (column, row) lcd.print("Project Micro"); o LCD lcd.setCursor(2, 1); r position (column,row) lcd.print("Thermometer"); LCD delay(5000); // wait 500ms text lcd.clear(); // clear LCD display play lcd.setCursor(1, 0); r position (column, row) lcd.print(" Ilmu Komputer KOM C " ); t text to LCD lcd.setCursor(1, 1); r position (column, row) lcd.print(" USU "); // include the //declare varia // Variable for // variable for // Declaring th // Array to hol // Max/Min temp measures Temp a

// initialize th

// Opens serial // Set up the LC // Set LCD curso // Print text t // Set LCD curso // Print text to // Delay to read // Clear the dis // Set LCD curso // Prin // Set LCD curso // Print text to LCD

delay(5000);

// Delay to read

text lcd.clear(); pinMode (Buzzer, OUTPUT) ; pinMode (Kipas_dan_Lampu_merah, OUTPUT) ; pinMode (Lampu_Hijau, OUTPUT); }

// Clear LCD

void loop() { Serial.println(""); // Blank line for spacing in the serial monitor Serial.println("status akan memunculkan ke serial monitor."); // Print text to Serial monitor Serial.print(" DATA AKAN SEGERA DI TAMPILKAN."); Serial.println("SABAR BRO!!!!"); // B lank line for spacing in the serial monitor Serial.print("LM35 Raw data: "); // Print text to Serial monitor Serial.println(analogRead(tempPin)); // Displays on se rial monitor the sampled value before conversion to real Temperature reading // Start of calcu lations FOR loop. for(i = 0;i<=7;i++){ // gets 8 samples of temperature samples[i] = ( 4.4 * analogRead(tempPin) * 100.0) / 1024.0; // conversion mat h of LM35 sample to readable temperature and stores result to samples array. // 5v is the supp ly volts of LM35. Change appropriatelly to have correct measurement. My case is 4.4Volts. // If powered fro m USB then use value 4.4v to 4.6v. If power is 7v< to the Arduino then use 4.9v to 5.1v // The voltage is critical for accurate readings Serial.println(samples[i]); // Print samples [i] to sertiual monitor // ( LCD note: li ne 1 is the second row, since counting begins with 0): lcd.setCursor(0, 0); position (column 0, row 0) lcd.print("Suhu Saat Ini : "); CD lcd.setCursor(1, 1); position (column 1, row 1) lcd.print(" Celcius "); LCD lcd.setCursor(12, 1); position (column 12, row 1) lcd.print(samples[i]); Temp sample to LCD tempC = tempC + samples[i]; n for average temperature delay(1000); // Set LCD cursor // Print text to L // Set LCD cursor // Print text to // Set LCD cursor // print current // do the additio // wait 800ms

tempf = (tempC * 9)/ 5 + 32; // Send results to LCD. lcd.setCursor(0, 1); position (column 0, line 1) lcd.print(" Fahrenheit "); LCD lcd.setCursor(12, 1); position (column 12, line 1) lcd.print(tempf); to the LCD

// Set LCD cursor // Print text to // Set LCD cursor // Send the data

delay(1000); // Wait 3 seconds to display the Fahrenheit temp and 3 seconds to display results to LCD screen b efor starting the loop again = 6 seconds. tempC = 0; // Set tempC to 0 so calculations can be done again digitalWrite (Lampu_Hijau, HIGH); if (samples[i] digitalWrite digitalWrite digitalWrite > 31) { (Lampu_Hijau, LOW); (Buzzer, HIGH) ; (Kipas_dan_Lampu_merah, HIGH) ; // Set LCD cursor // Print tex // Set LCD cursor // Print text to // Set LCD cursor // print current // do the additio // wait 800ms

lcd.setCursor(0, 0); position (column 0, row 0) lcd.print(" Suhu Berbahaya!!!! : "); t to LCD lcd.setCursor(1, 1); position (column 1, row 1) lcd.print(" Celcius "); LCD lcd.setCursor(12, 1); position (column 12, row 1) lcd.print(samples[i]); Temp sample to LCD tempC = tempC + samples[i]; n for average temperature delay(2000); tempf = (tempC * 9)/ 5 + 32; // Send results to LCD. lcd.setCursor(0, 1); position (column 0, line 1) lcd.print(" Fahrenheit "); LCD lcd.setCursor(12, 1); position (column 12, line 1) lcd.print(tempf); to the LCD

// Set LCD cursor // Print text to // Set LCD cursor // Send the data

delay(2000); // Wait 3 seconds to display the Fahrenheit temp and 3 seconds to display results to LCD screen b efor starting the loop again = 6 seconds. tempC = 0; // Set tempC to 0 so calculations can be done again } else {

digitalWrite (Buzzer, LOW) ; digitalWrite (Kipas_dan_Lampu_merah, LOW); digitalWrite (Lampu_Hijau, HIGH); lcd.clear (); } } Serial.println(" Kelompok Microprocessor "); // Blank line for spacing in the serial monitor Serial.println(" Ilmu Komputer USU "); // Blank line for spacing in the serial monitor tempC = tempC/8.0; averare of 8 samples in Celcius tempf = (tempC * 9)/ 5 + 32; hrenheit if(tempC > maxi) {maxi = tempC;} ature if(tempC < mini) {mini = tempC;} ature o Serial Monitor Serial.println("New measurement:"); Serial.print(" Average Temperature in Celcius is " ); Serial monitor Serial.println(tempC);//send the data to the computer to the computer Serial.print(" Average Temperature in Farenait is " ); Serial monitor Serial.println(tempf);//send the data to the computer to the computer Serial.print(" MAX Temperature in Celcius is " ); Serial monitor Serial.println(maxi);//send the data to the computer to the computer Serial.print(" MIN Temperature in Celcius is " ); Serial monitor Serial.println(mini);//send the data to the computer to the computer }

// calculated the // converts to fa // set max temper // set min temper // Send Results t // Print text to // Send the data // Print text to // Send the data // Print text to // Send the data // Print text to // Send the data

Das könnte Ihnen auch gefallen