Hello again. I try to count how many times a magnet passes in front of a hall effect sensor (in order to build my scooter speedometer). I am using a keyes ky-024 hall sensor and an interrupt in order to count passes of the magnet. The problem I face is that each time the magnet passes by the sensor I get a reading that does not correspond to reality.
Hall sensor has 4 pins. AO, -, +, DO. I have connected - to GND, + to 5v and DO to digital pin 2.
There may be a pullup on the module, but try setting pin2 as INPUTPULLUP. Try adding a 10K pullup from D0 to 5V.
Try adjusting the big blue potentiometer to a setting with better response.
Try placing a 100nf capacitor between D0 and GND.
cattledog:
There may be a pullup on the module, but try setting pin2 as INPUTPULLUP. Try adding a 10K pullup from D0 to 5V.
Try adjusting the big blue potentiometer to a setting with better response.
Try placing a 100nf capacitor between D0 and GND.
I have already tested all of your recommendations except for the 100nf cap advice.
The sensor has 3 main components on its circuit board. First, the sensor unit at the front of the module which measures the area physically and sends an analog signal to the second unit, the amplifier. The amplifier amplifies the signal, according to the resistant value of the potentiometer, and sends the signal to the analog output of the module.
The third component is a comparator which switches the digital out and the LED if the signal falls under a specific value.
You can control the sensitivity by adjusting the potentiometer.
Have you tried adjusting the sensitivity?
How close does your magnet pass?
How is your magnet oriented? You have a pole pointed at the hall device?
Can you post a picture of your assembly so we can see your component layout?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
How are you powering your project?
TomGeorge:
Hi,
Have you tried adjusting the sensitivity?
How close does your magnet pass?
How is your magnet oriented? You have a pole pointed at the hall device?
Can you post a picture of your assembly so we can see your component layout?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
How are you powering your project?
Thanks..Tom..
I tried to change the sensitivity but nothing changes. Just the range of the sensor increases/decreases.
The magnet gets really close but even if it does not the behaviour is the same. The magnet is not mounted in a rotating object. I move the magnet near the sensor.
I have a round magnet (like a coin) for testing. When the sensor senses the magnet a led lights up.
Here is the the circuit. Not a cad but you get the point.
Hi,
Can you try this code, it doesn't use interrupts, it is purely to detect the rising output of your hall sensor and update the displayed number.
It should advance one count with each pass of the magnet.
//Simple code to detect the rising edge of an input.
//Serial display is only updated on rising edge.
//Tom George 24/01/2018
int peristrofes;
byte pickupPin = 2;
bool pickupState = LOW;
bool oldpickupState = LOW;
void setup()
{
Serial.begin(115200);
pinMode(pickupPin, INPUT);
peristrofes = 0;
}
void loop()
{
pickupState = digitalRead(pickupPin);
if (pickupState == HIGH && oldpickupState == LOW) // checks to see if input has gone HIGH
{
peristrofes = peristrofes + 1;
Serial.print(" Input Count ");
Serial.println(peristrofes);
oldpickupState = pickupState;
}
if (pickupState == LOW && oldpickupState == HIGH) // checks to see if input has gone back to LOW
{
oldpickupState = pickupState;
}
}
It compiles, but I am at work and have not been able to test it.
Tom..
I have read it and I will do the recommended method. Thats not a problem. To be honest although I dont think it will make any difference.
Normally you should use digitalPinToInterrupt(pin), rather than place an interrupt number directly into your sketch. The specific pins with interrupts, and their mapping to interrupt number varies on each type of board. Direct use of interrupt numbers may seem simple, but it can cause compatibility trouble when your sketch is run on a different board. However, older sketches often have direct interrupt numbers. Often number 0 (for digital pin 2) or number 1 (for digital pin 3) were used.
Have you tried the capacitor between D0 and Ground? Other low cost modules using the lm393 comparator without hysteresis feedback have demonstrated the same problem.
cattledog:
Have you tried the capacitor between D0 and Ground? Other low cost modules using the lm393 comparator without hysteresis feedback have demonstrated the same problem.
The capacitor has been a simple fix.
I have not found so small cap yet. Can I use 1μF cap?
// Type: Analog
// External Libraries: no
// Magnetic field sensor analog HALL effect
// -------------------------------------------------------------------------
// Supply 5V
// Connections Arduino
// V = 5V
// G = mass
// S = A0
const int SIGPIN = A0;
const float GAUSS_PER_STEP = 2,713;
I managed to solve the problem. A little debouncing makes things work great. I will post the sketch later. I have completed the speedo part of my project.