Servo controlled by soil moisture

Dependencies:   mbed C12832 Servo

Files at this revision

API Documentation at this revision

Comitter:
tollidal
Date:
Sun Oct 17 10:26:17 2021 +0000
Commit message:
Strawberry Forever Soil Moisture Sensor & Servo

Changed in this revision

C12832.lib Show annotated file Show diff for this revision Revisions of this file
Servo.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832.lib	Sun Oct 17 10:26:17 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/askksa12543/code/C12832/#990d5eec2ef6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Sun Oct 17 10:26:17 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/simon/code/Servo/#36b69a7ced07
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Oct 17 10:26:17 2021 +0000
@@ -0,0 +1,51 @@
+#include "mbed.h"
+#include "Servo.h"
+#include "C12832.h"
+
+C12832 lcd(p5, p7, p6, p8, p11);            //LCD screen
+AnalogIn soil_moisture(p20);                //soil moisture sensor
+Servo myservo(p21);                         //servo
+
+int main()
+{
+
+
+    /*lcd.printf("Servo Calibration Controls:\n");
+    lcd.printf("1,2,3 - Position Servo (full left, middle, full right)\n");
+    lcd.printf("4,5 - Decrease or Increase range\n");*/
+
+    float range = 0.0005;
+    float position = 0.5;
+
+    float moisture_value = 0.0f;
+
+
+    while(1) {
+
+        moisture_value = soil_moisture;                                               //soil moisture value
+        lcd.locate(0,0);                                                               //text location on screen
+        lcd.cls();
+        lcd.printf("Moisture reading is: %2.2f\n", moisture_value);                     //display soil moisture value as a percentage
+        wait(1.0f);
+        //  lcd.printf("Moisture reading is: %2.2f\n", value);
+
+        if (moisture_value > 30&& moisture_value <= 65) {                                 //if soil moisture level is between 30 and 60 moisture level okay
+            lcd.printf("Moisture level okay");
+            position = 0.0;
+        }
+
+        else if (moisture_value <= 30) {                                        //if soil moisture level is below 30, soil is dry
+            position = 1.0;                                             //move servo to open position to water plant
+
+
+        } else {
+            position = 0.0;                                             //if soil moisture is above 65 soil is wet, do not water
+        }
+
+
+
+        lcd.printf("position = %.1f, range = +/-%0.4f\n", position, range);
+        myservo.calibrate(range, 45.0);
+        myservo = position;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Oct 17 10:26:17 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file