# Reed-switch counter HELP.

Hi Arduino's,

I'm brand new in the world of Arduino, programming...actually, brand new in the world of electronics. I bought a Arduino starter kit a few weeks ago, because I would like to learn how to program micro controllers.

But, it's not that easy when your'e new in the field, so I need some help from you pro's! ;)

I'm in need of a device, that tells me how many rounds my wheel has turned - but(!), it has to convert it so 3 rounds = 1 on my display. 6 rounds = 2 on my display. 9 rounds = 3 on my display. and so on, and so on... I was thinking about placing a magnet on the wheel and a Reed switch below.

I have tried to make a program in the Arduino-program, but I can't make it work... There must be someone that have made the same (or something similar), because in my head the code shouldn't be that difficult to make.

I really hope there is someone on this forum that can help me out. I would appreciate it a lot!

Ubbe09 (Denmark)

Go ahead and post what you have so far, don't be shy. What would be the maximum RPM of the wheel. Since you're learning, and the Arduino is probably plenty fast enough to do this a simple way. You can just watch a pin with a while() loop until it changes (start of magnet passing) and then another while() loop to wait until it is done. Then you could count it and update your display every third pulse. Finally, start all over again which the Arduino will do automatically if you put this in your loop() function.

Well I'm no "pro", that's for sure, but these two things spring to mind:

The reed switch will work like any other momentary switch, and will almost certainly need de-bouncing else you'll get a false count. So if you didn't already, take a look at the debounce tutorial.

Once you have that working, and of course keeping a count of how many pushes you have (or in your case, passes of the magnet) you're out by a factor of three. So have a look at modulo which gives you a remainder of a division... you would want a message when count modulo 3 is 0.

HTH?

@ afremont: So far I have the same "Debounce" code as the one JimboZA posted. I've just tried to combine the "Debounce" and the "Modulo" codes, but couldn't make it work. It came up with errors like: "84: error: 'values' was not declared in this scope" and something with a Void Loop error...

It just seems as a very simple code to make, but maybe my brain isn't made for programming... :~

Post your code and we’ll have a look at it…

Have you done the simple “starter” tutorials, like blink and so on?

EDIT…

Rather than debounce, you should actually look at the Button State Change tutorial, which exactly what you want except it uses modulo 4 to count in 4’s not the 3’s you need. (Although it’s not debounced… you may still need to combine the two)

Although you can certainly use a reed switch, it will need debouncing. Better in most cases (and still inexpensive) is a Hall sensor such as US1881, along with 2 magnets on the wheel mounted such that alternating N and S poles pass the Hall sensor.