Advertisement
pleasedontcode

RC_CAR rev_44

Nov 3rd, 2023
105
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: RC_CAR
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2023-11-03 22:28:49
  15.     - Source Code generated by: Francesco Alessandro
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <Servo.h>
  21. #include <DHT.h>
  22.  
  23. /****** SYSTEM REQUIREMENT 1 *****/
  24. /* Potentiometer reads a pressure sensor. If there is */
  25. /* a high pressure, close the first servo. If there */
  26. /* is a low pressure, close the second servo. If there */
  27. /* is no pressure, open both servos. */
  28.  
  29. /****** SYSTEM REQUIREMENT 2 *****/
  30. /* Read temperature and humidity from sensor and */
  31. /* close all servos if temperature is above 40°C or */
  32. /* humidity is lower than 20%. */
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37.  
  38. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  39. const uint8_t sensor_DHT22_DOUT_PIN_D4 = 4;
  40.  
  41. /***** DEFINITION OF ANALOG INPUT PINS *****/
  42. const uint8_t myPot_Potentiometer_Vout_PIN_A0 = A0;
  43.  
  44. /***** DEFINITION OF PWM OUTPUT PINS *****/
  45. const uint8_t servo_Servomotor_PWMSignal_PIN_D3 = 3;
  46. const uint8_t servo2_Servomotor_PWMSignal_PIN_D5 = 5;
  47.  
  48. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  49. Servo servo;
  50. Servo servo2;
  51. DHT dht(sensor_DHT22_DOUT_PIN_D4, DHT22);
  52.  
  53. void setup(void)
  54. {
  55.   // put your setup code here, to run once:
  56.   pinMode(sensor_DHT22_DOUT_PIN_D4, INPUT_PULLUP);
  57.   pinMode(myPot_Potentiometer_Vout_PIN_A0, INPUT);
  58.  
  59.   servo.attach(servo_Servomotor_PWMSignal_PIN_D3);
  60.   servo2.attach(servo2_Servomotor_PWMSignal_PIN_D5);
  61.  
  62.   dht.begin();
  63. }
  64.  
  65. void loop(void)
  66. {
  67.   // Read pressure from potentiometer
  68.   int pressure = analogRead(myPot_Potentiometer_Vout_PIN_A0);
  69.  
  70.   // Close first servo if pressure is high, close second servo if pressure is low, open both servos if pressure is normal
  71.   if (pressure > 800)
  72.   {
  73.     servo.write(180); // Close first servo
  74.     servo2.write(0);  // Open second servo
  75.   }
  76.   else if (pressure < 200)
  77.   {
  78.     servo.write(0);   // Open first servo
  79.     servo2.write(180); // Close second servo
  80.   }
  81.   else
  82.   {
  83.     servo.write(0);   // Open first servo
  84.     servo2.write(0);  // Open second servo
  85.   }
  86.  
  87.   // Read temperature and humidity from DHT sensor
  88.   float temperature = dht.readTemperature();
  89.   float humidity = dht.readHumidity();
  90.  
  91.   // Close all servos if temperature is above 40°C or humidity is lower than 20%
  92.   if (temperature > 40 || humidity < 20)
  93.   {
  94.     servo.write(180); // Close first servo
  95.     servo2.write(180); // Close second servo
  96.   }
  97.  
  98.   delay(1000); // Delay for 1 second before repeating the loop
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement