Created
July 22, 2020 01:03
-
-
Save HectorTorres/1db803f057168bec37bb77dd23a73dca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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