04-18-2020, 12:38 PM
(This post was last modified: 04-19-2020, 12:09 PM by prometheus.)
*
This article was written in Google Translator.
The expression may not be smooth.
*
This can be a lot complicated, but it may not.
I bought some stuff to implement this.
4ch relay
arduino nano
4P 12V relay
usb power:
https://drive.google.com/open?id=1JQa26O...P5Vq53dS_c
This is the wiring diagram.
https://drive.google.com/open?id=1wN0o8r...6Ump2Up-dG
Other than usb power (3), usb power is only a way to make the constant voltage 5V comfortable.
.
.
.
Arduino sketch.
__________________________________________________________
//ACC
void setup() {
Serial.begin(9600);
pinMode(9, INPUT);//acc
pinMode(12, OUTPUT); //Relay1
pinMode(11, OUTPUT); //Relay2
pinMode(13, OUTPUT); //Relay3
pinMode(10, OUTPUT); //Relay4
delay(10000);//Wait 10 second.
//HIgh=Off ,LOW=On
digitalWrite(12, HIGH);
digitalWrite(13, LOW);// Constant power on (main control unit)
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
delay(1000);//Wait 1 second.
digitalWrite(12, LOW); //Raspberry Pi power connection.
digitalWrite(11, LOW); //Main power connection.
delay(1000); //Wait 1 second.
digitalWrite(12, HIGH); //ACC Power Disconnect.
delay(75000); //Delay 75 seconds to complete boot.
}
void loop() {
int off = digitalRead(9); //Acc detection.
Serial.print("off : ");
Serial.println(off);
digitalWrite(10,HIGH);//Relay 4 initialization.
delay(1500); //Check every 1.5 seconds.
if (off == 0){
for (int i=0; i<22; i++){
Serial.print("i : ");
Serial.println(i);
delay(1000);
if (i == 20){
digitalWrite(10,LOW);
delay(1000);
digitalWrite(10,HIGH);
delay(10000);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
int reon = digitalRead(9);
if (reon==1) {
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
delay(300);
digitalWrite(11, LOW);
delay(75000);
}
}
int on = digitalRead(9);
Serial.print("on : ");
Serial.println(on);
if ( on == 1)
break;
}
}
}
_______________________________________________
RPI Python shutdown script.
import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BOARD)
GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)
while True:
print GPIO.input(5)
if (GPIO.input(5) == False):
os.system("sudo shutdown -h now")
break
time.sleep(1)
_____________________________________________
I am not a programmer.
Honestly, Arduino's coding is too embarrassing.
But this is the best I can do.
If ACC is blocked, it will be blocked after time passes.
This article was written in Google Translator.
The expression may not be smooth.
*
This can be a lot complicated, but it may not.
I bought some stuff to implement this.
4ch relay
arduino nano
4P 12V relay
usb power:
https://drive.google.com/open?id=1JQa26O...P5Vq53dS_c
This is the wiring diagram.
https://drive.google.com/open?id=1wN0o8r...6Ump2Up-dG
Other than usb power (3), usb power is only a way to make the constant voltage 5V comfortable.
.
.
.
Arduino sketch.
__________________________________________________________
//ACC
void setup() {
Serial.begin(9600);
pinMode(9, INPUT);//acc
pinMode(12, OUTPUT); //Relay1
pinMode(11, OUTPUT); //Relay2
pinMode(13, OUTPUT); //Relay3
pinMode(10, OUTPUT); //Relay4
delay(10000);//Wait 10 second.
//HIgh=Off ,LOW=On
digitalWrite(12, HIGH);
digitalWrite(13, LOW);// Constant power on (main control unit)
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
delay(1000);//Wait 1 second.
digitalWrite(12, LOW); //Raspberry Pi power connection.
digitalWrite(11, LOW); //Main power connection.
delay(1000); //Wait 1 second.
digitalWrite(12, HIGH); //ACC Power Disconnect.
delay(75000); //Delay 75 seconds to complete boot.
}
void loop() {
int off = digitalRead(9); //Acc detection.
Serial.print("off : ");
Serial.println(off);
digitalWrite(10,HIGH);//Relay 4 initialization.
delay(1500); //Check every 1.5 seconds.
if (off == 0){
for (int i=0; i<22; i++){
Serial.print("i : ");
Serial.println(i);
delay(1000);
if (i == 20){
digitalWrite(10,LOW);
delay(1000);
digitalWrite(10,HIGH);
delay(10000);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
int reon = digitalRead(9);
if (reon==1) {
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
delay(300);
digitalWrite(11, LOW);
delay(75000);
}
}
int on = digitalRead(9);
Serial.print("on : ");
Serial.println(on);
if ( on == 1)
break;
}
}
}
_______________________________________________
RPI Python shutdown script.
import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BOARD)
GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)
while True:
print GPIO.input(5)
if (GPIO.input(5) == False):
os.system("sudo shutdown -h now")
break
time.sleep(1)
_____________________________________________
I am not a programmer.
Honestly, Arduino's coding is too embarrassing.
But this is the best I can do.
If ACC is blocked, it will be blocked after time passes.