/********* Pleasedontcode.com **********

	Pleasedontcode thanks you for automatic code generation! Enjoy your code!

	- Terms and Conditions:
	You have a non-exclusive, revocable, worldwide, royalty-free license
	for personal and commercial use. Attribution is optional; modifications
	are allowed, but you're responsible for code maintenance. We're not
	liable for any loss or damage. For full terms,
	please visit pleasedontcode.com/termsandconditions.

	- Project: Temperature Logger
	- Source Code compiled for: Arduino Uno
	- Source Code created on: 2024-11-25 11:09:00

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* The project must implement the LM35 sensor for */
	/* continuous temperature monitoring, with readings */
	/* taken from analog pin A0. The setup should include */
	/* necessary error handling for sensor malfunctions. */
/****** END SYSTEM REQUIREMENTS *****/


/* START CODE */

/****** DEFINITION OF LIBRARIES *****/
#include <LM35.h>	//https://github.com/wilmouths/LM35

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/***** DEFINITION OF ANALOG INPUT PINS *****/
const uint8_t temp_LM35_Vout_PIN_A0 = A0;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
LM35 lm35(temp_LM35_Vout_PIN_A0); // Instantiate the LM35 object

void setup(void)
{
	// put your setup code here, to run once:
	pinMode(temp_LM35_Vout_PIN_A0, INPUT);
	Serial.begin(9600); // Initialize serial communication for debugging
}

void loop(void)
{
	// put your main code here, to run repeatedly:
	double temperature = lm35.getTemp(); // Get temperature in Celsius

	// Check for sensor malfunction
	if (temperature < -40 || temperature > 125) { // LM35 range
		Serial.println("Error: Sensor malfunction or out of range.");
	} else {
		Serial.print("Temperature: ");
		Serial.print(temperature);
		Serial.println(" °C");
	}

	delay(1000); // Delay for 1 second before the next reading
}

/* END CODE */