I'm not sure how you plan on recognizing the capacity of an inserted magazine.
But, whatever it was that was your idea to detect the firing of a round to keep track of shots is problematic, because.... What if you hand cycle a round? What if you shoot crap steel case surplus and you get a hard primer and have to drop mag and clear? Would your idea of a round counter get confused in all of that, thinking a fresh mag was inserted?
Keep it super simple. Keep your entire project limited to the magazine. At the very least, start there. All you need to do, is have a device that keeps track of how many rounds are in a magazine. That's it. It doesn't care why they leave the magazine, it doesn't care if the magazine isn't fully loaded, you're only designing something that is a digital version of a visible window that shows the follower and has the round count simply labelled along the magazine like witness holes on a pistol mag.
Consider the confines of a STANAG mag. I think what you can start with is a windowed poly mag, and consider how you might track the movement of the follower, because that is the quintessential component that reliably indicates how many rounds are in that magazine.