Different voltages in same Arduino circuit

Is it safe to use different voltages (for example 12V and 5V) in the same circuitry and tie the grounds together?

In general, yes.

If you e.g drive a NPN transistor from the Arduino (5V) to switch a higher voltage (12V) load, you actually have to connect the grounds.

The current from the Arduino through the transistor needs a path back to the 5V power supply else it will not work. The same for the current through the collector/emitter that needs a path back to the 12V. As the emitter is used by both, both grounds need to be connected to the emitter and hence both are tied together.

Thank you!

I use external PSU through nMOS as you mentioned to control the 12V power and 5V for some leds which cant handle the 12V andalso run the Arduino from that source.

to control the 12V power and 5V for some leds which cant handle the 12V andalso run the Arduino from that source

That's a bit strange:
With the correctly dimensioned resistor LED's can handle almost every power and 12V is absolutely no problem.
If you drive the LEDs directly via the 5V output pins of an Arduino without any resistor which limits the current, you will be close to buy another arduino and/or LED.

If you drive LED from Arduino, then need to replace only LED, Arduino will not have any issues.

rpt007:
That's a bit strange:
With the correctly dimensioned resistor LED's can handle almost every power and 12V is absolutely no problem.
If you drive the LEDs directly via the 5V output pins of an Arduino without any resistor which limits the current, you will be close to buy another arduino and/or LED.

OP, try this: plug a led into the + and - directly. Use a really small, cheap, led - it will be spectacular.

f you drive LED from Arduino, then need to replace only LED, Arduino will not have any issues.

I wouldn't bet on that. If you exceed the output of a pin too much you might destroy the output transistor of the Arduino. Depends on how long it takes that the LED dies.

I had one example which I intentionally wanted to fry - spectacular and it took some seconds (ok, not via an Arduino, but with my laboratory power supply).

rpt007:
... I had one example which I intentionally wanted to fry - spectacular and it took some seconds (ok, not via an Arduino, but with my laboratory power supply).

Oh yeah, use the heftiest power supply you can get your hands on. The LED will last a shorter (and thus more brilliant) amount of time with more current. There is probably a limen of perception, below which no event is observed, only the change of state. To a machine, that should be significant, but c'mon! I want the best flash! so try shorter and shorter times, and higher and higher currents.

NOTE:only try this if you are aware of all of the consequences. The author of this post is not responsible for damage to your property, even if you did exactly as was recommended.

ChrisTenone:
OP, try this: plug a led into the + and - directly. Use a really small, cheap, led - it will be spectacular.

I blinked..... darn, and that was my last really cheap led, all the rest cost 2 pennies.

sarouje:
If you drive LED from Arduino, then need to replace only LED, Arduino will not have any issues.

To be all encompassing, we do not know how many LED's the OP is using. either on one pin, or collectively on the Arduino.

10 LED's all anodes on one pin, to ground ? for each of 10 pins ?

or a couple of those nice 3 watt white LED's.