Question: Task: Modify the program to turn on an LED connected to pin 1 3 if the temperature exceeds a certain threshold ( e . g

Task: Modify the program to turn on an LED connected to pin 13 if the temperature exceeds a certain threshold (e.g.,\(25^{\circ}\mathrm{C}\)).
Procedure:
1. Set up the LED using direct register access as done in Part 1.
2. Use a function to turn on the LED if the temperature exceeds the threshold.
Code Example:
```
#include "RHTwh"
#define DHTPIN 7
#define DHTTYPE DHT11
##efine TEMP_THRESHOLD 25.0// Temperature threshold in Celsius
DHT dht{(DHTPIN, DHTTYPE);
// Function to initialige the DHT sensor and pin 13
```
```
ghtweggix(); // Initialize the DHT sensor
DDRB |={( DDB5); //3et pin 13 as output (direct register access)
}
// Function to read temperature and humidity
```
```
* humidity = dhtwreadHuridita(?;
```
```
}
// Function to control LED based on temperature
void GQRtr&lJER{float temperature){
if {temperature > TEMP_THRESHOLD\\\
PORTB |={1\ll PORTB5\; // Turn LED on (direct register access)
//(the easy way would be digitadJxiter{13, HIGH);)
} else {
PORTB &=\cong(1 PORTB5); // Turn LED off
}
}
void setupl){
Seximb_**gin(9600): //3tart serial communication
```
```
}
void loop() &
float temp, hum;
```
```
// Check if any reads failed and exit the loop early
```
```
return:
}
```
```
S9RtratJER{templ: // Control the LED based on the temperature
delay[2000); // Delay for 2 seconds
}
```
Discussion:
- Explore how combining sensor data and register manipulation in a modular program provides flexibility.
- You can experiment with different thresholds and modify the LED behavior.
Task: Modify the program to turn on an LED

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!