I'm trying to make a machine using sensors and a servo. Everything's perfectly fine but my servo isn't moving. Can anyone tell me why?
#include <LiquidCrystal.h> // includes the LiquidCrystal Library
#include <Servo.h>
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LCD object. Parameters: (rs, enable, d4, d5, d6, d7)
Servo myservo;
const int led = 0;
const int trigPin = 9;
const int echoPin = 10;
long duration;
int distanceCm, distanceInch;
int noteduration = 500;
void setup() {
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
pinMode(trigPin, OUTPUT);
pinMode(led, OUTPUT);
pinMode(echoPin, INPUT);
myservo.attach(11);
myservo.write(0);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm= duration*0.034/2;
distanceInch = duration*0.0133/2;
lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("Put Hand Under "); // Prints string "Distance" on the LCD
delay(10);
lcd.setCursor(0,1);
lcd.print("Arrow ");
delay(10);
if (distanceInch<5)
{
delay(500);
digitalWrite(led, HIGH);
delay(1000);
myservo.write(200);
}
else {
digitalWrite(led, LOW);
myservo.write(0);
}
}