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 Control**
- - Source Code NOT compiled for: Arduino Nano
- - Source Code created on: 2024-11-06 12:45:27
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Ek realy Jo float megnetic sensor high ho tab */
- /* realy on rahe or sensor low hone ke 15 second bad */
- /* off ho Jaye or 30 minutes ke baad automatic realy */
- /* on ho jaye uske baad sensor ke according realy */
- /* work kare */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <ESP_AT_WiFiManager.h> //https://github.com/khoih-prog/ESP_AT_WiFiManager
- #include <Arduino_APDS9960.h> //https://github.com/arduino-libraries/Arduino_APDS9960
- #include <Arduino.h> // Required for Arduino functions like pinMode, digitalRead, etc.
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- const int sensorPin = 2; // Sensor pin (digital)
- const int relayPin = 7; // Relay pin
- bool sensorState = false;
- bool relayState = false;
- unsigned long startTime = 0;
- unsigned long relayOffTime = 0;
- void setup(void)
- {
- // put your setup code here, to run once:
- Serial.begin(9600);
- pinMode(sensorPin, INPUT);
- pinMode(relayPin, OUTPUT);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- int sensorValue = digitalRead(sensorPin);
- if (sensorValue == HIGH) { // Sensor value check
- sensorState = true;
- digitalWrite(relayPin, HIGH);
- relayState = true;
- startTime = millis(); // Reset start time when relay is turned on
- Serial.println("Relay On");
- } else {
- sensorState = false;
- if (relayState) {
- if (millis() - startTime > 15000) { // 15 second timer
- digitalWrite(relayPin, LOW);
- relayState = false;
- relayOffTime = millis();
- Serial.println("Relay Off");
- }
- }
- if (!relayState && millis() - relayOffTime > 1800000) { // 30 minute timer
- digitalWrite(relayPin, HIGH);
- relayState = true;
- startTime = millis(); // Reset start time when relay is turned on automatically
- Serial.println("Relay On (Auto)");
- }
- }
- delay(100);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement