Advertisement
pleasedontcode

Distance Measurement rev_01

Oct 22nd, 2024
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Distance Measurement
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-10-22 07:26:42
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* design a circuit for pothole detection system */
  21.     /* using ESP32-CAM,ultrasonic sensor, GPRS, FT232RL */
  22.     /* FTDI USB to TTL Serial Converter 40Pin Jumper */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Ultrasonic.h> // https://github.com/ErickSimoes/Ultrasonic
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t HC_SR04_ultrasonice_HC-SR04_Echo_PIN_D13 = 13; // Echo pin for the ultrasonic sensor
  34. const uint8_t HC_SR04_ultrasonice_HC-SR04_Trig_PIN_D12 = 12; // Trigger pin for the ultrasonic sensor
  35.  
  36. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  37. // Instantiate the Ultrasonic object with the trigger and echo pins
  38. Ultrasonic ultrasonic(HC_SR04_ultrasonice_HC-SR04_Trig_PIN_D12, HC_SR04_ultrasonice_HC-SR04_Echo_PIN_D13);
  39.  
  40. void setup(void)
  41. {
  42.     // Initialize serial communication for debugging
  43.     Serial.begin(9600);
  44.    
  45.     // Set the echo pin as input
  46.     pinMode(HC_SR04_ultrasonice_HC-SR04_Echo_PIN_D13, INPUT);
  47.    
  48.     // Set a timeout for the ultrasonic sensor
  49.     ultrasonic.setTimeout(40000UL); // Set timeout to 40ms
  50. }
  51.  
  52. void loop(void)
  53. {
  54.     // Read the distance from the ultrasonic sensor
  55.     Serial.print("Distance in CM: ");
  56.     Serial.println(ultrasonic.read()); // Print the distance in centimeters
  57.     delay(1000); // Wait for 1 second before the next reading
  58. }
  59.  
  60. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement