Connect with us

Airsoft project : bb counter

Discussion in 'General Electronics Discussion' started by Evans, Dec 6, 2014.

Scroll to continue with content
  1. Evans


    Dec 6, 2014

    First of all I would like to inform you that English is not my mother language. So I apologize for the possible inconveniences.

    I play airsoft and wishes to make a counter indicating how many I have left bb into the magazine.

    To do this, I explore a lot of track and the most promising is the following:

    Into each charger, I put a PIC microcontroller. This PIC 12F1572 contains the number of remaining bb. I draw your attention to the fact that the microcontroller does not detect the bb, it contains just a number.
    I can communicate with this microcontroller via UART (so I can order him to decrement the number of bb, the increment, reset it, or ask for the number). PIC_Magazine's UART communicates with a microcontroller contained in the replica weapon, the PIC 18F22K23.

    The PIC_Replica aims to manage the operation of the replica.
    It detects when the trigger is pressed, if a bb was fired and in what mode the replica is (pin 12, 13 and 14). It also retrieves the number of bb contained in the charger (pin 17 and 18), and according to all this information, it triggers or not the shot (pin 23).

    Finally, the PIC_Replica communicates with a PIC_Display, PIC 16F1618 (pin 27 and 28).
    The purpose of PIC_Display is simply to retrieve the number of remaining bb into the magazine via UART (pin 12) and display via a 3 digit 7 segment.

    Here the overall operation.
    I would also add the ability to retrieve in the PIC_Replica the voltage of the battery (LiPo 2S) in order to send this informations to the PIC_Display.

    The problem is that I'm a big electronics novice.
    I miss a lot of things to achieve a coherent diagram.

    For example, to supply the 3 PIC, I use only the battery of the replica, the 2S LiPo.
    So I think putting a 5V voltage regulator but I can not seem to find a 3 pin component that makes it. It's the same for the voltage sensor. There's so much I do not know what to choose.

    The most successful electrical diagram that I could do is:

    Light blue: wire to ground
    Orange: 5V
    Red: 2S LiPo


    I would like to inform you that the purple square between the PIC_Magazine/PIC_Replica and the PIC_Display/PIC_Replica is a iphone sim's connector. It allow me to connect 6 pin.
    Since i will swap magazine once it was empty, the part of PIC_Magazine will be removable.
    The same thing is available for the PIC_Display, since i can not connect it at all. In this case, only the PIC_Magazine and the PIC_Replica will be here.

    Reading the datasheet to connect the pin, I came across this passage for the PIC 16F1618: "All pin outputs default to PORT data latch.
    Any pin Can Be selected as a peripheral digital output with the PPS output selection registers ".
    Do I understand that Rx and Tx for the PIC 16F1618 is on the same pin?
    In any case I wired this way.

    For the display, I would like to decrease or increase the brightness.

    I read that it was possible to do this in software, by increasing or decreasing the LED illumination rate of 7 segments.
    To 'drive' it, I would use a potentiometer, the result would be read on a DAC. I wanted to do this in the PIC_Display AN0, is that correct?

    I read that all this PIC have internal clock, so i don't need a external quartz, isn't it ?
    I want to manage my rate of fire with the PIC_Replica.

    Well, I know I'm far from a complete diagram (missing value resistors, decoupling capacitor, etc etc), but I'd like your opinion.

    Thank you for reading.

    Link : Datasheet and other :
    PIC 16F1618
    PIC 12F1572
    PIC 18F22K23
    NMOS : IRL1404
    PMOS : IRF4905
    LiPo 2S
    7 segment : i really like to use this, but i'm not sure if it's OOS or not.
    I just want a 7 segment 3 digit wich is not wide, like 23 or 26 millimeter.
  2. chopnhack


    Apr 28, 2014
    Welcome Evans, you are off to a really good start with your project!
    I am not sure what you meant that you couldn't find a three pin component for your voltage regulator?
    Three pin voltage regulators are fairly common, for 5v look for LM7805 this will give you a 5v regulated output.

    Do you really need three μcu's? I was thinking with all the available gates on the pic18, you should be able to combine the functions of the replica and charger unit into one. I should think there would be sufficient memory to retain the charge starting data in the pic18.

    How are you capturing the trigger pull and mode (pin 12,13,14) data?
  3. Evans


    Dec 6, 2014
    Hello chopnhack, and thanks you for your welcome. :)
    I had the chance to be helped by competent, patient and pedaguoge people.
    My electronics knowledge goes way back and at first I was doing more black magic than anything else.

    Well, I did my research via, but I did not find what I wanted.
    The link you give me sends me on a display ban suremenent because I am not in England but in France.

    "Unfortunately, access to this particular item has been blocked due to legal restrictions in some countries. We are blocking your viewing in an effort to prevent restricted items from being displayed. Regrettably, in some cases, we may prevent users from accessing items that are not within the scope of said restrictions because of limitations of existing technology. Please accept our apologies for any inconvenience this may cause, and we hope you may find other items of interest on eBay."
    It's quite funny in the end.

    So I searched the LM7805 and found his family in Farnell.
    Indeed, it is a three-leg, but I unfortunately forgot to specify the operating range.
    As I would use a LiPo 2S, the operating range will be from 6 to 7,8V (in practice, from 6 to 8.4V).
    However, if I understand it correctly, the minimum input voltage for the LM7805 family is 10V. You gave me the tracks, I'll go in that direction.

    I understand your question.
    To explain why, we need to know how the replica weapon at the base.

    Initially, the wiring diagram is very simple: a connected battery has a switch that controls a motor.
    The motor drives the gears, which themselves pulls back a piston, and then the piston is released. The air mass expelled and propels the bb.

    All firing is managed mechanically.
    If I select the mode "semi automatic", how is switched off the engine after a shot?
    Thanks to the cut off lever.

    In this video you can see it in action (the yellow mechanical part above the blue gear).
    In the semi mode, it is "jump" the switch trigger. In automatic mode, it is neutralized (visible a little further in the video).

    The fact is that nothing in the design of the replica gun permits to know when a shot was made - this were never intended.

    The idea to detect the shot with a mimimum of mechanical modification is to use the cut off lever.
    Semi automatic, the cut off lever is functional, but not automatic.
    Therefore remove the system that neutralizes the cut off up to detect the shot, regardless of the shooting mode.
    But we lose a shooting mode (without cut off lever, no semi).

    The idea is to manage the firing electronically and not mechanical.
    (yes I know, I spoke of "minimum change").

    The fact that the PIC_Replica has many input is because I need two UART (retrieve the number of bb from the PIC_Magazine and send the voltage and number of bb to PIC_Display).
    Originally, the PIC replica weapon was the same as the PIC_Magazine.

    Finally, i have to have a PIC in each magazine because each magazine can be loaded differently.
    On the MP7 i use actually, there is only 2 type of magazine : 50 or 100 rounds, but on the other AEG (automatic electric gun), you can have lowcap, midcap, hicap, drum, and even for two midcap, you can have a different maximum loading due to a differente brand.

    I hope i answered your question.

    The triger pull is captured by a switch like this, and the mode will be captured by another switch (i need to made it).
    However, I haven't found the switch to detect the cut off lever.
    It would take a very flat push button (2 millimeter).
    I will put photos that you realize.
  4. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    Jan 21, 2010
    I realise that the English and the French are traditional enemies, but surely they have reasonably good relations at the moment!

    Does this work?

    It sounds like the warning you're getting is from eBay, not farnell
  5. Evans


    Dec 6, 2014

    At the first glance, this one seem to match all my need, but since i see what you proposed, i search a little further and i found a huge quantity of similare part, except the fact there are "LDO" (low drop out).
    So, i search what is the advantage of a LDO, and i learn that a regular voltage regulator need +3V in order to run, but a LDO doesn't need such a potential difference.

    I want 5V and my Vmin is 6V, so i think i need a LDO, isn't it ?
    I think this one will be ok.

    But i have a question : the output current is 1A.
    I have trouble to find out if 1A is too much or not enough.
    What setting should I check in the datasheet of the PIC ?

    Edit : yes, the warning come from Ebay, not farnell.
  6. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    Jan 21, 2010
    Yes, if your input voltage is 6V then an LDO variant will allow you to have a valid 5V output for lower input voltages. Beware that LDO regulators have strict requirements for input and output capacitors or they can oscillate.

    A PIC alone requires far, far less than 1A (so a 1A regulator is fine). If you are driving motors or lots of relays, many bright LEDs, etc., then you may need more than 1A.

    Most three terminal regulators are current limited and will shut down if they get too hot, so they won't let the smoke out. If you find that the regulator is getting hot (too hot to hold) then you will need to attach a small heatsink. Beware that the metal tab on these devices is connected to one of the pins so you need to be careful not to short the tab (or the heatsink) to anything.
  7. chopnhack


    Apr 28, 2014
  8. Evans


    Dec 6, 2014
    Thanks for your reply, (*steve*) and chopnhack.

    My diagram is almost complet, the only thing that the 5V will supply is a 7 segment 3 digit and 3 PIC.
    So according to what you say, i think i'm safe with 1A.

    Thanks for all the information about the heat of the regulator.

    I update my diagram : adding the LM2940T with his capacitor.
    I also set the PIC capacitor to 10µF. I just read that many time, i can't really explain why, but i do it.

    But i have a long road before i can have a good diagram. Have you seen something wrong so far ?


    edit : i completly forgot to tell you how the number in the magazine can be set.
    I will make an another electronic part wich is can't be seen here.

    It's a modified bb loader wich will communicate via UART with PIC_Magazin.
    Each time the bb loader put a bb in the magazine, it will increment the number.
    That's how i can know how many bb left in the magazine without directly detect the bb.
    chopnhack likes this.
  9. Evans


    Dec 6, 2014

    I'm back with some new and some question.
    The first thing I added is the detection of power LiPo by the PIC_Replique. I did not know that a simple voltage divider to an analog input of PIC_Replique is enough, I thought i have to put a voltage sensor (just as there are current sensor).
    So it's done.

    The second thing is avoiding hot plugging of PIC_Chargeur.
    Indeed, as the PIC_Chargeur is on a circuit designed to be removable, so it will be connected / disconnected from the supply whenever I change my magazine.

    I only have a 6 pin SIM card connector for the connection.

    The connector will be at the bottom of the space when i put the magazine and on the top of the magazine wil be a IC footprints. The footprint and connector will therefore be closer to the face to face contact.
    So I can not use the trick usb which involves making first contact with the ground, and then the supply and finally the I / O port.

    So I chose to emulate this behavior as follows.
    A MOSFET controlled by PIC_Replique allows the 5V to go to the removable circuit. The detection of the presence of the removable circuit made by the ground.
    Once I detected the removable circuit, I wait 300ms (arbitrary value) and I supplies it with 5V.
    The resistance of Rx / Tx are such that the PIC_Chargeur not be abused.

    Here the current diagram :


    Come my questions.

    I do not know how to choose my mosfet based on the current / voltage I have.
    The Lipo deliver 6V to 8,4V (red wire) and the voltage regulator deliver 5V 1A (orange wire).

    I want to find the two mosfet on the right. What criteria must i search ?
    By the way, it's possible to delete the left NPN and connect RC3 directly on the gate of the two left mosfet (maybe delete the 100 Ohm resistance with it) ?


    Attached Files:

Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day