diff --git a/src/main/main.ino b/src/main/main.ino index 4b564516adf8b6ee302c33b6cce8e264af0dc37f..b67d31a3822aa703bc8326385c5d93961e16fee4 100644 --- a/src/main/main.ino +++ b/src/main/main.ino @@ -1,3 +1,6 @@ +#include <b64.h> +#include <HttpClient.h> + const int ledPin = 2; const int buttonPin = 4; int buttonState = 0; @@ -7,7 +10,10 @@ int soilPower = 7; int statusLED = 0; int buzzer = 9; int buzzerHigh = false; - +int sensorLDR = A1; +int valueLDR = 0; +int res0 = 10.0; + void setup() { // put your setup code here, to run once: Serial.begin(9600); @@ -30,7 +36,7 @@ void loop() { Serial.print("Soil Moisture = "); Serial.println(readSoil()); - if (readSoil() > 60) { + if (readSoil() > 100) { Serial.println("wet soil"); digitalWrite(ledPin, LOW); } else { @@ -40,7 +46,12 @@ void loop() { Serial.println("alarm on"); } -// delay(1000); //​take a reading every second + valueLDR = analogRead(sensorLDR); // read the value from the sensor + Serial.print("cahaya: "); //prints the values coming from the sensor on the screen + float vout0 = valueLDR*0.0048828125; // calculate the voltage + int lux0 = 500/(res0*((5-vout0)/vout0)); // calculate the Lux + Serial.println(lux0); + delay(1000); //​take a reading every second } int readSoil() { @@ -49,6 +60,6 @@ int readSoil() { delay(10); val = analogRead(soilPin); digitalWrite(soilPower, LOW); - return val/1023*100; //send current moisture value + return 1023 - val; //send current moisture value }