Re: robotic airsoft turret
I am not very fond of relays largely because they are bulky and mechanically fragile. A very common method of controlling a load with microcontrollers is to use a pair of MOSFET's in a simple switching circuit (one larger P-channel MOSFET to control the load, one small N-channel MOSFET to switch the P-channel MOSFET, a 1kOhm~10kOhm resistor to act as a pull-up on the P-channel MOSFET' Gate pin, and a ~1kOhm resistor to act as a pull-down on the N-channel MOSFET's Gate pin).
Voltage source <-> Source pin of P-MOSFET
Voltage source <-> one lead of pull-up resistor
Gate pin of P-MOSFET <-> second lead of pull-up resistor
Drain pin of N-MOSFET <-> second lead of pull-up resistor (same as Gate pin of P-MOSFET)
Drain pin of P-MOSFET <-> one airsoft motor lead
Ground <-> second airsoft motor lead
Ground <-> Source pin of N-MOSFET
Gate pin of N-MOSFET <-> Arduino output pin
Gate pin of N-MOSFET <-> one lead of pull-down resistor (not connected to P-MOSFET)
Ground <-> second lead of pull-down resistor
How it works:
When the Arduino pin is set low (or when configured as an input pin) the Gate of the N-MOSFET will be pulled low. In this state, the N-MOSFET will not pass current and so the pull-up resistor will keep the Gate of the P-MOSFET at VCC. In this state, the P-MOSFET also will not pass current to the airsoft motor.
When the Arduino pin is set high, then the Gate of the N-MOSFET will be pulled high and allow current to pass through the N-MOSFET. This will connect the low side of the pull-up resistor (and the Gate pin of the P-MOSFET) to ground (or thereabouts), which will allow the P-MOSFET to pass current to the airsoft motor.
There are undoubtedly plenty of circuit diagrams out there depicting this circuit, but I cannot remember if it has a specific name or not.
You could use just a larger N-channel MOSFET connected directly to the low side of the motor, but this would require connecting the other lead of the motor directly to the voltage source. The problem is that if there is ever a short between the low-side lead of the motor and the chassis' ground, then the gun will begin firing and continue to fire until: the ammo is depleted, the short is broken, the voltage source/battery runs too low to power the motor, or the motor burns up from over-use. Generally, the positive terminal of a battery or other voltage source is a bit better insulated/isolated/protected than the ground/negative terminal, so controlling the motor's connection to the positive voltage source instead of its connection to ground makes it a bit safer.
Please pardon the pedantry... and the profanity... and the convoluted speech pattern...
"You have failed me, Brain!"