Advertisement
pleasedontcode

SOC_and_SOH_estimation rev_02

Nov 22nd, 2023
64
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: SOC_and_SOH_estimation
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-11-22 18:53:28
  15.     - Source Code generated by: ANTU
  16.  
  17. ********* Pleasedontcode.com **********/
  18.  
  19. /********* User code review feedback **********
  20. #### Feedback 1 ####
  21. - worst code
  22.  
  23. ********* User code review feedback **********/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <DHT.h>
  27.  
  28. /****** SYSTEM REQUIREMENT 1 *****/
  29. /* soc and soh estimation of battery */
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t DHT_PIN = 2;
  37.  
  38. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  39. DHT dht(DHT_PIN, DHT22);
  40.  
  41. void setup(void)
  42. {
  43.   // Initialize serial communication
  44.   Serial.begin(9600);
  45.   Serial.println(F("DHTxx test!"));
  46.  
  47.   // Initialize DHT sensor
  48.   pinMode(DHT_PIN, INPUT_PULLUP);
  49.   dht.begin();
  50. }
  51.  
  52. void loop(void)
  53. {
  54.   // Delay for 2 seconds
  55.   delay(2000);
  56.  
  57.   // Read temperature and humidity from DHT sensor
  58.   float humidity = dht.readHumidity();
  59.   float temperature = dht.readTemperature();
  60.   float temperatureF = dht.readTemperature(true);
  61.  
  62.   // Check if any reading is invalid
  63.   if (isnan(humidity) || isnan(temperature) || isnan(temperatureF))
  64.   {
  65.     Serial.println(F("Failed to read from DHT sensor!"));
  66.     return;
  67.   }
  68.  
  69.   // Compute heat index
  70.   float heatIndexC = dht.computeHeatIndex(temperature, humidity);
  71.   float heatIndexF = dht.computeHeatIndex(temperatureF, humidity, false);
  72.  
  73.   // Print sensor data to serial monitor
  74.   Serial.print(F("Humidity: "));
  75.   Serial.print(humidity);
  76.   Serial.print(F("%  Temperature: "));
  77.   Serial.print(temperature);
  78.   Serial.print(F("°C "));
  79.   Serial.print(temperatureF);
  80.   Serial.print(F("°F  Heat index: "));
  81.   Serial.print(heatIndexC);
  82.   Serial.print(F("°C "));
  83.   Serial.print(heatIndexF);
  84.   Serial.println(F("°F"));
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement