Last active
April 28, 2018 11:13
-
-
Save komputronika/cf19cfac24e58b214bfebaf427c27793 to your computer and use it in GitHub Desktop.
Sketch Arduino untuk Auto-off Baterai Menggunakan Relay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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