Advertisement
pleasedontcode

SOC_and_SOH_estimation rev_01

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