Advertisement
pleasedontcode

**System Control** rev_02

Nov 22nd, 2024
218
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: **System Control**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-11-22 15:43:35
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* 20*4 lcd i2c, ds3231 rtc, 3 switches to 3 outputs, */
  21.     /* 1 switch to pump motor with low level and high */
  22.     /* level input controls */
  23. /****** SYSTEM REQUIREMENT 2 *****/
  24.     /* 20*4 lcd i2c,, 3 switches to 3 separate outputs  1 */
  25.     /* manual switch to pump motor with low level "motor */
  26.     /* on" and high level "motor off" input controls, and */
  27.     /* pump motor & 3 separate outputs are contolled by */
  28.     /* timer alarm rtc ds3231 and sms sim 900A gsm modu */
  29. /****** END SYSTEM REQUIREMENTS *****/
  30.  
  31. /* START CODE */
  32.  
  33. /****** DEFINITION OF LIBRARIES *****/
  34. #include <Wire.h>
  35. #include <LiquidCrystal_I2C.h>
  36. #include <RTClib.h>
  37. #include <SoftwareSerial.h>
  38.  
  39. /****** FUNCTION PROTOTYPES *****/
  40. void setup(void);
  41. void loop(void);
  42.  
  43. // Constants for the LCD
  44. #define LCD_ADDRESS 0x27 // I2C address of the LCD
  45. #define LCD_COLUMNS 20
  46. #define LCD_ROWS 4
  47.  
  48. // Pin definitions
  49. const int switch1Pin = 2; // Switch for output 1
  50. const int switch2Pin = 3; // Switch for output 2
  51. const int switch3Pin = 4; // Switch for output 3
  52. const int pumpSwitchPin = 5; // Manual switch for pump motor
  53.  
  54. // Output pins
  55. const int output1Pin = 6; // Output 1
  56. const int output2Pin = 7; // Output 2
  57. const int output3Pin = 8; // Output 3
  58. const int pumpMotorPin = 9; // Pump motor control
  59.  
  60. // Create instances of the libraries
  61. LiquidCrystal_I2C lcd(LCD_ADDRESS, LCD_COLUMNS, LCD_ROWS);
  62. RTC_DS3231 rtc;
  63. SoftwareSerial gsm(10, 11); // RX, TX for GSM module
  64.  
  65. void setup(void)
  66. {
  67.     // Initialize the LCD
  68.     lcd.begin(LCD_COLUMNS, LCD_ROWS);
  69.     lcd.backlight();
  70.     lcd.print("System Init...");
  71.  
  72.     // Initialize the RTC
  73.     if (!rtc.begin()) {
  74.         lcd.print("RTC Error!");
  75.         while (1);
  76.     }
  77.  
  78.     // Set up pin modes
  79.     pinMode(switch1Pin, INPUT);
  80.     pinMode(switch2Pin, INPUT);
  81.     pinMode(switch3Pin, INPUT);
  82.     pinMode(pumpSwitchPin, INPUT);
  83.     pinMode(output1Pin, OUTPUT);
  84.     pinMode(output2Pin, OUTPUT);
  85.     pinMode(output3Pin, OUTPUT);
  86.     pinMode(pumpMotorPin, OUTPUT);
  87.  
  88.     // Initialize GSM module
  89.     gsm.begin(9600);
  90. }
  91.  
  92. void loop(void)
  93. {
  94.     // Read switch states
  95.     bool switch1State = digitalRead(switch1Pin);
  96.     bool switch2State = digitalRead(switch2Pin);
  97.     bool switch3State = digitalRead(switch3Pin);
  98.     bool pumpSwitchState = digitalRead(pumpSwitchPin);
  99.  
  100.     // Control outputs based on switch states
  101.     digitalWrite(output1Pin, switch1State);
  102.     digitalWrite(output2Pin, switch2State);
  103.     digitalWrite(output3Pin, switch3State);
  104.  
  105.     // Control pump motor based on manual switch
  106.     if (pumpSwitchState) {
  107.         digitalWrite(pumpMotorPin, HIGH); // Motor ON
  108.     } else {
  109.         digitalWrite(pumpMotorPin, LOW); // Motor OFF
  110.     }
  111.  
  112.     // Get current time from RTC
  113.     DateTime now = rtc.now();
  114.     lcd.setCursor(0, 1);
  115.     lcd.print(now.year(), DEC);
  116.     lcd.print('/');
  117.     lcd.print(now.month(), DEC);
  118.     lcd.print('/');
  119.     lcd.print(now.day(), DEC);
  120.     lcd.print(" ");
  121.     lcd.print(now.hour(), DEC);
  122.     lcd.print(':');
  123.     lcd.print(now.minute(), DEC);
  124.     lcd.print(':');
  125.     lcd.print(now.second(), DEC);
  126.  
  127.     // Add any additional functionality here (e.g., timer alarms, SMS notifications)
  128.    
  129.     delay(1000); // Update every second
  130. }
  131.  
  132. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement