1. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Download Package Now!
  2. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  3. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant here. Do not following these rules will lead to permanent exclusion from this website: Read the forum rules.

Arduino Traction+Gforce feedback (LED/vibrator)

Discussion in 'DIY Motion Simulator Projects' started by sikjar, Oct 21, 2015.

  1. sikjar

    sikjar Xiao Nie

    Joined:
    Nov 10, 2014
    Messages:
    24
    Occupation:
    Translator
    Location:
    China
    Balance:
    585Coins
    Ratings:
    +37 / 0 / -0
    My Motion Simulator:
    Arduino
    A simple way of getting a bit of feedback about the behaviour of the car.

    Here's a small project using just an Arduino Uno and a few components. The idea is to get some sort of feedback to let you see or feel if the car is loosing traction or close to the limit.

    In the below video two LED's have been connected to an Arduino board. The left LED (at the bottom of the screen) lights up when there is significant traction loss, and the LED to the right lights up when the G-forces (sway or surge / lateral or longitudinal) reach a certain level. The idea is that the G-force LED gives you a warning when you are reaching the limit of the cars traction, and the left LED tells you when you have gone past the limit, traction is lost, and the car is slipping.



    The most simple setup is simply to connect two LED's via a resistor to pin 6 and 11 on the Arduino.
    Here's a tutorial on how to connect LED's to an Arduino:
    https://www.arduino.cc/en/Tutorial/Blink

    Here's the script for the Arduino:
    Code:
    // Traction and G-force feedback for SimTools
    // by Sikjar
    // Shared as Public Domain
    
    // Based in part on X-sim3dashboard v1  by TronicGr (Thanos) 4-26-2012
    
    // Interface settings:
    // BitsPerSec: 9600
    // Data Bits: 8
    // Parity: None
    // Stop bits: 1
    // Output range: 8
    // Output type: Binary
    // Interface - Output: A<Axis1><Axis2><Axis3>
    // 5 ms Packet Rate
    
    // Axis assignments:
    // Axis1: Extra1
    // Axis2: Sway 
    // Axis3: Surge
    
    
    void setup() {
    
      // JSN declare pin 6 and 11 to be an PWM output, LED's or vibrator circuits will connect to those two pins
        pinMode(6, OUTPUT);  
        pinMode(11, OUTPUT);
    //Create Serial Object to recieve the data from SimTools
        Serial.begin(9600);
    }
    
    
    void loop() {
    
    char bufferArray[4];              // holds all serial data from SimTools into a array
    int i;
    
    byte Slip; 
    int IntSlip;
    int MinSlip = 2;  // The traction value where LED starts to light up. Adjusts the sensitivty of the traction feedback
    int MaxSlip = 70; // The traction value where LED lights 100%
    int OutputSlip;
    
    byte LatG; 
    int IntLatG;
    int MinLatG = 3;  // The value for lateral G's where LED starts to light up. Set this higher for high performance cars, current value is for the Mazda MX5
    int MaxLatG = 30; // The value for lateral G's where LED lights 100%
    
    byte LongG; 
    int IntLongG;
    int MinLongG = 3;  // The value for longitudinal G's where LED starts to light up. Set this higher for high performance cars, current value is for the Mazda MX5 in iRacing
    int MaxLongG = 30; // The value for longitudinal G's where LED lights 100%
    
    int MinG = MinLatG + MinLongG;
    int MaxG = MaxLatG + MaxLongG;
    int TotalG;
    int OutputG;
    
    if (Serial.available() >= 4)  {    //if 4 bytes available in the Serial buffer...
          for (i=0; i<4; i++) {         // for each byte
          bufferArray[i] = Serial.read();        // put into array
      }
    if (bufferArray[0] == 'A' ){      // if new bytes have been recieved
    Slip = bufferArray[1];
    
    // Here we do a little math, so that 127=0 and slip traction values above or below 127 become a positive number, the more slip, the higher the number.
    IntSlip = (int) Slip;    // make the byte type variable received via serial into an integer, so we can do a bit of maths with it
    IntSlip = IntSlip - 127;   // The value for traction (Extra1) is between 0 and 255, where 127 means full traction. Anything above or below that means the wheels are slipping.
    if (IntSlip < 0) { IntSlip = IntSlip * -1; }  
        
    if (IntSlip < MinSlip) { IntSlip = MinSlip; }
      if (IntSlip > MaxSlip) { IntSlip = MaxSlip; }
    // Below the the min and max traction values are mapped to the range of the PWM power output.
       OutputSlip = map(IntSlip, MinSlip, MaxSlip, 0, 20); // The value 0,20 means that at 0 the LED is off, at 20 its 100% on. For vibrators the value might be something like 40,200. It depends on the components used.
          analogWrite(6, OutputSlip);
    
    LatG = bufferArray[2];
    IntLatG = (int) LatG; // make the byte type variable received via serial into an integer, so we can do a bit of maths with it
    IntLatG = IntLatG - 127;  // The value for lateral G (Sway) is between 0 and 255, where 127 means no sway. Anything above or below that means sway (=Gforce) to the left or right
    if (IntLatG < 0) { IntLatG = IntLatG * -1; }
    if (IntLatG < MinLatG) { IntLatG = MinLatG; }
    if (IntLatG > MaxLatG) { IntLatG = MaxLatG; }
    
    
    LongG = bufferArray[3];
    IntLongG = (int) LongG;
    IntLongG = IntLongG - 127;
    if (IntLongG < 0) { IntLongG = IntLongG * -1; }
    if (IntLongG < MinLongG) { IntLongG = MinLongG; }
    if (IntLongG > MaxLongG) { IntLongG = MaxLongG; }
    
    TotalG = IntLatG + IntLongG;
    OutputG = map (TotalG, MinG, MaxG, 0, 40);
    analogWrite(11, OutputG);
    
      }
    
      }
    
      }
    



    You can also use vibrator, but don't connect the vibration motors directly to the pins on the Arduino, they draw too much current!
    Here's a tutorial on how to connect vibration motors to the Arduino:
    http://www.learningaboutelectronics.com/Articles/Vibration-motor-circuit.php

    In order to use vibrators you also need to adjust the two final numbers in
    OutputSlip = map(IntSlip, MinSlip, MaxSlip, 0, 20);
    and
    OutputG = map (TotalG, MinG, MaxG, 0, 40);
    The numbers indicate the power range that is output from Arduino PWM pins 6 and 11.
    If they are too low, the vibrator won't start, and if they're too high, the vibrator is going to run all the time.
    For a setup like the one in the above link the lines should probably look something like this:
    OutputSlip = map(IntSlip, MinSlip, MaxSlip, 40, 200);
    and
    OutputG = map (TotalG, MinG, MaxG, 40, 200);
    But this depends on the components used.

    I just tape the vibrators to my fingers, easy and effective!

    The above script is optimized for the Mazda MX5 in iRacing, but it should work with most other sims and cars if you adjust the values MinSlip, MaxSlip etc. as mentioned in the script.
    • Like Like x 3
    • Winner Winner x 2
    • Creative Creative x 2
    • Informative Informative x 1
  2. Ads Master

    Ads Master

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
  3. mrbeginner

    mrbeginner Active Member Gold Contributor

    Joined:
    Apr 8, 2012
    Messages:
    151
    Occupation:
    What ever come in my way
    Location:
    Finland Niinisalo
    Balance:
    - 25Coins
    Ratings:
    +53 / 1 / -0
    Nice idea! Maybe you could put one vibration motor to brake pedal and do little code for abs?
    • Like Like x 1
  4. sikjar

    sikjar Xiao Nie

    Joined:
    Nov 10, 2014
    Messages:
    24
    Occupation:
    Translator
    Location:
    China
    Balance:
    585Coins
    Ratings:
    +37 / 0 / -0
    My Motion Simulator:
    Arduino
    I might try that, but in any case the traction indicator should light up if you are braking too hard.

    Someboy else actually made an application that should work for brakes only:
    http://fergotech.net/diy-g27-brake-vibration/
    Not sure how well it works, never tried it...
  5. mirxtrem

    mirxtrem mirxtrem.apps

    Joined:
    Apr 22, 2016
    Messages:
    17
    Occupation:
    Electrical engineering student
    Location:
    Colombia
    Balance:
    273Coins
    Ratings:
    +4 / 0 / -0
    My Motion Simulator:
    Arduino
    Thanks, it works. I probed with arduino uno and two motor vibrator from old gamepad and Live For Speed. i'll triying to upgrade my cheap steering wheel.
  6. RacingMat

    RacingMat Well-Known Member Gold Contributor

    Joined:
    Feb 22, 2013
    Messages:
    2,046
    Location:
    Marseille - FRANCE
    Balance:
    18,524Coins
    Ratings:
    +1,939 / 17 / -2
    My Motion Simulator:
    2DOF, DC motor, Arduino
    good job!
    maybe you could add potentiometers to setup the parameters on the fly rather than in code (MinSlip, maxSlip...)
  7. mirxtrem

    mirxtrem mirxtrem.apps

    Joined:
    Apr 22, 2016
    Messages:
    17
    Occupation:
    Electrical engineering student
    Location:
    Colombia
    Balance:
    273Coins
    Ratings:
    +4 / 0 / -0
    My Motion Simulator:
    Arduino
    here is the test.
    • Creative Creative x 1
  8. Deadlock

    Deadlock New Member Gold Contributor

    Joined:
    Jun 27, 2018
    Messages:
    10
    Balance:
    77Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, SimforceGT, Motion platform
    Does it works on simtools 2.0?I have try but nothing output.