counting circuit help

Hi all,

I am new to this forum, but thought I would post in the hope that someone can point me in the right direction as I am struggling a little with a circuit and I am in dire need of being pointed in the right direction.

I am trying to build a counting circuit that adds to one of 2 counters based on certain conditions, I then want to use the arduino to read from and reset those counters periodically.

I plan to use 5 pairs of IR Reflective Sensors (QRE1113) and a pair of hardware counters(N74161) on each unit.

Assume the reflective sensors are between two barriers so that stuff can travel 1 way or the other in single file over the pair of sensors, also assume that we nickname the sensors sensor "a" and sensor "b", if something goes over the sensors "a then b" then i want 1 to be added to 1 of the counters, we'll call it the "in counter" and if the sensors are triggered "b then a" i want to add 1 to the other counter nicknamed "out counter".

Each of the 5 pairs of sensors can trigger into the counters at anytime.

Anyone any ideas on the direction i need to take to get that logic working with the 5 pairs of sensors and the 2 hardware counters?

I have only done basic electronics at school, many years ago. I could achieve this in software, but don't believe it will be accurate enough for my needs. My main challenge at the moment is how to do a then b and b then a. a and b would be pretty straight forward, but doesn't meet my requirements. I think i need to use a pair of nand gates for each sensor pair and something else to allow the "then" logic to make this work, but that's where my knowledge breaks down.

Any help pointing me in the right direction would be appreciated.

Thanks
Darren

Are you looking for a hardware soloution or a software one.
With software you need to know all about state machines, so look at the blink without delay example.
Note you also have to cope with a triggered but never b, a and then a again, and the same two conditions for b.

Hi,

Ideally i want to do this as a purely hardware circuit with my software purely reading and resetting the counters to 0.

I am assuming that it will always be "a then b" or "b then a", there should never be a valid state whereby a or b could be triggered independently.

This is the blog post i wrote with my concept for this circuit, it should help people to visualise what I thought in my naivety would be easy to achieve. It includes basic drawings of the end device, the QRE1113 photo transistors will be in pairs within a couple of mm of each other.

In my head, both sensors are likely to be in the true state at the same time, but it is the one that entered that state first which is the key to determining direction.

Thanks
Darren

Valid state or not there will be cases of isolated triggering. Sure you can do it in hardware. In fact in my first job in the 60s I worked on a device like that which counted people going up stairs on a double decker bus. There was a display showing how many seats were left upstairs. This was in the days before microprocessors so it was all in hardware. In fact it was in the days before ICs so everything had to be made from transistors of various kinds.

You need to use a monostable to gate a counter, you need one for in and another for out.
Sensor A fires a monostable which enables the counter which is then clocked by sensor B. then you need to reset the counter after you have read it.
Mind you I can't see the point in doing that if you have a processor hanging arround doing nothing.

This was in the days before microprocessors so it was all in hardware. In fact it was in the days before ICs so everything had to be made from transistors of various kinds.

Thank goodness you at least had transistors. How would you have done it without them ?

We actually used SCRs to make the ring counter. The PCB was about one foot six square.

Hi Mike

Thanks for your reply.

The 3 reasons that i was planning to do this in hardware rather than the microcontroller(Arduino) are:

-> I am planning to use an arduino nano attached to the hive to keep the size and costs down, this only has 16kb to fit all the required code for this and the other sensors.
-> I am worried about the connectivity to the Arduino, i need 40 analog inputs just for the bee counter, 4 units * 5 gates * 2 sensors per gate, plus the other required connectivity
-> I am worried about the sampling rate to do this using the micro controller

I am more than happy to be proven wrong, if there is a better way then i am happy to learn, I am an IT engineer by trade, so it's more than possible that i have over complicated things and gone straight to the complex rather than looking for the simple solution, we all do it... :wink:

Thanks
Darren

Any size savings you make by using a nano will be more than eroded by trying to do this in hardware.
It only takes a few bytes of memory to do this anyway.
The sample rate of a micro is way faster than you need.

However you have now added more information so that might change the viability of the project. Have you tested this sensor with bees? I would try one sensor and see how it performs.
What is a unit? And how does this equate to 40 analogue sensors.

In my head, both sensors are likely to be in the true state at the same time, but it is the one that entered that state first which is the key to determining direction.

What you are describing is the way quadrature encoders work. In your project, the 20 gaps (entrances for bees), each with a pair of photo transistors, would represent 20 quadrature encoders.

You may find this interesting: Reading Quadrature Encoders with Arduino