Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tmthfrg/1394b131ef09dd9510c46108b3fda164 to your computer and use it in GitHub Desktop.
Save tmthfrg/1394b131ef09dd9510c46108b3fda164 to your computer and use it in GitHub Desktop.
Humidity Soil Sensor
// YL-39 + YL-69 humidity sensor
byte humidity_sensor_pin = A1;
byte humidity_sensor_vcc = 6;
int value;
void setup() {
// Init the humidity sensor board
pinMode(humidity_sensor_vcc, OUTPUT);
digitalWrite(humidity_sensor_vcc, LOW);
pinMode(13, OUTPUT);
// Setup Serial
while (!Serial);
delay(1000);
Serial.begin(9600);
}
void loop() {
digitalWrite(humidity_sensor_vcc, HIGH);
delay(500);
value = analogRead(humidity_sensor_pin);
digitalWrite(humidity_sensor_vcc, LOW);
Serial.println(1023 - value);
Serial.print("Humidity Level (0-1023): ");
// Serial.println(read_humidity_sensor());
if ((1023 - value) < 255) {
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment