Advertisement
Ruslan_nig

les2_3_ard

May 19th, 2022
807
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<NewPing.h>
  2. #define PIN_TRIG 12
  3. #define PIN_ECHO 11
  4. #define MAX_DISTANCE 250
  5. NewPing sonar(PIN_TRIG, PIN_ECHO, MAX_DISTANCE);
  6. void setup() {
  7. Serial.begin(9600);
  8. }
  9.  
  10. void loop() {
  11.   delay(50);
  12.   unsigned int distance = sonar.ping_cm();
  13.   if (Serial.available() > 0 ) {
  14.     String data = Serial.readStringUntil('\n');
  15.     Serial.print("You sent me: ");
  16.     Serial.print(data);
  17.     Serial.println(distance);
  18.   }
  19.  
  20. }
Advertisement
RAW Paste Data Copied
Advertisement