Advertisement
pleasedontcode

**Sensor Initialization** rev_01

Dec 18th, 2024
30
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: **Sensor Initialization**
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2024-12-18 16:22:34
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* This Arduino project integrates three TFMPlus for */
  21.     /* precise distance tracking, DHT for environmental */
  22.     /* monitoring, and XLR8HardwareSerial for optimized */
  23.     /* data transmission, focusing on reliable sensor */
  24.     /* connections and data accuracy. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <TFMPlus.h>    //https://github.com/budryerson/TFMini-Plus
  31. #include <XLR8HardwareSerial.h> //https://github.com/AloriumTechnology/XLR8HardwareSerial
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36.  
  37. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  38. // Define the serial instances for the TFMPlus sensors
  39. XLR8HardwareSerial mySerial1(0, 1, 2, 3, 4, 5); // Example pin numbers, adjust as necessary
  40. XLR8HardwareSerial mySerial2(6, 7, 8, 9, 10, 11); // Example pin numbers, adjust as necessary
  41. XLR8HardwareSerial mySerial3(12, 13, 14, 15, 16, 17); // Example pin numbers, adjust as necessary
  42.  
  43. TFMini tfmini1;
  44. TFMini tfmini2;
  45. TFMini tfmini3;
  46.  
  47. void setup(void)
  48. {
  49.     // Initialize the serial communication
  50.     Serial.begin(9600); // Set bit rate of serial port connecting Arduino with computer
  51.  
  52.     // Initialize the TFMPlus sensors with the defined serial instances
  53.     tfmini1.begin(&mySerial1);  // Set bit rate of serial port connecting LiDAR with Arduino
  54.     tfmini2.begin(&mySerial2);
  55.     tfmini3.begin(&mySerial3);
  56. }
  57.  
  58. void loop(void)
  59. {
  60.     // Take one TF Mini distance measurement
  61.     uint16_t dist1 = tfmini1.getDistance();
  62.     uint16_t strength1 = tfmini1.getRecentSignalStrength();
  63.     uint16_t dist2 = tfmini2.getDistance();
  64.     uint16_t strength2 = tfmini2.getRecentSignalStrength();
  65.     uint16_t dist3 = tfmini3.getDistance();
  66.     uint16_t strength3 = tfmini3.getRecentSignalStrength();
  67.  
  68.     // Display the measurement
  69.     Serial.print(dist1);
  70.     Serial.print(" cm      strength: ");
  71.     Serial.println(strength1);
  72.     Serial.print(dist2);
  73.     Serial.print(" cm      strength: ");
  74.     Serial.println(strength2);
  75.     Serial.print(dist3);
  76.     Serial.print(" cm      strength: ");
  77.     Serial.println(strength3);
  78.  
  79.     delay(1000);
  80. }
  81.  
  82. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement