Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneWire.h>
- #include <DallasTemperature.h>
- float RT = 100000;// the potentiometer value
- float R;// the unknow R value
- const int TEMP_THRESHOLD_UPPER = 30; // upper threshold of temperature
- int sensorValue ;
- const int SENSOR_PIN = 2; // Arduino pin connected to DS18B20 sensor's DQ pin
- const int RELAY_PIN = 9; // Arduino pin connected to relay which connected to fan
- OneWire oneWire(SENSOR_PIN); // setup a oneWire instance
- DallasTemperature sensors(&oneWire); // pass oneWire to DallasTemperature library
- float room_temperature; // temperature in Celsius
- void setup() {
- sensorValue = analogRead(A3);
- Serial.begin(9600); // initialize serial
- sensors.begin(); // initialize the sensor
- pinMode(RELAY_PIN, OUTPUT); // initialize digital pin as an output
- }
- void loop()
- {
- sensors.requestTemperatures(); // send the command to get temperatures
- room_temperature = sensors.getTempCByIndex(0); // read temperature in Celsius
- sensorValue = analogRead(A3);
- float voltage = sensorValue * (5 / 1023.0);
- R = ( voltage * RT) / 5;
- Serial.print("Voltage =");// pritns the text "Voltage =
- Serial.print(voltage);
- Serial.print("V R=");
- Serial.print(R);
- Serial.print(" ohms");
- Serial.println();
- delay(1000);
- digitalWrite(RELAY_PIN, LOW);
- if (( R <= 100000 ) && (R > 80000) && (room_temperature >= 25 ) && (room_temperature <= 30)) {
- Serial.println("A\C Temp is between 25 and 30 and room temp also");
- digitalWrite(RELAY_PIN, LOW); // turn off
- delay(2000);
- }
- else if (( R <= 100000 ) && (R > 80000) && (room_temperature > 30 ) && (room_temperature <= 35)) {
- digitalWrite(RELAY_PIN, HIGH); // turn on
- Serial.println("A\C Temp is between 25 and 30 and room temp is between 31 and 35 so the A\C is broken");
- delay(2000);
- }
- else if ((R == 100000) && (room_temperature == 25)) {
- digitalWrite(RELAY_PIN, LOW); // turn off
- Serial.println("A\C Temp is 25 and room temp is 25");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement