Hi Guys
I have been trying this by myself for a while, but seems I get nowhere.
I am trying to get my arduino relay board to control my bluetooth / lights / radio / PI / etc in my car.
I am having issues with the coding part of it, I have a basic knowledge of JAVA but having code interface with the real world is all new to me.
I have not found a proper library for the 8ch relay board so have had to improvise...
Has anyone got any coding advise for me?
Here is my code so far:
* ===============================================================
Project: 8 Channel 5V Relay Module
Author: Nathan v.N
Created: 5th August 2017
Arduino IDE: 1.0.5
Website: http://arduinobasics.blogspot.com.au
================================================================== */
/*
Connect 5V on Arduino to VCC on Relay Module
Connect GND on Arduino to GND on Relay Module
Connect GND on Arduino to the Common Terminal (middle terminal) on Relay Module. */
int maxnum = 1000; //max before reset
int count = 0;
int mini = -1;
int CH1 = 1; // Connect Digital Pin 1 | PI
int CH2 = 2; // Connect Digital Pin 2 | Bluetooth
int CH3 = 3; // Connect Digital Pin 3 | Head Lights Delay
int CH4 = 4; // Connect Digital Pin 4 | Cab lights?
int CH5 = 5; // Connect Digital Pin 5 | Radio
int CH6 = 6; // Connect Digital Pin 6 |
int CH7 = 7; // Connect Digital Pin 7 |
int CH8 = 8; // Connect Digital Pin 8 |
int Ignition = 9: // Connect Digital Pin 9 | Ignition sense
void setup(){
//Setup all the Arduino Pins
pinMode(CH1, OUTPUT);
pinMode(CH2, OUTPUT);
pinMode(CH3, OUTPUT);
pinMode(CH4, OUTPUT);
pinMode(CH5, OUTPUT);
pinMode(CH6, OUTPUT);
pinMode(CH7, OUTPUT);
pinMode(CH8, OUTPUT);
pinMode(Ignition, INPUT);
//Turn OFF any power to the Relay channels
digitalWrite(CH1,LOW);
digitalWrite(CH2,LOW);
digitalWrite(CH3,LOW);
digitalWrite(CH4,LOW);
digitalWrite(CH5,LOW);
digitalWrite(CH6,LOW);
digitalWrite(CH7,LOW);
digitalWrite(CH8,LOW);
delay(5000); //Wait 5 seconds before starting sequence
}
void loop(){
if (Ignition = HIGH) {
count++; // add one (1) to our count
}
if (count < maxnum) { // keep relays engadged till ignition is turned off
digitalWrite(CH2, HIGH); //Bluetooth ON
delay(1000);
digitalWrite(CH2, LOW); // 1 second to turn Bluetooth ON
digitalWrite(CH3,LOW);
digitalWrite(CH4,LOW);
digitalWrite(CH5,LOW);
digitalWrite(CH6,LOW);
digitalWrite(CH7,LOW);
digitalWrite(CH8,LOW);
}
if (count = maxnum) { // reset count if ignition is still turned on
count = 1; // set count to 1 again
}
if (Ignition = LOW) {
count = -1;
}
if (count = mini) { // turn relays off when ignition turns off
delay(5000);
digitalWrite(CH1, HIGH); // Power OFF PI
delay(1000);
digitalWrite(CH1, LOW); // Power OFF PI switch
digitalWrite(CH2, HIGH); //Bluetooth OFF
delay(3000);
digitalWrite(CH2, LOW); // 3 second to turn Bluetooth OFF
digitalWrite(CH3,LOW);
digitalWrite(CH4,LOW);
digitalWrite(CH5,LOW);
digitalWrite(CH6,LOW);
digitalWrite(CH7,LOW);
digitalWrite(CH8,LOW);
}
}