int greenLED = 18; // Pin for the green LED
int redLED = 23; // Pin for the red LED
int tempSensorPin = A5; // Pin for the temperature sensor (analog input)
void setup() {
Serial.begin(115200);
pinMode(greenLED, OUTPUT); // Set the green LED pin as OUTPUT
pinMode(redLED, OUTPUT); // Set the red LED pin as OUTPUT
pinMode(tempSensorPin, INPUT); // Set the temperature sensor pin as INPUT
void loop() {
// Read the analog value from the temperature sensor
int tempReading = analogRead(tempSensorPin);
// Define threshold values for low and high temperature
int lowTempThreshold = 50; // Adjust this value as needed
int highTempThreshold = 200; // Adjust this value as needed
// Check temperature reading and set LED states accordingly
if (tempReading < lowTempThreshold) {
digitalWrite(greenLED, LOW); // Green LED on for low temperature
digitalWrite(redLED, HIGH); // Red LED off
} else if (tempReading > highTempThreshold) {
digitalWrite(greenLED, HIGH); // Green LED off
digitalWrite(redLED, LOW); // Red LED on for high temperature
} else {
digitalWrite(greenLED, HIGH); // Green LED off
digitalWrite(redLED, HIGH); // Red LED off for other cases
}
// Print the temperature reading to the serial monitor
Serial.print("Temperature Reading: ");
Serial.println(tempReading);
delay(500); // Delay before the next reading
}
Loading
ds18b20
ds18b20