Advertisement
pleasedontcode

Temperature Filtering rev_03

Dec 15th, 2023
75
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: Temperature Filtering
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-15 11:22:04
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* GENERATRE LOW PASS FILTER TECHNIQUE USING ARDUINO */
  21. /****** SYSTEM REQUIREMENT 2 *****/
  22.     /* generatae the 100 sample using temperatre sensor */
  23.     /* collect in an array use low pass filter formula to */
  24.     /* get the code */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Arduino.h>
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /****** SYSTEM REQUIREMENTS *****/
  35. /****** SYSTEM REQUIREMENT 1 *****/
  36.   /* GENERATE LOW PASS FILTER TECHNIQUE USING ARDUINO */
  37.  
  38. /****** SYSTEM REQUIREMENT 2 *****/
  39.   /* GENERATE 100 SAMPLES USING TEMPERATURE SENSOR */
  40.   /* COLLECT IN AN ARRAY AND USE LOW PASS FILTER FORMULA TO */
  41.   /* GET THE FILTERED VALUE */
  42.  
  43. /****** END SYSTEM REQUIREMENTS *****/
  44.  
  45. /***** DEFINITION OF ANALOG INPUT PINS *****/
  46. const uint8_t LOW_PASS_PIN_A0 = A0;
  47.  
  48. /***** GLOBAL VARIABLES *****/
  49. const int SAMPLE_SIZE = 100; // Number of samples to collect
  50. int samples[SAMPLE_SIZE]; // Array to store the collected samples
  51.  
  52. void setup(void)
  53. {
  54.   // put your setup code here, to run once:
  55.   pinMode(LOW_PASS_PIN_A0, INPUT);
  56.  
  57.   Serial.begin(9600); // Initialize serial communication
  58.  
  59.   // Collect samples from temperature sensor
  60.   for (int i = 0; i < SAMPLE_SIZE; i++)
  61.   {
  62.     samples[i] = analogRead(LOW_PASS_PIN_A0);
  63.     delay(10); // Delay between each sample collection
  64.   }
  65. }
  66.  
  67. void loop(void)
  68. {
  69.   // put your main code here, to run repeatedly:
  70.  
  71.   // Apply low pass filter to the collected samples
  72.   int filteredValue = 0;
  73.   for (int i = 0; i < SAMPLE_SIZE; i++)
  74.   {
  75.     filteredValue += samples[i];
  76.   }
  77.   filteredValue /= SAMPLE_SIZE;
  78.  
  79.   Serial.print("Filtered Value: ");
  80.   Serial.println(filteredValue);
  81.  
  82.   delay(1000); // Delay between each iteration
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement