/*
Write a program that will solve the following task:
If the potentiometer reads a value below 200, the servo motor should be set to a position of 0.
If the potentiometer reads a value from 200 to 400, the servo motor should be set to a 45.
If the potentiometer reads a value from 400 to 600, the servo motor should be set to a 90.
If the potentiometer reads a value from 600 to 800, the servo motor should be set to a 135.
If the potentiometer reads a value of 800 or above, the servo motor should be set to a 180.
*/
#include <Servo.h>
Servo s1;
int sensordata=0;
int sensor=A1;
int led=3;
void setup()
{
s1.attach(11);
pinMode(sensor, INPUT);
}
void loop()
{
sensordata=analogRead(sensor);
analogWrite(led,sensordata);
if(sensordata<=200)
{
s1.write(0);
}
else if (sensordata>=200 && sensordata<=400)
{
s1.write(45);
}
else if (sensordata>=400 && sensordata<=600)
{
s1.write(90);
}
else if (sensordata>=600 && sensordata<=800)
{
s1.write(135);
}
else if (sensordata>=800)
{
s1.write(180);
}
}