Help programming Hall effect sensor for DIY handbrake

Hi

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

https://www.amazon.co.uk/KOOKYE-ATm...=1498684511&sr=8-2&keywords=arduino+micro+usb

and

https://www.amazon.co.uk/SunFounder...1498676322&sr=8-2&keywords=Hall+Effect+Sensor


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:
The sensor you're using is i think just a switch, so it gives you a digital signal and not an analog as you want.
As far as i know i use one of these sensors for my handbrake and pedals:
http://www.ebay.de/itm/A1302KUA-T-A...148025&hash=item21206670bc:g:so4AAOSwHnFVye-~

For calibrating your range you can use dxtweak, with that you can also find the correct position of the magnet.


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 ;)
 
Upvote 0
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.

A1302-hall-effect-sensor-pinout.png


Neodymium-laptop-hard-drive-magnet.jpg


Hall-effect-sensor-circuit.png
 
Upvote 0
For archival purposes I'de like to point out a glaring issue: you set a delay of 1000 milliseconds. This means the output is only updated every second. A delay isn't necessary when using the Joystick library, but if you want you can set it to 10. This means every 10 milliseconds the loop is run. Plenty enough for 60 fps games.
 
Upvote 0
Back
Top