CPP 231
Ultera sonic code school Guest on 28th October 2023 06:30:06 AM
  1. /*
  2. Hightechrobo learn
  3. by Arianramianpour
  4. */
  5.  
  6. #define trig 9
  7. #define echo 10
  8.  
  9. void setup(){
  10.   pinMode(trig,OUTPUT);
  11.   pinMode(echo,INPUT);
  12.   Serial.begin(9600);
  13. }
  14.  
  15. void loop(){
  16.  
  17.   digitalWrite(trig, LOW);
  18.   delayMicroseconds(2);
  19.   digitalWrite(trig, HIGH);
  20.   delayMicroseconds(10);
  21.   digitalWrite(trig, LOW);
  22.   int duration = pulseIn(echo,HIGH);
  23.   int distance = duration * 0.034/2;
  24.   Serial.println(distance);
  25.  
  26. }

Hightechrobo bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.