Advertisement
safwan092

Untitled

Feb 25th, 2023
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3. float RT = 100000;// the potentiometer value
  4. float R;// the unknow R value
  5. const int TEMP_THRESHOLD_UPPER = 30; // upper threshold of temperature
  6. int sensorValue ;
  7.  
  8. const int SENSOR_PIN = 2; // Arduino pin connected to DS18B20 sensor's DQ pin
  9. const int RELAY_PIN = 9; // Arduino pin connected to relay which connected to fan
  10. OneWire oneWire(SENSOR_PIN); // setup a oneWire instance
  11. DallasTemperature sensors(&oneWire); // pass oneWire to DallasTemperature library
  12.  
  13. float room_temperature; // temperature in Celsius
  14.  
  15. void setup() {
  16. sensorValue = analogRead(A3);
  17. Serial.begin(9600); // initialize serial
  18. sensors.begin(); // initialize the sensor
  19. pinMode(RELAY_PIN, OUTPUT); // initialize digital pin as an output
  20.  
  21. }
  22.  
  23.  
  24. void loop()
  25. {
  26. sensors.requestTemperatures(); // send the command to get temperatures
  27. room_temperature = sensors.getTempCByIndex(0); // read temperature in Celsius
  28. sensorValue = analogRead(A3);
  29. float voltage = sensorValue * (5 / 1023.0);
  30. R = ( voltage * RT) / 5;
  31. Serial.print("Voltage =");// pritns the text "Voltage =
  32. Serial.print(voltage);
  33. Serial.print("V R=");
  34. Serial.print(R);
  35. Serial.print(" ohms");
  36. Serial.println();
  37. delay(1000);
  38. digitalWrite(RELAY_PIN, LOW);
  39. if (( R <= 100000 ) && (R > 80000) && (room_temperature >= 25 ) && (room_temperature <= 30)) {
  40. Serial.println("A\C Temp is between 25 and 30 and room temp also");
  41. digitalWrite(RELAY_PIN, LOW); // turn off
  42. delay(2000);
  43. }
  44. else if (( R <= 100000 ) && (R > 80000) && (room_temperature > 30 ) && (room_temperature <= 35)) {
  45. digitalWrite(RELAY_PIN, HIGH); // turn on
  46. Serial.println("A\C Temp is between 25 and 30 and room temp is between 31 and 35 so the A\C is broken");
  47. delay(2000);
  48. }
  49. else if ((R == 100000) && (room_temperature == 25)) {
  50. digitalWrite(RELAY_PIN, LOW); // turn off
  51. Serial.println("A\C Temp is 25 and room temp is 25");
  52. }
  53. }
  54.  
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement