Hello there. Im currently working on a project that are using servo motor. I intend to do an automated rain sensing wiper. whenever there is rain, the wiper will be automatically turn on. I managed to make it to work for now. I wonder would it be possible if it is not raining and the wiper is currently moving, i send an order to ask the wiper to stop?
here is an example of the code
#define Grove_Water_Sensor 13 // Attach Water sensor to Arduino Digital Pin 13
#include <Servo.h>
#include <LiquidCrystal.h>
#include <DHT.h>
#include "DHT.h"
#define DHTPIN A0 // what pin we're connected to
#define DHTTYPE DHT11 // we are using the DHT11 sensor
Servo myservo;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
DHT dht(DHTPIN, DHTTYPE);
int pos = 0; // variable to store the servo position
void setup() {
pinMode(Grove_Water_Sensor, INPUT); // The Water Sensor is an Input
myservo.attach(3);
Serial.begin(9600);
for (int DigitalPin = 7; DigitalPin <= 9; DigitalPin++)
{
pinMode(DigitalPin, OUTPUT);
}
lcd.begin(16,2); //16 by 2 character display
dht.begin();
}
void loop() {
if( digitalRead(Grove_Water_Sensor) == HIGH) {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay(1000);
// Reading temperature or humidity takes about 250 milliseconds!
float h = dht.readHumidity();
float t = dht.readTemperature(); // Read temperature as Celsius (the default)
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(t); //printing temperarture to the LCD display
lcd.print("'C");
lcd.setCursor(0,1);
lcd.print("Humid: ");
lcd.print(h); //printing humidity to the LCD display
lcd.print("%");
}
else {
myservo.detach();
}
}