I'm using my arduino on a Go Kart. I have a hall effect sensor reading a Key on a shaft to calculate RPM and Speed. However, its very erratic, especially at lower speeds. It bounces wildly when viewed in the Serial Plotter. Thats when I noticed I was getting readings when not moving! Even when I unplug the hall effect sensor, I'm getting random readings popping up. Here is my code.
The code is irrelevant here.
The problem is, that even with NO wires connected anywhere on the arduino other than a USB cord powering it, I'm getting an RPM value because my interrupts are triggered anytime my arduino is within 6 feet of the running engine!
Having random pin states on a floating input pin is expected. You can use a pull-up or pull-down resistor to make the pin default to a known state. The Arduino has internal pull-up resistors you can set via pinMode(pin, INPUT_PULLUP). Some boards have internal pull-downs too, but not the popular AVR-based boards (e.g. Uno, Mega, Leonardo, Nano).
pert:
Having random pin states on a floating input pin is expected. You can use a pull-up or pull-down resistor to make the pin default to a known state. The Arduino has internal pull-up resistors you can set via pinMode(pin, INPUT_PULLUP). Some boards have internal pull-downs too, but not the popular AVR-based boards (e.g. Uno, Mega, Leonardo, Nano).
Its not a floating pin. Even with the hall effect sensor wired in and the shaft not spinning, I still get interrupts on the pin.
madworm:
It works exactly like a switch that is normally open (NPN transistor with open collector). You connect the supply voltage to Vcc and GND. It will need about 10mA according to the datasheet. As I assume it will be connected to an arduino directly, Vcc is 5V. Then you take a 'pull-up' resistor (say 10k) and connect that to Vcc and the 'output'. Then connect 'output' to any digital pin on your arduino.
7 years ago advice to and two seasoned users advice and your brain tells you it’s not float issue.
Hexen:
The problem is, that even with NO wires connected anywhere on the arduino other than a USB cord powering it, I'm getting an RPM value because my interrupts are triggered anytime my arduino is within 6 feet of the running engine!
You don't do anything with the interrrupt pin in setup, so the pin is floating if it's not connected to a sensor.
If you also having trouble with the sensor connected, then post a link to the sensor,
and a picture of the (shielded) wiring to the sensor.
Leo..
pert:
Note that the internal pull-up resistors are fairly weak so in a noisy electrical environment you might need to use a lower value external resistor.
The internal pull-ups are way too weak for this kind of environment - try 2k2 or 1k in the first instance,
also add 1nF or so across the input to reject any RFI.
Shielded cable is a good idea, certainly twisted pair if not. Never connect the shield except at the Arduino end,
otherwise you create a massive ground loop (v. bad for interference). No part of the sensor wiring should be
grounded at the sensor, only via the ground wire back to the Arduino.
Nevermind. I forgot that asking questions on this forum usually leads to ~20 theoretical solutions and never the most simple answer.
I just added an IF line to the interrupt to check and make sure the digitalRead(2) was low before increasing the counter. Since its interrupting on FALLING, any RFI would set the D2 to HIGH. Just double checking to make sure it was low was a 5 second fix.
No need for a schematic or data sheet, although I know that's the go-to reply for any problem anyone has here on the forum.
Hexen:
No need for a schematic or data sheet, although I know that's the go-to reply for any problem anyone has here on the forum.
WHY???
You have the project infront of you, we don't.
You know how it is wired, we don't.
You know how you are powering the arduino, we don't.
You know how you have wired the sensor and with what wire, we don't.
A picture, a circuit diagram and a sketch is worth a thousand words and can save a thousand ill informed posts.
Thanks.. Tom...
Hundreds of different Hall effect sensors and you have "a" Hall effect sensor, many have open collector outputs and when not triggered, the output (and your interrupt pin) are floating and may show anywhere from 0 to Vcc, so you need a strong pullup in a noisy environment.
A pullup resistor did nothing. I tried several. The hall effect sensor is wired directly to the arduino, via 5V, Ground, and the signal to D2. I tried jumpering with multiple pullup resistors. Zero change.
My hall effect sensor is an AC Delco 12560228, the stock crankshaft position sensor for an LS1. If you can find a datasheet, be my guest. 99% of the sensors I use with arduino are automotive or industrial and datasheets aren't available, yet I get criticized here when I can't produce one.
Its not criticism of you - without a datasheet there is no definitive information, you are flying on your own unless
you want to post the sensor to us to play with(!)
If the datasheets aren't online, ask the manufacturer for them.
Like I said, the entire thing was fixed with one line.
If (digitalRead(2) == LOW) {}
RFI was making the pin go high when it wasn't supposed to. It was interrupting the square wave. I just added a double check to make sure the pin was still low when the interrupt was triggered on the FALLING side of the square wave, and all RFI interference is gone. I can now read RPM and MPH with incredible accuracy.
No need to complicate things. I've NEVER actually been given a straight answer when posting to these forums (I lost the login info for my old username a long time ago). Every solution I'm given is usually a reinvention of the wheel and I end up figuring it out via the most simplistic solution possible.
Hexen:
I've NEVER actually been given a straight answer when posting to these forums...
Post#0 should have had ALL the information according to the "how to post" sticky.
YOUR post has virtually NO hardware information, so most of us start guessing, which is wrong.
So indeed you're right. WE are to blame.
Leo..
Edit: Searched, but no datasheet online for that sensor.
You basically can't use a sensor if you don't know how it behaves.
Wawa:
Post#0 should have had ALL the information according to the "how to post" sticky.
YOUR post has virtually NO hardware information, so most of us start guessing, which is wrong.
So indeed you're right. WE are to blame.
Leo..
Edit: Searched, but no datasheet online for that sensor.
You basically can't use a sensor if you don't know how it behaves.
There were over 30 million of them produced. While a datasheet can't be found, its only takes a couple of minutes to look them up.
If you read my post the sensor itself is irrelevant. The sensor isn't misbehaving in any way. Its working 100% as intended. Its working as the coding is asking it to. The problem here isn't the hall effect sensor, yet everyone has made it the problem.
The problem is the RFI from the engine's magnetron ignition system and the fact that it is interfering with pins on the arduino. Not only is it triggering interrupts, but its also throwing off analog sensor values.
So, please excuse me if I get a little flustered when I come searching for a solution to an RFI problem and everyone wants to focus on something that wired right, working right, and programmed right.
Well, your testing was flawed by trying it with a floating pin.
And your understanding was questioned by ignoring that you did so.
That sensor is obviously made for the automotive industry,
and the manufacturere doesn't want others to use it (no datasheet online).
So you can only guess how to properly connect/use it, unless you can reverse-engineer the module that it's normally connected to.
You just have found out that things that work on the bench don't always work in 'dirty' environments.
You likely have to put your Arduino in a metal enclosure, and treat every wire going in with byass caps and/or ferrite beads.
Making a circuit immune to RFI is a sciency in istself.
Leo..
Right place, wrong way of asking.
If we don't see what you have or have done, then we can't give proper advice.
This seems to be more and more of a common problem on this forum.
Many of us then make the mistake of already anwering (guessing) without knowing all the facts,
leaving the poster usually with more questions.
Leo..