Micro-controller drives solenoid 12 volt through interposing relay 5 volt issue
Your circuit should be like this.





These two are screenshots of the proteus simulation results. You have placed diode in the wrong position, plus haven't used a BJT / MOSFET. ATMEGA 8 can have a maximum 5.5 volts. I hope this will work.