Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Soil Moisture
int soil=0;
int rEye = 10; //define right eye as pin10 on the Arduino
int lEye = 11; //define left eye as pin11 on the Arduino
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
pinMode(rEye, OUTPUT); //set right eye for output
pinMode(lEye, OUTPUT); //set left eye for output
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(rEye, LOW);
digitalWrite(lEye, LOW);
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
sensorValue = constrain(sensorValue, 485, 1023);
// print out the value you read:
//map the value to a percentage
soil = map(sensorValue, 485, 1023, 100, 0);
// print out the soil water percentage you calculated:
digitalWrite(rEye, HIGH);
digitalWrite(rEye, LOW);
digitalWrite(rEye, HIGH);
digitalWrite(lEye, HIGH);
digitalWrite(rEye, LOW);
delay(1000); // delay in between reads for stability
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment