Help programming Hall effect sensor for DIY handbrake

Discussion in 'Sim Racing Hardware' started by nil80c, Jul 1, 2017.

  1. nil80c



    I'm building a handbrake for my sim racing rig and need help with the code as i can't actually code myself.

    These are the 2 parts i'm using


    First i compiled and uploaded this sketch to test the sensor.

    //Analog Hall Sensor
    //using an LM393 Low Power Low Offset Voltage Dual Comparator
    * Analog Hall Sensor Uno R3
    * A0 A0
    * D0 7
    * VCC 5V
    * GND GND

    const int ledPin = 13;//the led attach to pin13
    int sensorPin = A0; // select the input pin for the potentiometer
    int digitalPin=7; //D0 attach to pin7

    int sensorValue = 0;// variable to store the value coming from A0
    boolean digitalValue=0;// variable to store the value coming from pin7

    void setup()
    pinMode(digitalPin,INPUT);//set the state of D0 as INPUT
    pinMode(ledPin,OUTPUT);//set the state of pin13 as OUTPUT
    Serial.begin(9600); // initialize serial communications at 9600 bps


    void loop()
    sensorValue = analogRead(sensorPin); //read the value of A0
    digitalValue=digitalRead(digitalPin); //read the value of D0
    Serial.print("Sensor Value "); // print label to serial monitor
    Serial.println(sensorValue); //print the value of A0
    Serial.print("Digital Value "); // print label to serial monitor
    Serial.println(digitalValue); //print the value of D0 in the serial
    if( digitalValue==HIGH )//if the value of D0 is HIGH
    digitalWrite(ledPin,LOW);//turn off the led
    if( digitalValue==LOW)//else
    digitalWrite(ledPin,HIGH);//turn on the led
    delay(1000);//delay 200ms

    And i can get a readout on the serial monitor.

    I then installed the joystick library and ran the test code and i can see windows is recognising the arduino as a game controller.

    I need windows to recognise the analog hall sensor as a throttle, and be plug and play so i don't have to mess about when starting a game. I think i'll also need the ability to adjust the range.

    Can anyone help?
    Last edited: Jul 1, 2017
  2. Thomas Weg

    Thomas Weg

  3. nil80c



    Thanks for replying Thomas. I really hope your wrong about the sensor ;(
    The description on amazon says "The comparator LM393 on the module supports output of both digital and analog signals at the same time"

    Doesn't that mean it's not just a switch?
    The output i get from the above code ranges from about 500 to 0 depending on how close i put the magnet.

    btw, thanks for the tip on dxtweak, i was thinking about how to do that ;)
  4. manc0ntr0


    I made a handbrake with a Hall sensor and Thomas is right. You need a Hall sensor and a neodymium magnet. You can find one of this magnet in ebay or in an old mechanical hard drive.
    Then you need to wire the Hall. Power (5V better than 3.3V), ground and signal, this last to the desired analog pin in Arduino.