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 compiled for: Arduino Uno
- - Source Code created on: 2024-01-01 11:54:09
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Measures temperature If temperature is greater */
- /* than 27 degrees celsius print "high temp" and turn */
- /* on red LED if temperature is less than 25 */
- /* degrees celsius print "low temp" and turn on blue */
- /* LED create this in a function called water_temp */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- #include <DHT.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void water_temp(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t mydht_DHT22_DOUT_PIN_D2 = 2;
- const uint8_t red_LED_PIN = 3;
- const uint8_t blue_LED_PIN = 4;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- DHT dht(mydht_DHT22_DOUT_PIN_D2, DHT22);
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(mydht_DHT22_DOUT_PIN_D2, INPUT_PULLUP);
- pinMode(red_LED_PIN, OUTPUT);
- pinMode(blue_LED_PIN, OUTPUT);
- dht.begin();
- Serial.begin(9600);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- water_temp();
- delay(2000);
- }
- void water_temp(void)
- {
- float temperature = dht.readTemperature();
- // Check if the temperature reading is valid
- if (isnan(temperature)) {
- Serial.println(F("Failed to read from DHT sensor!"));
- return;
- }
- Serial.print(F("Temperature: "));
- Serial.print(temperature);
- Serial.println(F("°C"));
- // Check if temperature is greater than 27 degrees celsius
- if (temperature > 27) {
- Serial.println(F("High temperature"));
- digitalWrite(red_LED_PIN, HIGH);
- digitalWrite(blue_LED_PIN, LOW);
- }
- // Check if temperature is less than 25 degrees celsius
- else if (temperature < 25) {
- Serial.println(F("Low temperature"));
- digitalWrite(red_LED_PIN, LOW);
- digitalWrite(blue_LED_PIN, HIGH);
- }
- else {
- digitalWrite(red_LED_PIN, LOW);
- digitalWrite(blue_LED_PIN, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement