Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **Temperature Control**
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-02-07 10:24:02
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* turn on a relay on temperature 20 and turn off */
- /* relay with temperature 60 */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* Activate a relay when the temperature reaches 20°C */
- /* and deactivate it at 60°C, ensuring precise */
- /* temperature monitoring and control for optimal */
- /* performance. Utilize compatible temperature */
- /* sensors and relay modules for effective operation. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <DHT.h> // Include the DHT library for temperature and humidity sensor
- #include <Relay.h> // Include the Relay library for controlling the relay
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Define constants
- #define DHTPIN 2 // Pin where the DHT sensor is connected
- #define DHTTYPE DHT11 // Define the type of DHT sensor (DHT11, DHT22, etc.)
- #define RELAY_PIN 3 // Pin where the relay is connected
- // Create instances of the DHT and Relay classes
- DHT dht(DHTPIN, DHTTYPE); // Create a DHT object
- Relay relay(RELAY_PIN, 1); // Create a Relay object with a 1-second period
- void setup(void)
- {
- // Initialize the DHT sensor
- dht.begin();
- // Set the relay mode to automatic
- relay.setRelayMode(relayModeAutomatic);
- }
- void loop(void)
- {
- // Read temperature as Celsius
- float temperature = dht.readTemperature();
- // Check if the reading is successful
- if (isnan(temperature)) {
- // Handle error
- return;
- }
- // Control the relay based on temperature
- if (temperature >= 20 && relay.getRelayPosition() == relayPositionOpen) {
- relay.setRelayPosition(relayPositionClosed); // Activate relay
- } else if (temperature >= 60 && relay.getRelayPosition() == relayPositionClosed) {
- relay.setRelayPosition(relayPositionOpen); // Deactivate relay
- }
- // Call the relay loop to manage relay timing
- relay.loop();
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement