Advertisement
pleasedontcode

"Temperature-controlled Servo" rev_01

Feb 15th, 2024
77
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-controlled Servo"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-02-15 17:55:04
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Отрегулируйте положение серводвигателя на контакте */
  21.     /* D3 под углом 90 градусов, когда температура */
  22.     /* DS18B20 обнаруженная датчиком, достигнет 30 */
  23.     /* градусов по Цельсию. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <Servo.h>  //https://github.com/arduino-libraries/Servo
  28. #include <OneWire.h>
  29. #include <DallasTemperature.h>
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void updateOutputs(void);
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t sensor_DS18B20_DQ_PIN_D2 = 2;
  38.  
  39. /***** DEFINITION OF PWM OUTPUT PINS *****/
  40. const uint8_t motor_Servomotor_PWMSignal_PIN_D3 = 3;
  41.  
  42. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  43. /***** used to store raw data *****/
  44. uint8_t motor_Servomotor_PWMSignal_PIN_D3_rawData = 0;
  45.  
  46. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  47. /***** used to store data after characteristic curve transformation *****/
  48. float motor_Servomotor_PWMSignal_PIN_D3_phyData = 0.0;
  49.  
  50. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  51. Servo myservo;
  52. OneWire oneWire(sensor_DS18B20_DQ_PIN_D2);
  53. DallasTemperature sensors(&oneWire);
  54.  
  55. void setup(void)
  56. {
  57.   // put your setup code here, to run once:
  58.  
  59.   pinMode(sensor_DS18B20_DQ_PIN_D2, INPUT);
  60.  
  61.   pinMode(motor_Servomotor_PWMSignal_PIN_D3, OUTPUT);
  62.  
  63.   myservo.attach(motor_Servomotor_PWMSignal_PIN_D3); // Initialize servo
  64.  
  65.   sensors.begin(); // Initialize DS18B20 sensor
  66.  
  67. }
  68.  
  69. void loop(void)
  70. {
  71.   // put your main code here, to run repeatedly:
  72.  
  73.   updateOutputs(); // Refresh output data
  74.  
  75. }
  76.  
  77. void updateOutputs(void)
  78. {
  79.   sensors.requestTemperatures(); // Request temperature from DS18B20 sensor
  80.  
  81.   float temperature = sensors.getTempCByIndex(0); // Read temperature from DS18B20 sensor
  82.  
  83.   if (temperature >= 30) {
  84.     myservo.write(90); // Set servo position to 90 degrees
  85.   } else {
  86.     myservo.write(0); // Set servo position to 0 degrees
  87.   }
  88. }
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement