How to build "two power sources" in a microcontroller circuit?
Sounds like the back-EMF from the solenoid is disrupting the micro. There are a few potential issues / solutions here;

1st, read up on snubber diodes/protection used with relays/solenoids, it's been covered many times here on all the hundreds of variations on "how do I switch a relay from my *duino?" questions.

2nd, look at the smoothing and grounding of the micro's supply.

3rd, you may need to separate the "power" side of your circuit from the "logic" side using something like an opto-isolator and perhaps splitting the power supply - this does not mean you need two separate PSU's, just that the delicate side of the circuit could include a power supply/conditioning circuit that isolates it from the noisy side.