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 if the temperature exceeds a certain threshold egcircmathrmC
Procedure:
Set up the LED using direct register access as done in Part
Use a function to turn on the LED if the temperature exceeds the threshold.
Code Example:
#include RHTwh
#define DHTPIN
#define DHTTYPE DHT
##efine TEMPTHRESHOLD Temperature threshold in Celsius
DHT dhtDHTPIN DHTTYPE;
Function to initialige the DHT sensor and pin
ghtweggix; Initialize the DHT sensor
DDRB DDB; et pin as output direct register access
Function to read temperature and humidity
humidity dhtwreadHuridita;
Function to control LED based on temperature
void GQRtr&lJERfloat temperature
if temperature TEMPTHRESHOLD
PORTB ll PORTB; Turn LED on direct register access
the easy way would be digitadJxiter HIGH;
else
PORTB &cong PORTB; Turn LED off
void setupl
Seximbgin: tart serial communication
void loop &
float temp, hum;
Check if any reads failed and exit the loop early
return:
SRtratJERtempl: Control the LED based on the temperature
delay; Delay for 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.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
