The code is fine just one of the parts needs 12v. I connected it and the arduino got hot so I disconnected it and tried the 9v in neither case did the circuit start. All that happened was the arduino shut its lights off and got extremely hot. What happened?
For context I'm working on a CO2 incubator. Here are some pictures
This is the schematic for the circuit
Ignoring for the moment that the coil amperage appears to be right on the Absolute Maximum rating that an output pin can supply, your diode across the coil will be a short to ground any time D7 goes high and you will definitely exceed by a wide margin the Absolute Maximum current available.
Post a link to the part labeled "valve". You can probably switch it safely using this circuit, where M stands for valve coil. Be sure to use a logic level MOSFET.