You are on page 1of 2

#include <Servo.

h>

Servo myservo;

int analogInPin = A0; // Analog input pin that the potentiometer is attached to

int buzz = 2;

int out =13;

int pos = 0;

int sensorValue = 0; // value read from the pot

void setup() {

// initialize serial communications at 9600 bps:

myservo.attach(9);

Serial.begin(9600);

pinMode(out, OUTPUT);

pinMode(buzz, OUTPUT);

void loop() {

// read the analog in value:

sensorValue = analogRead(analogInPin);

Serial.print("sensor = " );

Serial.println(sensorValue);

delay(200);
if(sensorValue<800)

digitalWrite(buzz,HIGH);

myservo.write(0);

if (sensorValue<500){

digitalWrite(buzz,HIGH);

myservo.write(180);

if (sensorValue>800){

digitalWrite(buzz,LOW);

myservo.write(0);

You might also like