AUTOMATIC SOAP DISPENSER USING ARDUINO

AUTOMATIC SOAP DISPENSER USING ARDUINO

BUYING LINK TO AMAZON BELOW : 

PROGRAM : 

 #include <Servo.h>

#include <NewPing.h>

int trigPin = 9;

int echoPin = 10;

int maxDist = 100;

NewPing sonar(trigPin, echoPin, maxDist);

Servo myservo;

  

int distance;

int pos = 0;    

int pos1=0;

void setup()

{

  Serial.begin(9600);

  myservo.attach(6);  

  delay(1000);

    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(5);                       // waits 5ms for the servo to reach the position

  }

}



void loop()

{

int distance = sonar.ping_cm();



Serial.print(distance);

Serial.println(" cm");

delay(250);



  if(distance>2 && distance<5 )///////////donot give data

{

  



  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(5);                       // waits 5ms 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(5);                       // waits 5ms for the servo to reach the position

  }

}

  }

Post a Comment

0 Comments