Arduino with heat sensor

Arduino with heat sensor

Matthew Oh and 2 OthersEscher Briere
Mason Clish
#include <OneWire.h>#include <DallasTemperature.h>#include <Servo.h>
// Pin configurationsconst int oneWireBus = A0;  // Pin where DS18B20 is connectedconst int servoPin = 12;    // Pin for the servo motor
// Create a OneWire instance to communicate with the DS18B20 sensorOneWire oneWire(oneWireBus);
// Pass our OneWire reference to DallasTemperatureDallasTemperature sensors(&oneWire);
// Create servo objectServo myServo;
// Temperature threshold (in Celsius)const float tempThresholdCelsius = 30.0;  // Temperature in Celsius (corresponds to ~90°F)
void setup() {  // Start serial communication  Serial.begin(9600);
  // Start the Dallas Temperature library  sensors.begin();
  // Attach the servo to the pin  myServo.attach(servoPin);}
void loop() {  // Request temperature readings from the DS18B20  sensors.requestTemperatures();
  // Get temperature in Celsius from the first sensor (assuming only one sensor is connected)  float tempC = sensors.getTempCByIndex(0);
  // Check if the temperature is valid  if (tempC == DEVICE_DISCONNECTED_C) {    Serial.println("Error: Could not read temperature data.");    return;  }
  // Print temperature to Serial Monitor  Serial.print("Temperature: ");  Serial.print(tempC);  Serial.println(" °C");
  // If temperature exceeds the threshold, move servo motors 180 degrees 4 times  if (tempC > tempThresholdCelsius) {    for (int i = 0; i < 4; i++) {      myServo.write(90);  // Move servo to 180 degrees      delay(500);           // Wait for the servo to reach the position      myServo.write(30);    // Move servo back to 0 degrees      delay(500);           // Wait for the servo to reach the position    }  }
  // Wait 1 second before reading the temperature again  delay(1000);}