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: "Relay Logic"
- - Source Code compiled for: Arduino Nano
- - Source Code created on: 2024-04-04 23:49:01
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Turns Relay on at 8:00 every morning and turn */
- /* itself off after 3min or if the water level goes */
- /* below 10%. */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* Turns the nano RBG light to blue when relay is on */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- /****** FUNCTION PROTOTYPES ******/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- void turnOnRelay(void);
- void turnOffRelay(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Water_Level_PIN_D2 = 2;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t Relay_PIN_D4 = 4;
- const uint8_t RGB_LIGHT_PIN_D7 = 7;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool Relay_PIN_D4_rawData = false;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float Relay_PIN_D4_phyData = 0.0;
- void setup(void)
- {
- // put your setup code here, to run once:
- // Setup digital input pins
- pinMode(Water_Level_PIN_D2, INPUT);
- // Setup digital output pins
- pinMode(Relay_PIN_D4, OUTPUT);
- pinMode(RGB_LIGHT_PIN_D7, OUTPUT);
- // Turn off the relay initially
- turnOffRelay();
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- // Check if it's 8:00 AM
- if (getCurrentHour() == 8 && getCurrentMinute() == 0)
- {
- // Turn on the relay
- turnOnRelay();
- }
- // Check if the water level goes below 10%
- if (readWaterLevel() < 10)
- {
- // Turn off the relay
- turnOffRelay();
- }
- // Turn the nano RGB light to blue when relay is on
- if (Relay_PIN_D4_rawData)
- {
- digitalWrite(RGB_LIGHT_PIN_D7, HIGH); // Turn on the RGB light
- }
- else
- {
- digitalWrite(RGB_LIGHT_PIN_D7, LOW); // Turn off the RGB light
- }
- delay(1000); // Delay for 1 second before checking conditions again
- }
- void updateOutputs(void)
- {
- digitalWrite(Relay_PIN_D4, Relay_PIN_D4_rawData);
- }
- void turnOnRelay(void)
- {
- Relay_PIN_D4_rawData = true;
- updateOutputs();
- }
- void turnOffRelay(void)
- {
- Relay_PIN_D4_rawData = false;
- updateOutputs();
- }
- int getCurrentHour(void)
- {
- // Implement code to get current hour value from the system clock
- // Return the current hour
- return 8; // Stub return value for testing, replace with actual code
- }
- int getCurrentMinute(void)
- {
- // Implement code to get current minute value from the system clock
- // Return the current minute
- return 0; // Stub return value for testing, replace with actual code
- }
- float readWaterLevel(void)
- {
- // Implement code to read the water level from the sensor
- // Return the water level value in percentage
- return 5.0; // Stub return value for testing, replace with actual code
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement