- /*
- Hightechrobo learn
- by Arianramianpour
- */
- #define trig 9
- #define echo 10
- void setup(){
- pinMode(trig,OUTPUT);
- pinMode(echo,INPUT);
- Serial.begin(9600);
- }
- void loop(){
- digitalWrite(trig, LOW);
- delayMicroseconds(2);
- digitalWrite(trig, HIGH);
- delayMicroseconds(10);
- digitalWrite(trig, LOW);
- int duration = pulseIn(echo,HIGH);
- int distance = duration * 0.034/2;
- Serial.println(distance);
- }
Recent Pastes