Software button debounce.

solenoid connected to digital pin 4 on arduino

Ok, I'm sure it's not a direct connection, but hopefully the solenoid has a clamping diode or snubber circuit. Otherwise, the spikes from energizing/de-energizing solenoids will create havoc.