Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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 Control
- - Source Code compiled for: Arduino Uno
- - Source Code created on: 2024-03-16 08:26:12
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Develop the code in Arduino to interface an LM35 */
- /* temperature sensor (Assume the sensor is connected */
- /* to Arduino Analog pin A0) with an Arduino Uno and */
- /* control the onboard LED based on temperature */
- /* readings: 1. Interface the LM35 temperature */
- /* sensor */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* Develop the code in Arduino to interface an LM35 */
- /* temperature sensor (Assume the sensor is connected */
- /* to Arduino Analog pin A0) with an Arduino Uno and */
- /* control the onboard LED based on temperature */
- /* readings: 1. Interface the LM35 temperature */
- /* sensor */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <OneWire.h> // Library for DallasTemperature
- #include <DallasTemperature.h> // Library for DallasTemperature
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF ANALOG INPUT PIN *****/
- const uint8_t LM35_PIN = A0;
- /****** DEFINITION OF LIBRARY CLASS INSTANCE*****/
- OneWire oneWire(LM35_PIN);
- DallasTemperature ds18b20(&oneWire);
- void setup(void)
- {
- // put your setup code here, to run once:
- ds18b20.begin();
- pinMode(LED_BUILTIN, OUTPUT);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- ds18b20.requestTemperatures();
- float temperature = ds18b20.getTempCByIndex(0);
- // Control the onboard LED based on temperature readings
- if (temperature >= 25.0) {
- digitalWrite(LED_BUILTIN, HIGH);
- } else {
- digitalWrite(LED_BUILTIN, LOW);
- }
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement