MajinGotenks

modul 2 arduino

Jan 20th, 2023
1,200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.30 KB | None | 0 0
  1. #include <DHT.h>
  2.  
  3. int redLed = 4;
  4. int greenLed = 5;
  5. int blueLed = 6;
  6. int yellowLed = 7;
  7. #define DHT11_PIN 12
  8. DHT dht(DHT11_PIN, DHT11);
  9.  
  10. void setup() {
  11.  
  12.   pinMode(redLed, OUTPUT);  
  13.   pinMode(greenLed, OUTPUT);  
  14.   pinMode(blueLed, OUTPUT);  
  15.   pinMode(yellowLed, OUTPUT);
  16.  
  17.   Serial.begin(9600);    
  18.   dht.begin();
  19.   }
  20.  
  21. void loop(){
  22.  
  23.       float humidity = dht.readHumidity();
  24.       float temperature = dht.readTemperature();
  25.      
  26.    
  27.       if (isnan(humidity) || isnan(temperature)) {
  28.         Serial.println("Failed to read from DHT sensor!");
  29.         return;
  30.       }
  31.    
  32.    
  33.       Serial.print(humidity);
  34.       Serial.print(",");
  35.       Serial.println(temperature);
  36.  
  37.   if(Serial.available()){  
  38.  
  39.     char val = Serial.read();
  40.  
  41.     if(val == 'r'){      
  42.       digitalWrite(4, HIGH);
  43.       }
  44.     if(val == 'g'){    
  45.       digitalWrite(5, HIGH);
  46.       }
  47.     if(val == 'b'){      
  48.       digitalWrite(6, HIGH);
  49.       }
  50.     if(val == 'y'){      
  51.       digitalWrite(7, HIGH);
  52.       }
  53.     if(val == 's'){      
  54.       digitalWrite(4, LOW);
  55.       }
  56.     if(val == 'h'){      
  57.       digitalWrite(5, LOW);
  58.       }
  59.     if(val == 'c'){      
  60.       digitalWrite(6, LOW);
  61.       }
  62.     if(val == 'z'){      
  63.       digitalWrite(7, LOW);
  64.       }
  65.  
  66.  
  67.  
  68.       }
  69.     }
Advertisement
Add Comment
Please, Sign In to add comment