Untitled
unknown
plain_text
2 years ago
1.4 kB
7
Indexable
#include <Servo.h> // servo library Servo myservo; int m=0; int n=0; int pos = 0; void setup() { // put your setup code here, to run once: pinMode(A0, INPUT_PULLUP); // Soil Moisture Sensor 1 PIN A0 pinMode(8,OUTPUT); // Relay Module PIN D8 Serial.begin(9600); // Sensor Buart Rate myservo.attach(9); // Servo PIN D9 digitalWrite(8, HIGH); // Relay Normally Hight for OFF condition } void loop() { // put your main code here, to run repeatedly: int m= analogRead(A0); // Soil Moisture Sensor 1 PIN A0 Serial.println(m); delay(10); Serial.println(n); delay(200); if (m>=980) { while(m>-980){ int currentAngle = myservo.read(); if(currentAngle >= 45){ myservo.write(0); } else{ myservo.write(90); } } digitalWrite(8, LOW); // Relay ON delay(1000); } else if(m<=970) { digitalWrite(8, HIGH); // Relay ON } if (n>=980) { myservo.write(0); // tell servo to go to position in variable 'pos' digitalWrite(8, LOW); // Relay ON delay(1000); } else if(n<=970) { digitalWrite(8, HIGH); // Relay OFF } else { digitalWrite(8, HIGH); // Relay OFF } }
Editor is loading...