Created
June 14, 2018 06:31
-
-
Save elktros/26c03aca43083a9d9a4dd6f73759f00d to your computer and use it in GitHub Desktop.
Arduino Code for Arduino Radar Project.
This file contains hidden or 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 <Servo.h> | |
const int trigPin = 9; | |
const int echoPin = 10; | |
long duration; | |
int distinCM; | |
Servo radarServo; | |
void setup() | |
{ | |
pinMode(trigPin, OUTPUT); | |
pinMode(echoPin, INPUT); | |
Serial.begin(9600); | |
radarServo.attach(11); | |
} | |
void loop() | |
{ | |
for(int i=0;i<=180;i++) | |
{ | |
radarServo.write(i); | |
delay(50); | |
digitalWrite(trigPin, LOW); | |
delayMicroseconds(2); | |
digitalWrite(trigPin, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(trigPin, LOW); | |
duration = pulseIn(echoPin, HIGH); | |
distinCM = duration*0.034/2; | |
Serial.print(i); | |
Serial.print("*"); | |
Serial.print(distinCM); | |
Serial.print("#"); | |
} | |
for(int i=180;i>=0;i--) | |
{ | |
radarServo.write(i); | |
delay(50); | |
digitalWrite(trigPin, LOW); | |
delayMicroseconds(2); | |
digitalWrite(trigPin, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(trigPin, LOW); | |
duration = pulseIn(echoPin, HIGH); | |
distinCM = duration*0.034/2; | |
Serial.print(i); | |
Serial.print("*"); | |
Serial.print(distinCM); | |
Serial.print("#"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment