Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@HectorTorres
Created July 22, 2020 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HectorTorres/1db803f057168bec37bb77dd23a73dca to your computer and use it in GitHub Desktop.
Save HectorTorres/1db803f057168bec37bb77dd23a73dca to your computer and use it in GitHub Desktop.
#include <NewPing.h>
#include <Servo.h>
#define TRIGGER_PIN 13
#define ECHO_PIN 12
#define MAX_DISTANCE 50
#define TimeDelayServo 200
int pos; //Position Servo
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
Servo servo;
void setup() {
servo.attach(11);
}
void loop() {
if (sonar.ping_cm()<=10){
pos=90;
servo.write(pos);
delay(TimeDelayServo);
}
else{
pos=0;
servo.write(pos);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment