Darlington transistor for driving coils
A fundamental error involves D1. Its anode should go to Q1's collector, not to GND.
A capacitor should be added from +5V DC supply to GND. This is not a fundamental error. But it will keep transient voltages from destroying your processor, and act as a local charge reservoir that will give your solenoid more &quot;punch&quot;: something in the hundred(s) of microfarads.
When a solenoid is switched off, its stored energy dumps via D1 into the DC supply. The capacitor absorbs this energy and keeps the DC supply from momentarily rising...even a short transient above that which the processor can stand will cause destruction.
This processor seems to have 4 GPIO pins, one of which you are using to activate the solenoid. The other three pins are left open-circuit: their default state is to be GPIO input pins. Leaving high-resistance input pins floating is not good practice. Either change them to be outputs, or tie them to known logic states (high or low).