Power in Flux
Likes Likes:  3
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Arduino 12v Systems VCU

              
   
   
  1. #1
    I should be working! furyphoto's Avatar
    Join Date
    Jan 2012
    Location
    Harrop, BC, Canada
    Posts
    280
    Post Thanks / Like

    My Social Networking

    Add furyphoto on Facebook

    Arduino 12v Systems VCU

    In the generic thread I mentioned a 12v systems Arduino controller I was working on, and had promised to share some details and code. I figured I would start a new thread since there will likely be some questions, and hopefully suggestions to help me along the way.

    This project was started as my "Get your feet wet" Arduino introduction. It was designed to replace most of the wiring on a vintage ICE motorcycle custom build, but will hopefully morph into a full on VCU /BMS for my Electric as I learn and add peripheral hardware and modules of code to the program.

    I call it the sXootONE.

    Here is the prototype:


    It currently consists of an Arduino Pro Mini (blue in the middle) an FTDI USB converter (Red on the left), a Voltage regulator (blue on the right) and an 8 relay breakout board to which everything else is mounted. There is a network cable soldered to 8 inputs on the arduino that will run to the handlebar controls, a network breakout for easily attaching wires from the switches. Main power is attached to the common terminal of one of the relays, jumpered to the Voltage Regulator which has been adjusted to put out exactly 5v to the arduino and the logic side of the relay board. Ground to the boards is from the soldered pin in the bottom left of the Reg. Power to the boards is via red wire in the lower right from the Reg. out to a VCC pin on the Relay Board



    Any new versions will likely use a Arduino Nano which has a built in voltage regulator (up to 20v input vs. 12v for the Pro Mini) and USB converter, which will eliminate a bunch of soldering and fabrication.

    I have added a 12AWG guage 12v buss on the back of the relay board to eliminate having to jumper the 12 volts to the common terminal on each relay


    The FTDI is soldered using bent over pins and double stick taped to the board. The arduino has the 8 network wires soldered to pins 10 through A3 for switch inputs:


    The VCC pin has a wire the runs under the arduino to the power pin on the relay board. The GRD and output pins 2-9 conveniently fit on the header of the Relay Board and so were soldered into place (+ double stick tape).



    The Code is pretty raw at this point and contains a bunch of stuff that may or may not get included in the final version, but it is working

    It uses the Clickbutton Library which can be found here

    You can copy the code and paste it into the Arduino IDE if you want to play with it. You will have to install the Clickbutton Library for it to work

    It also has the non Clickbutton code still included but commented out, although I don't recommend use without Clickbutton, as it de-bounces the switch inputs for more accurate button push readings.

    Code:
    /*
    
                sXoot ONE 
     Motorcycle Virtual Wiring Harness
             2014 Andrew Doran
            http://andrewdoran.com
     
     */
    
    
    
    
    //INCLUDE LIBRARIES:-------------------------------------------------------------
    #include "ClickButton.h"
    
    
    // DEFINE INITIAL FUNCTION STATES: ----------------------------------------------
    boolean runlightsActive = true;
    boolean britesActive = false;
    boolean brakeActive = false;
    boolean leftTurnActive = false;
    boolean rightTurnActive = false;
    boolean hornActive = false;
    boolean startActive = false;
    boolean suspendRunlights = false;
    boolean parkActive = false;
    boolean hazzardActive = false;
    //boolean killActive = false;
    //boolean headlightActive = false;
    
    
    // DEFINE INPUT PINS: -----------------------------------------------------------//
    #define frontCtrlPin A0
    #define britesCtrlPin 10
    #define brakeCtrlPin 11
    #define leftCtrlPin 12
    #define rightCtrlPin A0
    #define hornCtrlPin A1 
    #define startCtrlPin A3
    
    
    // DEFINE CLICKBUTTONS
    
    
    ClickButton britesButton (britesCtrlPin, LOW, CLICKBTN_PULLUP);
    ClickButton brakeButton (brakeCtrlPin, LOW, CLICKBTN_PULLUP);
    ClickButton leftButton (leftCtrlPin, LOW, CLICKBTN_PULLUP);
    ClickButton rightButton (rightCtrlPin, LOW, CLICKBTN_PULLUP);
    ClickButton hornButton (hornCtrlPin, LOW, CLICKBTN_PULLUP);
    ClickButton startButton (startCtrlPin, LOW, CLICKBTN_PULLUP);
    
    
    // DEFINE RELAY PINS: -----------------------------------------------------------
    
    
    #define runlightsPin 2
    #define britesPin 3
    #define brakePin 4
    #define leftTurnPin 5
    #define rightTurnPin 6
    #define hornPin 7
    #define startPin 8
    //#define killPin 9
    //#define headlightPin 
    
    
    // DEFINE INITIAL RELAY STATES FOR TIMED FUNCTIONS: -----------------------------
    int leftLight = HIGH;   
    int rightLight = HIGH;
    
    
    // DEFINE INITIAL MS COUNT FOR FUNCTIONS: ---------------------------------------
    // will store last time LED was updated OR switch debonce
    unsigned long leftTurnMs = 0;
    unsigned long rightTurnMs = 0; 
    unsigned long hazzardMs = 0;
    
    
    unsigned long britesCtrlMs = 0;
    unsigned long brakeCtrlMS = 0;
    unsigned long leftCtrlMS = 0;
    unsigned long rightCtrlMS = 0;
    unsigned long hornCtrlMS = 0;
    unsigned long startCtrlMS = 0;
    
    
    
    
    
    
    
    
    // DEFINE CONSTANT INTERVALS:----------------------------------------------------
    #define turnInterval 500 
    #define hazzardInterval 200
    
    
    
    
    
    
    // SETUP ///////////////////////////////////////////////////////////////////////
    
    
    void setup() {
    
    
    // SET INITIAL RELAY STATES TO AVOID MISFIRES AT STARTUP:------------------------
      digitalWrite (runlightsPin,LOW);
      digitalWrite (britesPin,HIGH);
      digitalWrite (brakePin,HIGH);
      digitalWrite (rightTurnPin, rightLight);
      digitalWrite (leftTurnPin, leftLight);
      digitalWrite (hornPin,HIGH);
      digitalWrite (startPin, HIGH);
      //digitalWrite (killPin, HIGH);
      //digitalWrite (headlightPin,HIGH);
      
    /* / ACTIVATE INPUT BUTTION PULLUPS:----------------------------------------------- 
      digitalWrite (britesCtrlPin, HIGH);
      digitalWrite (brakeCtrlPin, HIGH);
      digitalWrite (leftCtrlPin, HIGH);
      digitalWrite (rightCtrlPin, HIGH);
      digitalWrite (hornCtrlPin, HIGH);
      digitalWrite (startCtrlPin, HIGH);  */
      
    /* // DEFINE INPUT PINS:------------------------------------------------------------
      //pinMode(frontCtrlPin,INPUT);
      pinMode(britesCtrlPin,INPUT_PULLUP);
      pinMode(brakeCtrlPin,INPUT_PULLUP);
      pinMode(leftCtrlPin,INPUT_PULLUP);
      pinMode(rightCtrlPin,INPUT_PULLUP);
      pinMode(hornCtrlPin,INPUT_PULLUP);
      pinMode(startCtrlPin,INPUT_PULLUP);  */
      
    
    
    
    
      // Setup button timers (all in milliseconds / ms)
      // (These are default if not set, but changeable for convenience)
      //button1.debounceTime   = 20;   // Debounce timer in ms
      brakeButton.multiclickTime = 1000;  // Time limit for multi clicks
      startButton.longClickTime  = 1500; // time until "held-down clicks" register
      
    // DEFINE OUTPUT PINS:-----------------------------------------------------------
      pinMode(runlightsPin, OUTPUT);
      pinMode(britesPin, OUTPUT);
      pinMode(brakePin, OUTPUT);
      pinMode(leftTurnPin, OUTPUT);
      pinMode(rightTurnPin, OUTPUT);  
      pinMode(hornPin, OUTPUT);
      pinMode(startPin, OUTPUT);
      //pinMode(killPin, OUTPUT);
      //pinMode(headlightPin, OUTPUT);
    }
    
    
    
    
    // MAIN LOOP ////////////////////////////////////////////////////////////////////
    void loop()
    {
      
    // CHECK CONDITIONS FOR EACH FUNCTION STATE AND CALL APPROPRIATE FUNCTION ////////////////////////
    
    
    readInputSwitches();
    
    
    if (runlightsActive == true && suspendRunlights == false ){ runlightsOn();}
    else{runlightsOff();}
      
    if (britesActive == true){britesOn();}
    else{britesOff();}
      
    if (brakeActive == true){brakeLightsOn();}
    else{brakeLightsOff();}
      
    if (hornActive == true){hornOn();}
    else{hornOff();}
    
    
    if (startActive == true){
      starterOn();
      suspendRunlights = true;
    }
    else{
      starterOff();
      suspendRunlights = false;
    }
      
    if (leftTurnActive == true){
      leftTurnOn();
      rightTurnActive = false;
      parkActive = false;
      hazzardActive = false;
    }
    else if (rightTurnActive == true){
      rightTurnOn();
      leftTurnActive = false;
      parkActive = false;
      hazzardActive = false;
    }
    else if (hazzardActive == true){
      hazzardFlashers();
      leftTurnActive = false;
      rightTurnActive = false;
      parkActive = false;
    }
    else if (parkActive == true){
      parkingLightsOn();
      leftTurnActive = false;
      rightTurnActive = false;
      hazzardActive = false;
    }
    else {blinkersOff();}
    
    
      
      // TEST SEQUENCE TO CHECK FUNCTIONS WITHOUT BUTTONS
    
    
    //leftTurnActive = true;
    
    
    //rightTurnActive = true;
    
    
    //hazzardActive = true;
    
    
    //parkActive = true;
    
    
    //brakeActive = true;
    
    
    //headlightOn();
    
    
    //britesActive = true;
    
    
    //runlightsOff();
    
    
    //hornActive = true;
    
    
    //startActive = true;
    
    
    }
    
    
    
    
    
    
    //FUNCTIONS///////////////////////////////////////////////////////////////////
    
    
    
    
    // READ INPUT SWITCHES
    
    
    void readInputSwitches(){
      
    //WITH CLICKBUTTON
    
    
    britesButton.Update();
    if (britesButton.depressed == true){britesActive = true;}
    else britesActive = false;
    
    
    leftButton.Update();
    
    
    if (leftButton.depressed == true){leftTurnActive = true;}
    else leftTurnActive = false;
    
    
    rightButton.Update();
    if (rightButton.depressed == true){rightTurnActive = true;}
    else rightTurnActive = false;
    
    
    brakeButton.Update();
    if (brakeButton.depressed == true){brakeActive = true;}
    else brakeActive = false;
    
    
    hornButton.Update();
    if (hornButton.depressed == true){hornActive = true;}
    else hornActive = false;
    
    
    startButton.Update();
    if (startButton.depressed == true){startActive = true;}
    else startActive = false;  
      
    /*  WITHOUT CLICKBUTTON
    if (digitalRead (britesCtrlPin) == LOW){britesActive = true;}
    else britesActive = false;
    
    
    if (digitalRead (leftCtrlPin) == LOW){leftTurnActive = true;}
    else leftTurnActive = false;
    
    
    if (digitalRead (rightCtrlPin) == LOW){rightTurnActive = true;}
    else rightTurnActive = false;
    
    
    if (digitalRead (brakeCtrlPin) == LOW){brakeActive = true;}
    else brakeActive = false;
    
    
    if (digitalRead (hornCtrlPin) == LOW){hornActive = true;}
    else hornActive = false;
    
    
    if (digitalRead (startCtrlPin) == LOW){startActive = true;}
    else startActive = false;   */
    
    
    }
    
    
    // RUNNING LIGHTS: --------------------------------------------------------------
    
    
    void runlightsOn(){
      digitalWrite(runlightsPin, LOW);
    }
    
    
    void runlightsOff(){
      digitalWrite(runlightsPin, HIGH);
    }
    
    
    
    
    // HIGHBEAM: -------------------------------------------------------------------
    
    
    void britesOn(){
      digitalWrite(britesPin, LOW);
    }
    
    
    void britesOff(){
      digitalWrite(britesPin, HIGH);
    }
    
    
    
    
    // BRAKE LIGHTS: ---------------------------------------------------------------
    
    
    void brakeLightsOn(){
      digitalWrite(brakePin, LOW);
    }
    
    
    void brakeLightsOff(){
      digitalWrite(brakePin, HIGH);
    }
    
    
    
    
    // LEFT TURN SIGNAL: ---------------------------------------------------------
    
    
    void leftTurnOn(){
      unsigned long currentMs = millis();
      if(currentMs - leftTurnMs >= turnInterval) {
        // save the last time you blinked the LED 
        leftTurnMs = currentMs;   
    
    
        // if the LED is off turn it on and vice-versa:
        if (leftLight == HIGH)
          leftLight = LOW;
        else
          leftLight = HIGH;
    
    
        // set the LED with the ledState of the variable:
        digitalWrite(leftTurnPin, leftLight);
        digitalWrite(rightTurnPin, HIGH);
      }
    }
    
    
    
    
    // RIGHT TURN SIGNAL: ---------------------------------------------------------
    
    
    void rightTurnOn(){
      unsigned long currentMs = millis();
      if(currentMs - rightTurnMs >= turnInterval) {
        // save the last time you blinked the LED 
        rightTurnMs = currentMs;   
    
    
        // if the LED is off turn it on and vice-versa:
        if (rightLight == HIGH)
          rightLight = LOW;
        else
          rightLight = HIGH;
    
    
        // set the LED with the ledState of the variable:
        digitalWrite(rightTurnPin, rightLight);
        digitalWrite(leftTurnPin, HIGH);
      }
    }
    
    
    
    
    // HAZZARD FLASHERS: -----------------------------------------------------------
    
    
    void hazzardFlashers(){
      unsigned long currentMs = millis();
      if(currentMs - hazzardMs >= hazzardInterval) {
        // save the last time you blinked the LED 
        hazzardMs = currentMs;   
    
    
        // if the LED is off turn it on and vice-versa:     
        if (rightLight == HIGH)
          rightLight = LOW;
        else
          rightLight = HIGH;
    
    
        if (leftLight == HIGH)
          leftLight = LOW;
        else
          leftLight = HIGH;
    
    
        // set the LED with the ledState of the variable:
        digitalWrite(rightTurnPin, rightLight);
        digitalWrite(leftTurnPin, leftLight);
      }
    }
    
    
    
    
    // PARKING LIGHTS: -------------------------------------------------------------
    
    
    void parkingLightsOn(){
      digitalWrite(rightTurnPin, LOW);
      digitalWrite(leftTurnPin, LOW);
    }
    
    
    
    
    // BLINKERS OFF: ---------------------------------------------------------------
    
    
    void blinkersOff(){
      digitalWrite(rightTurnPin, HIGH);
      digitalWrite(leftTurnPin, HIGH);
    }
    
    
    
    
    // HORN: ------------------------------------------------------------------------
    
    
    void hornOn(){
      digitalWrite(hornPin, LOW);
    }
    
    
    void hornOff(){
      digitalWrite(hornPin, HIGH);
    }
    
    
    
    
    // STARTER: ---------------------------------------------------------------------
    
    
    void starterOn(){
      digitalWrite(startPin, LOW);
    }
    
    
    void starterOff(){
      digitalWrite(startPin, HIGH);
    }
    
    
    
    
    /* / KILLSWITCH: ------------------------------------------------------------------
    
    
    void killOn(){
      digitalWrite(killPin, LOW);
    }
    
    
    void killOff(){
      digitalWrite(killPin, HIGH);
    }
    */
    
    
    
    
    /* / HEADLIGHT: ------------------------------------------------------------------
    
    
    void headlightOn(){
      digitalWrite(headlightPin, LOW);
    }
    
    
    void headlightOff(){
      digitalWrite(headlightPin, HIGH);
    }
    */
    
    
    
    //  END OF CODE (FOR NOW)
    Currently the program does the following fairly basic things using the relays:
    • Turns on the running lights (headlight and tail light) when ignition comes on
    • Turns on the high beams when the switch in on
    • Turns on the brake light when the switch is activated (front and rear brakes need to be wired in parallel)
    • Flashes the left turn signal when the switch is activated (flasher interval can be adjusted, default 500 miliseconds)
    • Flashes the right turn signal when the switch is activated (flasher interval can be adjusted, default 500 miliseconds)
    • Sounds the horn when button is pushed
    • Triggers the ICE bikes original starter solenoid when the start button is pushed, and suspends all lights while starting to feed all power to the starter


    The connections are pretty simple:

    The controls are attached to the input pins as defined in the code. Each button is connected to the wire from the arduino on one side and ground on the other side. The inputs are "pulled up" which means they are normally reading 5v so shorting the buttons to ground activates the input. This eliminates the need for two wires to the arduino for each button. The switches have to be Normally Open.

    For the outputs, again each device is connected to the Normally Open side of the respective relay and grounded to the frame.

    The goal was to simplify the wiring, one Network buss for the inputs and one 12v wire to each device, eliminating lots of redundant ground wires, and things like a flasher relay.

    Although it doesn't do much that is special right now, once the system is in place, all sorts of options for additional features are in now in play through software updates.
    Some Ideas I have are:
    • Custom turn signal flashing sequence (multiple pulses of different lengths perhaps to the beat of the Imperial Death March)
    • Auto canceling turn signals (either timed, or by distance using a hall sensor and a magnet or both)
    • Auto brake light using a accelerometer to light the lamp anytime the bike is decelerating)
    • Pulsing brake light for added visibility
    • multiple clicks of the brake switch or high beam switch to activate parking lights or hazzard flashers
    • electronic kill switch
    • RFID or Fingerprint Ignition switch instead of a key
    • Auto dimming high beams
    • Head light doesn't light until after the bike is running to save battery
    • custom horn sequence (beep beep ba bee beep) (or Imperial Death March!)


    I'm open to any suggestions too

    So take a look if you are interested, play with it, and contribute if you like.

    Cheers,
    Last edited by furyphoto; 31 October 2016 at 2307.
    -Andrew

    http://www.andrewdoran.com
    mail(at)andrewdoran.com

    My ElMoto Project "Electric Hurricane" - 1987 Honda CBR600 F1: Check out my Build ALBUM
    My ICE Cafe Racer Project "My Precious" - 1983 Honda CM400 Classic

  2. Likes marcexec liked this post
  3. #2
    Senior Member SplinterOz's Avatar
    Join Date
    Aug 2010
    Location
    Canberra, Australia
    Posts
    758
    Post Thanks / Like

    My Social Networking


    Visit SplinterOz's Youtube Channel
    That is cool.. will download and try. Seems to be a reasonable replacement for the m-Unit from Motogadget
    SplinterOz
    From Australia'a Capital
    http://rgelectric.wordpress.com/

  4. #3
    Senior Member
    Join Date
    Aug 2011
    Location
    Eastern Massachuesetts
    Posts
    166
    Post Thanks / Like
    Quote Originally Posted by furyphoto View Post
    [*]Auto canceling turn signals (either timed, or by distance using a hall sensor and a magnet or both)
    Excellent Post!

    How about using a GPS board to cancel turn signals?
    "obstacles suck but challenges are fun"

  5. #4
    Senior Member SplinterOz's Avatar
    Join Date
    Aug 2010
    Location
    Canberra, Australia
    Posts
    758
    Post Thanks / Like

    My Social Networking


    Visit SplinterOz's Youtube Channel
    Btw gotta ask where you got that relay board from.
    SplinterOz
    From Australia'a Capital
    http://rgelectric.wordpress.com/

  6. #5
    I should be working! furyphoto's Avatar
    Join Date
    Jan 2012
    Location
    Harrop, BC, Canada
    Posts
    280
    Post Thanks / Like

    My Social Networking

    Add furyphoto on Facebook
    A poor man's m-unit was the motivation. The parts total about $20. Got the relay board from eBay, about $6. Search "arduino 8 relay" you can get a solid state relay board for about 15 bucks but the SSR'S have a much lower amp limit.
    Last edited by furyphoto; 23 July 2015 at 1016.
    -Andrew

    http://www.andrewdoran.com
    mail(at)andrewdoran.com

    My ElMoto Project "Electric Hurricane" - 1987 Honda CBR600 F1: Check out my Build ALBUM
    My ICE Cafe Racer Project "My Precious" - 1983 Honda CM400 Classic

  7. #6
    Senior Member SplinterOz's Avatar
    Join Date
    Aug 2010
    Location
    Canberra, Australia
    Posts
    758
    Post Thanks / Like

    My Social Networking


    Visit SplinterOz's Youtube Channel
    Quote Originally Posted by furyphoto View Post
    A poor man's m-unit was the motivation. The parts total about $20. Got the relay board from eBay, about $6. Search "arduino 8 relay" you can get a solid state relay board for about 15 bucks but the SSR'S have a much lower amp limit.
    Cool I actually found some advertised and based on your descovery have orded a relay board, Arduino Nano (I have some Uno's and Mega's), and FTDI board for about 30 bucks australian. pretty good.
    I am turning over in my head how you could put the fuse box as part of this arrangement... a main one on the input and a fuse for each relay out.
    SplinterOz
    From Australia'a Capital
    http://rgelectric.wordpress.com/

  8. #7
    Moderator Nuts & Volts's Avatar
    Join Date
    Aug 2010
    Location
    Columbus, OH
    Posts
    1,765
    Post Thanks / Like
    Quote Originally Posted by SplinterOz View Post
    Cool I actually found some advertised and based on your descovery have orded a relay board, Arduino Nano (I have some Uno's and Mega's), and FTDI board for about 30 bucks australian. pretty good.
    I am turning over in my head how you could put the fuse box as part of this arrangement... a main one on the input and a fuse for each relay out.
    Yea the only thing missing for me is the fuses. With those you have a drop in 12V solution. Just add wires.

    This is a cool project.


    Sent from my iPhone using Tapatalk
    Whats under my tank may shock you!!! R6 Build, Blog/, [/URL] OSU Current webpage

  9. Likes Athlon liked this post
  10. #8
    Senior Member
    Join Date
    Nov 2013
    Posts
    112
    Post Thanks / Like
    I want one. Real bad.

  11. #9
    I should be working! furyphoto's Avatar
    Join Date
    Jan 2012
    Location
    Harrop, BC, Canada
    Posts
    280
    Post Thanks / Like

    My Social Networking

    Add furyphoto on Facebook
    Quote Originally Posted by SplinterOz View Post
    Cool I actually found some advertised and based on your descovery have orded a relay board, Arduino Nano (I have some Uno's and Mega's), and FTDI board for about 30 bucks australian. pretty good.
    I am turning over in my head how you could put the fuse box as part of this arrangement... a main one on the input and a fuse for each relay out.
    You shouldn't need the FTDI with a Nano, it has USB support built in.
    -Andrew

    http://www.andrewdoran.com
    mail(at)andrewdoran.com

    My ElMoto Project "Electric Hurricane" - 1987 Honda CBR600 F1: Check out my Build ALBUM
    My ICE Cafe Racer Project "My Precious" - 1983 Honda CM400 Classic

  12. #10
    I should be working! furyphoto's Avatar
    Join Date
    Jan 2012
    Location
    Harrop, BC, Canada
    Posts
    280
    Post Thanks / Like

    My Social Networking

    Add furyphoto on Facebook
    Quote Originally Posted by Nuts & Volts View Post
    Yea the only thing missing for me is the fuses. With those you have a drop in 12V solution. Just add wires.

    This is a cool project.
    I don't know much about PTC resettable fuses, but I might have to take a look at incorporating some into the 12v buss I added to the relay common pins on the bottom of the board.

    It would be great to get a custom PBC made with everything incorporated in one package. Maybe someday once I get it running smoothly.
    Last edited by furyphoto; 24 July 2015 at 2338. Reason: added link
    -Andrew

    http://www.andrewdoran.com
    mail(at)andrewdoran.com

    My ElMoto Project "Electric Hurricane" - 1987 Honda CBR600 F1: Check out my Build ALBUM
    My ICE Cafe Racer Project "My Precious" - 1983 Honda CM400 Classic

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •