Created
January 29, 2021 20:16
-
-
Save alvesoaj/601fc68f00425219a2a819f596e43c86 to your computer and use it in GitHub Desktop.
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
/* | |
* AJ Alves ([email protected]) | |
*/ | |
const int MOISTURE_ANALOGIC_IN = A0; // Arduino's analogic pin | |
const int BOARD_RESOLUTION = 1024; // The analogic board resolution, for example Arduino Uno is 10 bit (from 0 to 1023) | |
const float OPERATIONAL_VOLTAGE = 5.0; // The default Arduino voltage | |
const float MAX_SENSOR_VOLTAGE = 3.0; // The maximum voltage that the sensor can output | |
const float SENSOR_READ_RATIO = OPERATIONAL_VOLTAGE / MAX_SENSOR_VOLTAGE; // The ratio betwent the two voltages | |
void setup() { | |
Serial.begin(9600); // Serial Port setup | |
} | |
void loop() { | |
int moistureAnalogicVal = analogRead(MOISTURE_ANALOGIC_IN) * SENSOR_READ_RATIO; // Read the analogic data and convert it to [0, 1023] range | |
if (moistureAnalogicVal < BOARD_RESOLUTION * 0.1) { | |
Serial.println("It is really dry!"); | |
} else if (moistureAnalogicVal < BOARD_RESOLUTION * 0.33) { | |
Serial.println("It is not wet!"); | |
} else if (moistureAnalogicVal < BOARD_RESOLUTION * 0.66) { | |
Serial.println("It is ok!"); | |
} else if (moistureAnalogicVal < BOARD_RESOLUTION * 0.9) { | |
Serial.println("It is really wet!"); | |
} else { | |
Serial.println("I am about to get drowned!"); | |
} | |
delay(3000); // Wait 3 second | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment