Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 7 months ago.
Help with Interrupts
Hello Mbed Team,
I'm tryin to implement a break beam circuit(consisting of ir led and phototransistor) for calculating the number of persons entering the room .
I rigged up the circuit and the same circuit worked well for arduino,but here on mbed i'm not getting the exact output .For a single beam cut the count is incrementing by 30 or 40 not sure why .
I have attached the code and the hyperterminal o/p for the same .
main.cpp
#include "mbed.h" char counter=0; InterruptIn button(p18); void inc() { counter++; } int main() { button.rise(&inc); while(1) { printf("The number of persons Entered = %d \n",counter); wait(0.2); } }
Before 1st cut
After 1st cut
The count has increased by 36 instead of 1 ,not sure why .Please help .
4 Answers
11 years, 7 months ago.
Are you possibly now using a button to simulate your circuit? Then this could simply be bouncing. Even if not I guess something similar could happen. You can have a look at the PinDetect library: http://mbed.org/users/AjK/code/PinDetect/docs/tip/
11 years, 7 months ago.
Hello Mr Erik,
I'm using an IR break beam circuit to count the number of ppl entering , i tried with the circuit given in the below link and could even implement an tachometer too on arduino . Not sure why its not working with the mbed board .
Below is the link where i got the circuit .
http://arduinoprojects101.com/arduino-rpm-counter-tachometer/
11 years, 7 months ago.
Most likely cause is bouncing. Original arduino code used falling edge for count. The ir diode may have better response that way. Try button.fall(&inc). You may also try some small capacitor parallel to the ir diode to reduce bouncing.