Skip to content

Design an Automatic Power on OFF system using Arduino Uno and Relay module #71

Open

Description

@cksajil
  1. Connect rain sensor and relay module to the Arduino Uno board
  2. Sample Arduino script would look like the following

Activity

  1. cksajil commented on Jun 13, 2024

    @cksajil
    OwnerAuthor
    const int relayPin = 3;       // Pin connected to the relay module
    
    void setup() {
      pinMode(rainSensorPin, INPUT);
      pinMode(relayPin, OUTPUT);
      digitalWrite(relayPin, LOW); // Ensure the relay is initially off
    }
    
    void loop() {
      int sensorValue = digitalRead(rainSensorPin);
      
      if (sensorValue == LOW) { // Rain detected
        digitalWrite(relayPin, HIGH); // Turn on relay (and thus the Raspberry Pi)
      } else {
        // Add delay functionality so that the Pi turns off itself based on inference values after some time
        digitalWrite(relayPin, LOW); // Turn off relay (and thus the Raspberry Pi)
      }
    
      delay(1000); // Check every second
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions