// Include the libraries we need #include #include #include // Data wire is plugged into port 2 on the Arduino #define ONE_WIRE_BUS PA0 // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); SoftwareSerial mySerial(PA6, PA5); // RX, TX /* The setup function. We only start the sensors here */ void setup(void) { // start serial port // Start up the library sensors.begin(); pinMode(PA7, OUTPUT); pinMode(PA1, OUTPUT); mySerial.begin(4800); } /* Main function, get and show the temperature */ void loop(void) { // call sensors.requestTemperatures() to issue a global temperature // request to all devices on the bus sensors.requestTemperatures(); // Send the command to get temperatures // After we got the temperatures, we can print them here. // We use the function ByIndex, and as an example get the temperature from the first sensor only. float tempC = sensors.getTempCByIndex(0); // Check if reading was successful if (tempC != DEVICE_DISCONNECTED_C) { // Serial.println(tempC); if (tempC < 25.0) { digitalWrite(PA7, !digitalRead(PA7)); digitalWrite(PA1, LOW); //relay Fan off mySerial.println("Temp: " + (String)(tempC)); mySerial.println(" Fan: " + (String)(int)digitalRead(PA1)); } else //>25C { digitalWrite(PA7, HIGH); // LED ON digitalWrite(PA1, HIGH); // relay FAN on mySerial.println("Temp: " + (String)(tempC)); mySerial.println(" Fan: " + (String)(int)digitalRead(PA1)); } } else { // Serial.println("Error: Could not read temperature data"); digitalWrite(PA7, LOW); // LED off digitalWrite(PA1, LOW); //relay Fan off mySerial.println("Error: Could not read temperature data"); } }