Advertisement
pleasedontcode

Ultrasonic Measurement rev_01

May 16th, 2024
762
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: Ultrasonic Measurement
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-05-16 13:47:46
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* ball and beam balance with servo motor */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Ultrasonic.h> //https://github.com/ErickSimoes/Ultrasonic
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29. void updateOutputs(void);
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t sensor_HC_SR04_Echo_PIN_D3 = 3;
  33.  
  34. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  35. const uint8_t sensor_HC_SR04_Trigger_PIN_D2 = 2;
  36.  
  37. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  38. /***** used to store raw data *****/
  39. bool sensor_HC_SR04_Trigger_PIN_D2_rawData = 0;
  40.  
  41. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  42. /***** used to store data after characteristic curve transformation *****/
  43. float sensor_HC_SR04_Trigger_PIN_D2_phyData = 0.0;
  44.  
  45. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  46. Ultrasonic ultrasonic(sensor_HC_SR04_Trigger_PIN_D2, sensor_HC_SR04_Echo_PIN_D3);
  47.  
  48. void setup(void)
  49. {
  50.     // put your setup code here, to run once:
  51.     pinMode(sensor_HC_SR04_Echo_PIN_D3, INPUT);
  52.     pinMode(sensor_HC_SR04_Trigger_PIN_D2, OUTPUT);
  53.     ultrasonic.setTimeout(40000UL);
  54.     Serial.begin(9600);
  55. }
  56.  
  57. void loop(void)
  58. {
  59.     // put your main code here, to run repeatedly:
  60.     Serial.print("Distance in CM: ");
  61.     Serial.println(ultrasonic.read());
  62.     delay(1000);
  63. }
  64.  
  65. void updateOutputs()
  66. {
  67.     digitalWrite(sensor_HC_SR04_Trigger_PIN_D2, sensor_HC_SR04_Trigger_PIN_D2_rawData);
  68. }
  69.  
  70. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement