Go Down

Topic: Arduino Relay board hacked to control devices in my car (Read 2282 times) previous topic - next topic


Nov 08, 2017, 06:38 pm Last Edit: Nov 08, 2017, 06:46 pm by AsaltedPnut
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:

Code: [Select]
* ===============================================================
      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
   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
     digitalWrite(CH2, LOW);  // 1 second to turn Bluetooth ON
  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
   digitalWrite(CH1, HIGH);  // Power OFF PI
   digitalWrite(CH1, LOW);  // Power OFF PI switch
   digitalWrite(CH2, HIGH);   //Bluetooth OFF
   digitalWrite(CH2, LOW);  // 3 second to turn Bluetooth OFF


Best advice is to NOT power the relay board from the Arduino 5 volt line. Use a separate power source.



I have a 3 amp 5v step down transformer already waiting to go in, the plan is to connect relay module and pi/Bluetooth to the transformer.

Thank you for the good advise, will definitely change over to the stand alone transformer.


You don't need a library. Just use digital write like you did.

If you were to have a library you could look for a timer Lombardy to get rid of the delays. I suspect they will cause issue.

Maybe just use the millis without the library in second thought.


if you plan to control more than 8 devices in the future i would look at the MCP23017, it also has the ability to make what you already have use I2C, which indeed does take a library... the MCP23017 has the ability at max to control 128 (relays) digital I/O on one bus, i have a few custom PCBS that have all 8 chips on them ... very useful..

as for controlling stuff with android take a look at Virtuino, I use it in my smart home, the only app on the entire app store in my opinion that is worth real money and its cheap for what it does, very reliable. It also pretty much writes all the code for you for the arduino.... 

Go Up