#include <Servo.h>
int servoPin = 9;
int servoPos = 90;
int ldrPin = A0;
Servo servo;
void setup() {
// put your setup code here, to run once:
pinMode(servoPin, OUTPUT); // no require
pinMode(ldrPin, INPUT);
servo.attach(servoPin);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
servo.write(servoPos);
int temp = analogRead(ldrPin);
Serial.print("output :");
Serial.println(temp);
int frequency = map(temp, 8 , 1015, 0 , 180);
servoMov(frequency);
delay(1000);
}
void servoMov(int frequency){
Serial.print("what is the weather");
while(Serial.available()==0)
{
}
String msg = Serial.readString();
if(msg=="sunny\n")
{
servo.write(0);
}
if(msg =="rainny\n")
{
servo.write(90);
}
if(msg=="bad\n")
{
servo.write(180);
}
}