# Automating and recording solenoid valve

When you are working with sensors, you want to have as many repetitions as you can of certain stimuli. For electronic noses, you want to put the nose in contact with those volatiles that interest you. To get improve our precision and automate this repetitive task, we decided to create minimal electronic device that switches a valve open/closed according to some protocol and exposes an electronic nose to a certain odor. Although this is not a completely crazy project, there are subtle details that are worth paying attention to. I will describe below how this was performed..

Thanks a lot for help from Brenno Barbosa, Lirio Onofre and Reynaldo Pinto.

## Testing if the solenoid does work

The first thing we should do is make sure the valve and solenoid are working properly. A quick way to check that is to pour water into one end of the valve, and make it open by applying 12V DC. This solenoid valve is directional, and there is an arrow indicating what is the proper flow direction. When the voltage is applied, you should hear a click, although no mechanical movement is appearent (everything is internal!). The water should flow right away. Once you open the circuit again, you hear another click, meaning that the valve is now closed again. The click may sound a bit scary at first – at least I thought I broke it the first time…

Because I could not find any videos of this solenoid operating in a development environment, I shot a quick video and posted on YouTube (click below to watch to it). Note at the bottom-left corner when Jaque closes the circuit by connecting a black jumper.

## Connecting to Arduino

Here is an sketch of how the final circuit looks like.

To help debugging the final circuit and code, we added two LEDs. LED D signals when the arduino leg 7 is set to ON. LED S lights if there is voltage coming from Vin and the circuit is closed. If everything is working properly, LEDs S and D should both blink together.

## Syncing and recording time

After running this for over two hours, we found that Arduino has an intrinsic jitter of about 400$\mu$s and a latency very close to zero. Notice that the distribution is skewed: it goes from -250$\mu$s to +400$\mu$s.

a