Skip to content

Instantly share code, notes, and snippets.

@komputronika
Last active April 28, 2018 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komputronika/cf19cfac24e58b214bfebaf427c27793 to your computer and use it in GitHub Desktop.
Save komputronika/cf19cfac24e58b214bfebaf427c27793 to your computer and use it in GitHub Desktop.
Sketch Arduino untuk Auto-off Baterai Menggunakan Relay
/*
Sketch auto off baterai
menggunakan relay
Author: Komputronika.com
*/
// Definisi
#define PINRELAY 13
#define TIMEOUT 5000
// Variable menyimpan waktu start auto off
unsigned long waktu = 0;
void setup() {
pinMode(PINRELAY, OUTPUT);
digitalWrite(PINRELAY, LOW); // Low = active
// Set start auto off pertama hidup
waktu = millis();
}
void loop() {
// Kalau waktu sekarang sudah lewat timeout, matikan relay
if ( millis() - waktu > TIMEOUT ) {
digitalWrite(PINRELAY, HIGH); // High = non-active
}
/*
Apabila ada penekanan tombol atu interaksi dari pengguna,
maka waktu direset ke posisi sekarang (millis()).
Agar MCU tidak off sebelum waktu yang diinginkan.
Misalnya:
if (digitalRead(10)==HIGH) {
// bla
// bla
waktu = millis();
}
dst.
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment