Advertisement
pleasedontcode

Temperature Sensor rev_04

Nov 25th, 2024
68
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 Sensor
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-11-25 11:07:15
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* The project must implement the LM35 sensor for */
  21.     /* continuous temperature monitoring, with readings */
  22.     /* taken from analog pin A0. The setup should include */
  23.     /* necessary error handling for sensor malfunctions. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <LM35.h>   //https://github.com/wilmouths/LM35
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF ANALOG INPUT PINS *****/
  36. const uint8_t temp_LM35_Vout_PIN_A0 = A0;
  37.  
  38. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  39. LM35 lm35(temp_LM35_Vout_PIN_A0); // Instantiate the LM35 object
  40.  
  41. void setup(void)
  42. {
  43.     // put your setup code here, to run once:
  44.     pinMode(temp_LM35_Vout_PIN_A0, INPUT);
  45.     Serial.begin(9600); // Initialize serial communication for debugging
  46. }
  47.  
  48. void loop(void)
  49. {
  50.     // put your main code here, to run repeatedly:
  51.     double temperature = lm35.getTemp(); // Get temperature in Celsius
  52.  
  53.     // Check for sensor malfunction
  54.     if (temperature < -40 || temperature > 125) { // LM35 range
  55.         Serial.println("Error: Sensor malfunction or out of range.");
  56.     } else {
  57.         Serial.print("Temperature: ");
  58.         Serial.print(temperature);
  59.         Serial.println(" °C");
  60.     }
  61.  
  62.     delay(1000); // Delay for 1 second before the next reading
  63. }
  64.  
  65. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement