Advertisement
pleasedontcode

Temperature Control rev_01

Mar 16th, 2024
16
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 Control
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-16 08:26:12
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Develop the code in Arduino to interface an LM35 */
  21.     /* temperature sensor (Assume the sensor is connected */
  22.     /* to Arduino Analog pin A0) with an Arduino Uno and */
  23.     /* control the onboard LED based on temperature */
  24.     /* readings:   1.      Interface the LM35 temperature */
  25.     /* sensor */
  26. /****** SYSTEM REQUIREMENT 2 *****/
  27.     /* Develop the code in Arduino to interface an LM35 */
  28.     /* temperature sensor (Assume the sensor is connected */
  29.     /* to Arduino Analog pin A0) with an Arduino Uno and */
  30.     /* control the onboard LED based on temperature */
  31.     /* readings:   1.      Interface the LM35 temperature */
  32.     /* sensor */
  33. /****** END SYSTEM REQUIREMENTS *****/
  34.  
  35. /****** DEFINITION OF LIBRARIES *****/
  36. #include <OneWire.h>    // Library for DallasTemperature
  37. #include <DallasTemperature.h>  // Library for DallasTemperature
  38.  
  39. /****** FUNCTION PROTOTYPES *****/
  40. void setup(void);
  41. void loop(void);
  42.  
  43. /***** DEFINITION OF ANALOG INPUT PIN *****/
  44. const uint8_t LM35_PIN = A0;
  45.  
  46. /****** DEFINITION OF LIBRARY CLASS INSTANCE*****/
  47. OneWire oneWire(LM35_PIN);
  48. DallasTemperature ds18b20(&oneWire);
  49.  
  50. void setup(void)
  51. {
  52.     // put your setup code here, to run once:
  53.     ds18b20.begin();
  54.    
  55.     pinMode(LED_BUILTIN, OUTPUT);
  56. }
  57.  
  58. void loop(void)
  59. {
  60.     // put your main code here, to run repeatedly:
  61.    
  62.     ds18b20.requestTemperatures();
  63.    
  64.     float temperature = ds18b20.getTempCByIndex(0);
  65.    
  66.     // Control the onboard LED based on temperature readings
  67.     if (temperature >= 25.0) {
  68.         digitalWrite(LED_BUILTIN, HIGH);
  69.     } else {
  70.         digitalWrite(LED_BUILTIN, LOW);
  71.     }
  72.    
  73.     delay(1000);
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement