Advertisement
tmth

Humidity Soil Sensor

Aug 14th, 2020
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // YL-39 + YL-69 humidity sensor
  2. byte humidity_sensor_pin = A1;
  3. byte humidity_sensor_vcc = 6;
  4. int value;
  5.  
  6. void setup() {
  7.   // Init the humidity sensor board
  8.   pinMode(humidity_sensor_vcc, OUTPUT);
  9.   digitalWrite(humidity_sensor_vcc, LOW);
  10.   pinMode(13, OUTPUT);
  11.   // Setup Serial
  12.   while (!Serial);
  13.   delay(1000);
  14.   Serial.begin(9600);
  15. }
  16.  
  17. void loop() {
  18. digitalWrite(humidity_sensor_vcc, HIGH);
  19.   delay(500);
  20.    value = analogRead(humidity_sensor_pin);
  21.   digitalWrite(humidity_sensor_vcc, LOW);
  22.   Serial.println(1023 - value);
  23.   Serial.print("Humidity Level (0-1023): ");
  24. //  Serial.println(read_humidity_sensor());
  25.     if ((1023 - value) < 255) {
  26.     digitalWrite(13, HIGH);
  27.  
  28.   } else {
  29.     digitalWrite(13, LOW);
  30.   }
  31.  
  32.   delay(500);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement