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: "Sensor Control"
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-11-26 12:24:05
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* DESIGN & IMPLEMENT A SYSTEM TO ADDRESS ANY */
- /* CHALLENGE IN ANY FIELD OF APPLICATION. THE SYSTEM */
- /* SHOULD INCLUDE AN LCD, A BLUETOOTH MODULE, TWO */
- /* SENSORS & TWO ACTUATORS WITH ONE OF THE SENSORS & */
- /* ACTUATORS BEING MODELLED. */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <LiquidCrystal.h> // Library for LCD
- #include <SoftwareSerial.h> // Library for Bluetooth communication
- #include <DHT.h> // Library for DHT sensor
- #include <Servo.h> // Library for Servo motor
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /****** GLOBAL VARIABLES *****/
- // LCD pins
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // RS, E, D4, D5, D6, D7
- // Bluetooth pins
- SoftwareSerial bluetooth(10, 9); // RX, TX
- // DHT sensor
- #define DHTPIN 7 // Pin where the DHT sensor is connected
- #define DHTTYPE DHT11 // DHT 11
- DHT dht(DHTPIN, DHTTYPE);
- // Servo motor
- Servo myServo; // Create a servo object
- /****** SETUP FUNCTION *****/
- void setup(void)
- {
- // Initialize the LCD
- lcd.begin(16, 2); // Set up the LCD's number of columns and rows
- lcd.print("Initializing...");
- // Initialize Bluetooth
- bluetooth.begin(9600); // Set the baud rate for Bluetooth
- // Initialize DHT sensor
- dht.begin();
- // Attach the servo to pin 8
- myServo.attach(8);
- }
- /****** LOOP FUNCTION *****/
- void loop(void)
- {
- // Read temperature and humidity from DHT sensor
- float h = dht.readHumidity();
- float t = dht.readTemperature();
- // Check if any reads failed and exit early (to try again).
- if (isnan(h) || isnan(t)) {
- lcd.print("Failed to read");
- return;
- }
- // Display temperature and humidity on LCD
- lcd.clear();
- lcd.print("T:");
- lcd.print(t);
- lcd.print("C H:");
- lcd.print(h);
- lcd.print("%");
- // Control the servo based on Bluetooth input
- if (bluetooth.available()) {
- char command = bluetooth.read();
- if (command == '1') {
- myServo.write(90); // Move servo to 90 degrees
- } else if (command == '0') {
- myServo.write(0); // Move servo to 0 degrees
- }
- }
- delay(2000); // Wait for 2 seconds before the next loop
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement