#include #include // Create a OneWire instance to communicate with the DS18B20 temperature sensor OneWire oneWire(10); // Create a DallasTemperature instance to interface with the OneWire bus DallasTemperature sensor(&oneWire); // Define the pin connected to the LED int LED = 5; void setup(void) { // Start serial communication with a baud rate of 9600 Serial.begin(9600); delay(2); // Initialize the DallasTemperature sensor library sensor.begin(); delay(20); // Set the LED pin as an output pin pinMode(LED, OUTPUT); } void loop(void) { // Request temperature readings from the DS18B20 sensor sensor.requestTemperatures(); // Print the temperature in Celsius to the serial monitor Serial.print("Temperature is: "); delay(10); // Read the temperature value in Celsius from the sensor int value = sensor.getTempCByIndex(0); // Print the temperature value to the serial monitor Serial.println(value); // Map the temperature value to LED brightness range (from -127°C to 125°C to 0-255 brightness) int ledbrightness = map(value, -127, 125, 0, 255); // Print the mapped LED brightness value to the serial monitor Serial.println(ledbrightness); // Set the LED brightness based on the mapped temperature value analogWrite(LED, ledbrightness); // Delay for 1 second before taking the next temperature reading delay(1000); }