Controlling a Solenoid with Arduino

When it’s time to take your Arduino project into the “real world,” beyond light, radio waves, and sound, you’re going to need an actuator. Most actuators use a rolling element of some kind, which then translates into linear motion as needed. But what about creating that linear motion directly?

What is a Solenoid Used For?

If your application depends more on speed than it does on force, solenoids can be a great choice. Pairing a solenoid with an Arduino board is simple as well; as electromagnets, they only need the proper amount of voltage and current to pull them from a resting state into an activated position.

Caption: Tiny Solenoid, substantial voltage and current requirements.

The trick to using solenoids is getting the numbers right. These devices they take a good amount of current to run, voltages that are generally higher than what Arduino boards can provide. As seen in the image above, even the tiny solenoids we used in this project setup took 700mA at 12V to actuate, far above the 5V output and 20 mA per pin for which the Arduino UNO is rated. For proper actuation, you’ll need a transistor setup. As we’ll discuss later, you can use a motor shield.

Arduino-Control Current Output: Transistor Activation

To Arduino-control a solenoid you’ll need a way to control a lot of current with the board’s limited control outputs. That sounds like an ideal job for a transistor. In this case, we’ll be using a TIP120 Power Darlington transistor. Hook up the circuit as shown below and in the first image on this article, noting that a 5V USB source powers the Arduino, linked to the solenoids via ground and output pins alone.


Caption: Solenoids set up with an Arduino Uno

Arduino outputs 11, 12, and 13 connect to the transistor’s base through a 1000 ohm resistor. Here’s how to set it up:

1. Hook each transistor’s collector to one solenoid lead and plug the other solenoid lead into a common positive voltage.

2. On the collector lead, run a diode (1N4007 or another appropriate device) to a positive line. This will only allow voltage flow into the positive bank to account for electrical discharge (or kickback) from the solenoid when it turns off.

3. Connect the emitter leg of the transistor to ground.

4. Power the transistor/solenoid assembly with the appropriate power supply (12V in this setup).

5. Power the Arduino separately using USB or another source.

6. Wire the Arduino’s ground pin to the board’s ground and wire each Arduino output to the appropriate resistor and transistor.

7. Program your Arduino with this sketch. When you apply power, the solenoids will click away in sequence.

Using a Motor Shield as an Arduino Solenoid Driver


Caption: 12V solenoids driven by Arduino Uno with the motor shield.

As far as an Arduino board goes, a solenoid operates the same way as a motor. In reality, a solenoid is even simpler. When it comes to arranging the leads; positive and negative orientation doesn’t matter. Therefore, to use a motor shield as an Arduino solenoid driver, all you need to do is connect the leads to where a motor would go and run the appropriate program. Here’s the process:

1. For the Adafruit Motor Shield I used, you’ll need to download and install the library. You can also find an updated “V2” version of the shield with its own separate library.

2. Once you install the library, run this code to make your solenoids click away.

You can modify the timing or other features to your liking, or add or subtract solenoids in the setup() routine as needed. Note that the speeds are all set to 255 to allow the magnets to pull as hard as possible. Note that most of the solenoids are set to run in a FORWARD direction, while solenoid2 is set to run BACKWARD. This illustrates that +/- wire orientation isn’t important when working with solenoids. If you prefer, other external H Bridge modules are also available that integrate with Arduino or other microcontroller boards in a similar manner.

What is a Solenoid Valve?

Solenoids can act quickly, but force is not their strong suit. Besides directly activating objects, another excellent use for solenoids is to actuate air valves, much like the way a relay activates a high-power line. These so-called solenoid valves use a small amount of force from electromagnets to shift the flow of compressed air to do the literal heavy lifting. Air valves can activate quickly and with impressive force.

You’ll see solenoid valves most commonly at use in manufacturing setups. In these applications, when the solenoid stopper inside the valve moves into one position, the three-way solenoid valves push a piston forward. You can accomplish the same task with Arduino, but you’ll need to supply the proper voltages and current for your application.

최신 뉴스

Sorry, your filter selection returned no results.

개인정보 보호정책이 업데이트되었습니다. 잠시 시간을 내어 변경사항을 검토하시기 바랍니다. 동의를 클릭하면 Arrow Electronics 개인정보 보호정책 및 이용 조건에 동의하는 것입니다.

당사의 웹사이트에서는 사용자의 경험 향상과 사이트 개선을 위해 사용자의 기기에 쿠키를 저장합니다. 당사에서 사용하는 쿠키 및 쿠키 비활성화 방법에 대해 자세히 알아보십시오. 쿠키와 추적 기술은 마케팅 목적으로 사용될 수 있습니다. '동의'를 클릭하면 기기에 쿠키를 배치하고 추적 기술을 사용하는 데 동의하는 것입니다. 쿠키 및 추적 기술을 해제하는 방법에 대한 자세한 내용과 지침을 알아보려면 아래의 '자세히 알아보기'를 클릭하십시오. 쿠키 및 추적 기술 수락은 사용자의 자발적 선택이지만, 웹사이트가 제대로 작동하지 않을 수 있으며 사용자와 관련이 적은 광고가 표시될 수 있습니다. Arrow는 사용자의 개인정보를 존중합니다. 여기에서 당사의 개인정보 보호정책을 읽을 수 있습니다.