Electronic – Safe microcontroller input from 8.4V circuit

opto-isolator

I have an airsoft rifle which uses an 8.4V battery to drive a motor when the trigger is pulled. The circuit is that simple, just a battery, motor and switch – there's also a 15A fuse.

I want my microcontroller to detect when the trigger is pulled, but I don't want to have to dismantle or extensively modify the replica gun. The only wiring I can get to is the battery terminals.

My first thought was to just put in a relay on one side of the battery, but I'd prefer to avoid the noise and reliability issues. (I'm willing to be persuaded otherwise)

Now I'm considering using opto-isolator. I haven't picked a particular model yet.

I can't risk the microcontroller being damaged. Its digital input is pulled up to 3.3V by a 22k resistor.

I apologise for my total lack of skill at electronics, but I don't know how to put the opto-isolator in circuit, at the right voltage etc. (Other than just putting it in series, with a resistor, which would presumably slow down the motor – no good.)

I'd appreciate any relevant example you can provide – or completely different approaches.

Thanks!

Best Answer

First you need to measure the "running current" of the motor. Do this by putting an ammeter (Digital MultiMeter set to the "amps" mode) in series with either terminal of the battery.

I am assuming the "motor" you are referring to is a "permanent magnet DC motor" - the most likely type of DC motor used in this type of simple application you describe. In this type of motor there is also the "starting current". This is a brief high-current pulse which occurs when the motor first starts up from a resting position. You may see a brief display of this current when you first pull the trigger. The "running current" occurs when the motor achieves its final speed, usually after a fraction of a second.

It would also help if you can measure the resistance of the motor using the "ohms" setting of your DMM. It is probably in the range of 20 to 100 Ohms. This resistance along with the battery voltage can be used to calculate the "starting current" using Ohms Law ( in this case I = V/R, where V is the battery voltage and R is the measured motor resistance). Do this by removing the battery, connect the ohmmeter across the battery terminals and pull the trigger.

Once you have those parameters you can determine whether the series opto-isolator approach you propose will work. The main limitation with this approach is that the series voltage drop imposed by the opto's LED will starve the motor of starting current and maybe thwart operation of its intended mechanical function.

The topology (component connections) you will want to use here is a first resistor in series with the opto's LED and a second resistor in parallel with the first resistor and LED. Choosing the correct resistor values is the key to getting this scheme to work reliably. It may be possible that there is NOT a workable solution. It depends on the current measurements you come up with as described above.

The idea is that the second resistor will be a low enough value (Ohms) to pass the "starting current" with minimal voltage drop, but large enough that it won't shunt too much of the current away from the opto's LED during the "running current" period of operation. It's a delicate balance, but easily calculated once you know the currents involved.

Once you get enough current to flow thru the opto's LED, it's a simple matter to connect the opto's output transistor to your 3.3 volt micro.

There will definitely be certain opto-isolators better suited for this task than others. You'll want to choose one with as low an operational LED current as possible.

There is another way to do this. You would use a current sensing resistor in series with the battery. But this approach would require a much more complex circuit.

I'd suggest you make the measurements I described, then post the question again with these values and my proposed two-resistor & opto-isolator topology shown in schematic form, along with the battery voltage and type (AA, AAA, etc). You may also want to ask for opto-isolator selection suggestions.