I've been told this circuit will not work and I need to use an opto isolator as there is no ground for the transistor
The chip is a pic32
I say it will work fine it's a simple switch, the transistor conducts and the ground is the other end of the module, in this case a HC-12
Assuming that the processor is a CMOS chip powered from 5V, the highest voltage any port pin will pull to while sourcing a couple of mA to the base of the NPN through R4 is about 4.8V. R4 is not needed, so leave it out.
You will loose another 0.7V as the base-to-emitter drop on the '3904, so the highest voltage you will ever get to pin 4 of HC-12 will be 4.8V - 0.7V = 4.1V. Is that enough? Probably not!
How much current does the HC-12 require? At what voltage?
The correct approach is to use a "high side PMOS" switch circuit. Can you reverse the logic on the port pin such that it is "low" when you want the HC-12 to be powered?
Ok, so you left out so much information on your first post so as to make my response mostly guesses...
When high, the PIC port pin will struggle to get above 3.2V while sourcing the base current. That means (best case) 3.2V-0.7V = 2.5V for the HC-12.
Since you didn't answer the question about how much current the HC-12 requires ( I had to guess) ...here is a "High-Side-Switch" which delivers up to 100mA @5V when driven from a 3.3V PIC port:
Com1 is just a simple serial port
It won't be receiving any data - it will only be transmitting data when pin 16 is driven high
even if it was receiving, it wouldn't be listening unless pin 16 goes high
granddad I don't get what you mean
I'm using the transistor as a simple on/off switch to power the HC-12 from the 5v line The tx/rx wont be working unless pin 16 goes high
HC-12 is an RF txd and rxd module (transmits serial data over 433Mhz)
I've tested the HC-12 by powering it direct from 5V without using a transistor or switching it from the pic and it works fine
it's only the switching circuit I'm having problems with
ALL I need to do it turn the power to the HC-12 on and off with the pic pin
The 5v tolerant pins can be ignored, pretend that the wording isn't there!
To conserve power
Both the HC-12 and a GPS module with be "powered on" by pins on the pic32 chip
The reason is - its battery powered and the battery is solar charged and its in a remote location where no mains power is available