Created
May 5, 2023 21:13
-
-
Save tmthfrg/1394b131ef09dd9510c46108b3fda164 to your computer and use it in GitHub Desktop.
Humidity Soil Sensor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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