Advertisement
pleasedontcode

"Sensors Processing" rev_01

Mar 3rd, 2024
62
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: "Sensors Processing"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-03 17:25:35
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* four ultrasonic sensor, flame sensor, water sensor */
  21. /****** SYSTEM REQUIREMENT 2 *****/
  22.     /* four ultrasonic sensor, flame sensor, water sensor */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Ultrasonic.h>
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31. void updateOutputs(void);
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t HC_SR04_Echo_PIN_D3 = 3;
  35. const uint8_t HC_SR04_Echo_PIN_D5 = 5;
  36. const uint8_t HC_SR08_Echo_PIN_D10 = 10;
  37. const uint8_t HC_SR08_Echo_PIN_D12 = 12;
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t HC_SR04_Trigger_PIN_D2 = 2;
  41. const uint8_t HC_SR08_Trigger_PIN_D6 = 6;
  42. const uint8_t Flame_Sensor_PIN_D4 = 4;
  43. const uint8_t Water_Sensor_PIN_D7 = 7;
  44.  
  45. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  46. /***** used to store raw data *****/
  47. bool HC_SR04_Trigger_PIN_D2_rawData = 0;
  48. bool HC_SR08_Trigger_PIN_D6_rawData = 0;
  49. int Flame_Sensor_rawData = 0;
  50. int Water_Sensor_rawData = 0;
  51.  
  52. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  53. /***** used to store data after characteristic curve transformation *****/
  54. float HC_SR04_Trigger_PIN_D2_phyData = 0.0;
  55. float HC_SR08_Trigger_PIN_D6_phyData = 0.0;
  56. float Flame_Sensor_phyData = 0.0;
  57. float Water_Sensor_phyData = 0.0;
  58.  
  59. /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
  60. Ultrasonic ultrasonic1(HC_SR04_Echo_PIN_D3);
  61. Ultrasonic ultrasonic2(HC_SR04_Echo_PIN_D5);
  62. Ultrasonic ultrasonic3(HC_SR08_Echo_PIN_D10);
  63. Ultrasonic ultrasonic4(HC_SR08_Echo_PIN_D12);
  64.  
  65. void setup() {
  66.   // System initialization
  67.   pinMode(HC_SR04_Echo_PIN_D3, INPUT);
  68.   pinMode(HC_SR04_Echo_PIN_D5, INPUT);
  69.   pinMode(HC_SR08_Echo_PIN_D10, INPUT);
  70.   pinMode(HC_SR08_Echo_PIN_D12, INPUT);
  71.  
  72.   pinMode(HC_SR04_Trigger_PIN_D2, OUTPUT);
  73.   pinMode(HC_SR08_Trigger_PIN_D6, OUTPUT);
  74.   pinMode(Flame_Sensor_PIN_D4, INPUT);
  75.   pinMode(Water_Sensor_PIN_D7, INPUT);
  76.  
  77.   // Setup code here (if needed)
  78. }
  79.  
  80. void loop() {
  81.   // Main code here
  82.  
  83.   // Read data from ultrasonic sensors
  84.   unsigned int distance1 = ultrasonic1.read();
  85.   unsigned int distance2 = ultrasonic2.read();
  86.   unsigned int distance3 = ultrasonic3.read();
  87.   unsigned int distance4 = ultrasonic4.read();
  88.  
  89.   // Read data from Flame and Water sensors
  90.   // Modify this section based on the flame and water sensor requirements
  91.   int flameValue = digitalRead(Flame_Sensor_PIN_D4);
  92.   int waterValue = digitalRead(Water_Sensor_PIN_D7);
  93.  
  94.   // Further processing or decision making based on sensor values
  95.  
  96.   // Update output pins
  97.  
  98.   // Example: If distance1 is greater than a threshold, set HC_SR04_Trigger_PIN_D2_rawData to HIGH
  99.   int threshold = 100; // Set your desired threshold value
  100.   HC_SR04_Trigger_PIN_D2_rawData = (distance1 > threshold) ? HIGH : LOW;
  101.  
  102.   // Example: If distance2 is greater than a different threshold, set HC_SR08_Trigger_PIN_D6_rawData to HIGH
  103.   int differentThreshold = 200; // Set your desired different threshold value
  104.   HC_SR08_Trigger_PIN_D6_rawData = (distance2 > differentThreshold) ? HIGH : LOW;
  105.  
  106.   // Example: Set Flame_Sensor_rawData based on the flame sensor value
  107.   Flame_Sensor_rawData = flameValue;
  108.  
  109.   // Example: Set Water_Sensor_rawData based on the water sensor value
  110.   Water_Sensor_rawData = waterValue;
  111.  
  112.   // Refresh outputs
  113.   updateOutputs();
  114.  
  115.   // Delay if necessary for desired loop time
  116. }
  117.  
  118. void updateOutputs() {
  119.   // Write raw data values to output pins
  120.   digitalWrite(HC_SR04_Trigger_PIN_D2, HC_SR04_Trigger_PIN_D2_rawData);
  121.   digitalWrite(HC_SR08_Trigger_PIN_D6, HC_SR08_Trigger_PIN_D6_rawData);
  122. }
  123.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement