Hi Folks,
I have PIN2 on my UNO connected to the 5V terminal via 18k pull-up resistor.
Merely touching the yellow lead on the insulator portion is causing my interrupt to fire. I can't seem to explain it. I wouldn't expect any grounding when touching the insulated portion of the cable. What is causing this phenomenon?
I've seen this suggestion floating around the web, I believe you mean to indicate the addition of a semaphore via calls to noInterrupts()/interrupts(). I don't understand why this is necessary as I'm only reading the value of the counter. Please help me understand what I'm missing
I've improved the code as such, as well as removed the onboard internal pull up resistor:
int INPUT_PIN = 2;
int G_COUNTER = 0;
void handlerFall()
{
G_COUNTER++;
}
void setup() {
Serial.begin(9600);
pinMode(INPUT_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(INPUT_PIN),
handlerFall,
FALLING);
}
char buf[256];
void loop() {
int val = 0;
noInterrupts();
val = G_COUNTER;
interrupts();
snprintf(buf, sizeof(buf), "Count: %d", G_COUNTER);
Serial.println(buf);
delay(100);
}
And when i switched the 33k resistor to a 1K resistor, everything works as I'd expect. No capacitor needed.
Can you direct me to what I need to learn more about in order to understand the relationship between the resistor value, and this noise I experienced?
Thank you!
I would use a higher value pullup resistor along with a 0.1uF ceramic capacitor from the input to ground. A higher resistor to minimize current draw. A 4.7K will draw 1/5 the current and still, probably, be a plenty strong pullup. The cap is to filter noise and provide some hardware switch debounce.
Google something like "arduino pull up resistor usage" or "arduino pull up resistor value" for more ingormation on the subject.
Thank you, I'll give google a search. Switching 1K to 4.7k results increase sensitivity when touching the wire. A 330 resistor seems to be pretty bullet proof however.
I'm attempting to debug a hall sensor setup which is receiving spurious events in the interrupt handler. I created this trivial setup so I can reach out here for help. Using a capacitor really helps this contrived case, but makes the readings out of the hall sensor worse by a whole magnitude.
If the lower value pullup works, by all means go that way.
I did not know that you are using a Hall sensor (my bad, i must have missed that). The cap is not necessary (or even useful) with a Hall sensor. Hall sensors need no debounce.
It is all very simple. It is all about what is known as impedance matching.
Impedance is like resistance, in fact it is expressed in ohms. However impedance also covers AC signals.
If you have something sending a signal to an other thing, there are two impedances involved. The sending thing has an output impedance, the low the impedance the more current it can transfer. So a battery can be thought of as a voltage source with an associated impedance. So why can a car battery start a car but a hand full of AA batteries can not. Sure they have the same voltage but not the same current capacity. This can be summed up by the concept of an impedance. It actually is determined by battery chemistry and size, but can be summarised in the concept that the car battery has a much lower impedance that the AA batteries. Using ohms law you can even calculate it.
On the receiving device the input impedance of a device determines how much current it takes to change the voltage. So a low impedance input means that a lot of current is needed to develop a voltage on the input device, think of a speaker, of say 4 to 8 ohms will take a lot of current, where as a high impedance like a voltmeter only takes a very small current (ideally zero) to move a meter to full scale deflection.
Now if you have a 33K pull up resistor on an input then the input impedance is very close to 33K. Where as if you have a low value pull up resistor of say 330R, it will take a strong signal to move the voltage on the input.
Interference signals are high impedance, lots of signal but not much current capacity. So if you are picking up interference that is disrupting your signal, then you can reduce that disruption by making the input impedance lower, that is using a smaller pull up resistor.
The capacitor also helps by providing a low impedance path to ground for high frequencies.
In short signals picked up by an antenna is high impedance, so make the input impedance low by adding a smaller resistor.