I need to get a 12v square wave to an actuator (Tachometer) with common ground.
So far any use of a transistor i've tried either didn't work or was always on.
I've also tried to use a optocoupler to control the transistor which did work but wasn't fast enough.
That is an emitter follower, and won't work well. Try the common emitter configuration instead. The transistor must be able to handle the current required by the actuator/tachometer.
Can’t quite make out the values , I would have 560R in series with the led and 1k base resistor for the transistor and say 10k up to + 12v from the base too
Where u have it in the last picture , it needs to be a pnp transistor.
use Larry's circuit from post #3. If it didnt work you built it wrong - maybe had the pnp & npn mixed up?
You can use the BLINK example to generate a square wave.
Alternatively you CAN use the circuit above; however I'd put a resistor between base and emitter of the transistor - say about 4k7.
You will need a resistor in the region of 470 ohm for the LED. Not 100k.
I've added the resistors you mentionned and now it works.
All i need to do now is put the right frequency in the code, but i will get to that.
Thank you for your help.