cksajil / rainfall_monitor

This project done by ICFOSS is an attempt to estimate precipitation using machine learning techniques with sound loudness as an input data. It contains supporting scripts to log sound loudness using acoustic sensors and its corresponding data analysis and machine learning models.
MIT License
2 stars 3 forks source link

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

Open cksajil opened 3 months ago

cksajil commented 3 months ago
  1. Connect rain sensor and relay module to the Arduino Uno board
  2. Sample Arduino script would look like the following
cksajil commented 3 months ago
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
}