Categories
Uncategorized

Solenoid Control Using Arduino

In this tutorial we are going to learn, how to control a Solenoid using Arduino. There are different types of Solenoids and every solenoid has different applications as per the requirement of the user like linear pull-push type(for wending machines), pull type(for door lock system), solenoid valve(which is used in water type projects), etc. So, in this tutorial i have used a Linear Pull-Push type Electromagnet Solenoid to explain you that how we can control all the solenoids using Arduino with simple steps.

This is our target.

Required Components

Before we start making the circuit, we must know the required components which are listed below:-

  1. 8×8 inch MDF board
  2. 1 x Arduino UNO
  3. 1 x Arduino Cable(USB A to USB B)
  4. 1 x Breadboard
  5. 1 x Solenoid
  6. 1 x TIP122 Transistor
  7. 1 x DC Female Jack
  8. 1 x 1N4007 Diode
  9. 1 x 1Kohm  Resistor
  10. 5 x Male to Male Jumper Wires

NOTE:- Here I have used a MDF sheet for the base of my circuit and a PULL PUSH type Solenoid to demonstrate you. So you can take any board for your circuit base and Solenoid as per your requirement.

Circuit Building

Let’s start building the circuit.

Step 1: Fix your Arduino and Breadboard

Here, I have fixed my Arduino UNO and breadboard on MDF (MDF is medium density fiberboard, which is basically engineered wood obtained by breaking down hardwood and softwood composites) board (you can use any insulated board for the base).

Step 2: Power up the Breadboard

Connect the female DC jack to the breadboard to power up the circuit.

Step 3: Common the Ground

We have to make the common ground of breadboard and Arduino, so that Arduino can control the solenoid (i.e. black jumper wire).

Step 4:- Placing 1N4007 Diode

Here, we have to use a 1N4007 diode because it never allows the current to flow in reverse direction, so that our components remains in safe side.

Step 5:- Connections of Solenoid

In this tutorial, I am using a PULL PUSH TYPE ELECTROMAGNET Solenoid (JF-0730B). You don't have to worry about its polarity. You can connect any wire in any direction. Here, I have connected one wire of solenoid to the anode(+ve) terminal of the diode and another wire of solenoid to the cathode(-ve) terminal of the diode.

Step 6:- Powering the Solenoid

To power up the Solenoid we have to give external power because Arduino is not capable of providing enough power to make the solenoid work. Therefore, we have connected a red wire jumper from the positive terminal of female DC jack to the cathode(-ve) of the diode as you can see in the image.

Step 7:- Connection of TIP122

Here, I am using TIP122 as a switch, because Arduino is not capable of controlling the solenoid directly. If we connect the Solenoid directly to the Arduino, either the Arduino's pin will get damaged or the Solenoid will get damaged because the Arduino is unable to provide the required current of the Solenoid.

Step 8:-Connect a resistor to TIP122

In TIP122, there are three pins namely base, collector and emitter. Here, I have connected 1Kohm resistor to the base pin of the TIP122 transistor as shown in the image.

Step 9:- Connection of TIP122 to Arduino

Take a jumper (i.e. brown jumper wire) and connect the digital pin number 2 of Arduino to the 1Kohm resistor which is directly connected to the TIP122 transistor(as you can see in the image). Here, Arduino will control the TIP 122 transistor.

Step 10:- Connection of TIP122 to Solenoid

Next we have to connect the collector pin of TIP122 transistor to the cathode(+ve) terminal of the diode (i.e. green jumper wire). Here, TIP122 transistor will control the Solenoid as per the instructions given by code burnt in the Arduino.

Step 11:- Make the TIP122 ground

Emitter is the last pin of TIP122, which we have to connect to the ground of the circuit (i.e. black jumper wire). Here, we have made the complete circuit.

Step 12:- Double check the connection

Please double check your connection properly.

Step 13:- Code Explanation 
The complete code for controlling the Solenoid with Arduino is given at the end of this explanation. Below we have mentioned the complete code to explain the working of the solenoid with Arduino.

Define the digital pin of Arduino

   int solenoid_pin = 2;                   //output pin of solenoid

Then we have to initialize the digital pin 2 of Arduino as an output pin for controlling the solenoid.

void setup() {
  
  pinMode(solenoid_pin, OUTPUT);         //set the pin as output pin
  
}

Now in void loop() we have to make our Solenoid work as PULL and PUSH continuously. 

void loop() {

  digitalWrite(solenoid_pin, HIGH);     //switch the solenoid ON
  delay(1000);                          //wait for 1 second 
  digitalWrite(solenoid_pin, LOW);      //switch the solenoid OFF
  delay(1000);                          //wait for 1 second
  
}

Below is the full code for controlling the Solenoid with Arduino.

int solenoid_pin = 2;                   //output pin of solenoid
void setup() {
  
  pinMode(solenoid_pin, OUTPUT);         //set the pin as output pin
  
}

void loop() {

  digitalWrite(solenoid_pin, HIGH);     //switch the solenoid ON
  delay(1000);                          //wait for 1 second 
  digitalWrite(solenoid_pin, LOW);      //switch the solenoid OFF
  delay(1000);                          //wait for 1 second
  
}
Working Video
Here is the fully working video of Solenoid Control Using Arduino.
Play Video

-Posted by Dev Narayan Chakrawarti & Helped by RISciTech Team. 

Leave a Reply

Your email address will not be published. Required fields are marked *