Arduino Solenoid Tutorial - Button Demo



This Arduino Solenoid Tutorial shows how to control a solenoid using pushbuttons and a relay with your Arduino compatible controller.
- The first button will hold the solenoid/relay on while it is held
- The second button will hold the solenoid/relay on for 2 seconds

Solenoids are great for when you need simple, low cost short linear actuation. Solenoids are electromagnetically driven actuators. When voltage is applied to the solenoid coil the electromagnetic force pulls the center plunger in. It is an excellent mechanical solution for all kinds of DIY projects requiring short quick linear actuation. Solenoids are most often found in latching and trigger-like mechanisms.

Project Parts List:


Device Sensor Shield Port
RobotGeek Pushbutton 1 Digital Pin 2
RobotGeek Pushbutton 2 Digital Pin 4
RobotGeek Relay Digital Pin 7

Arduino Solenoid Code:

You can download the code sketch here:

Feedback Form