Stepper Motor Direction Control using Arduino

Hello friends! I hope you all will be absolutely fine and having fun. Today, I will elaborate you that how can we make a simple algorithm for Stepper Motor Direction Control using Arduino. In my previous tutorials I made algorithm for DC Motor Direction Control using Arduino, DC Motor Direction Control using Matlab, DC Motor Speed Control using Arduino and DC Motor Speed Control using Matlab. Now, in this tutorial I will control a stepper motor using Arduino by entering the different commands through its serial port. Before going into the detail of this tutorial, you must know the basic difference between stepper and DC motors. DC motors have only two input terminal one is positive and the other one is negative. You just have to provide the power supply and it will start rotating but this is not the case in stepper motor. The stepper motor which I will use in this tutorial, has six pins out of which four pins provide pulses or steps and the other two pins are power pins. So, in this tutorial I will control this six pins stepper motor using L298 motor controller and Arduino UNO board. Basically we can use stepper motor where precision is required. Stepper motor has wide range of applications e.g robotics, CNC machines, home automation etc. In simple word, we can say that stepper motor can be used where there is a need to move at particular angle. So, let's get started with Stepper Motor Direction Control using Arduino:

Stepper Motor Direction Control using Arduino

In this tutorial we will learn how to make a program for Stepper Motor Direction Control using Arduino by sending dfferent commands from the serial port. First of all, I am going share the list of components used for this mini project.
  • Arduino UNO
  • Stepper motor (6 wire)
  • L298 Motor Controller (H-Bridge)
  • Voltage Regulator (7805)
  • 1000uF
  • Jumper Wires
  • Solderig Iron
  • Soldering Wire
I want to tell you a bit about the stepper motor because all the other components are discussed in detail in DC Motor Direction Control using Arduino.
Stepper Motor
Basically, stepper motors are like the DC motors that rotate in discrete steps. They have multiple arranged coils and they are usually known as phases. Motor will rotate one step at a time if we energize each phase sequence. High levels of precision can be achieved by controlling the stepper motor with computer. Steppers motors are available in the market in many different sizes. The speed of the stepper motor is controlled by frequency of pulses generated. They have wide range of applications like hard disk drives, robotics, telescope, antenna, toys etc. A six wire stepper motor is shown in the figure below.  
  • You can download complete source code for Stepper Motor Direction Control using Arduino by clicking the below button:

Download Arduino Source Code

Selection of Wires
  • I have used 6 wire stepper motor and each wire has its own function.
  • I have first divided these six wires into two pair.
  • Each pair is consisting of three wires out of which one wire is common and the other two generate pulses.
  • The two pair of three wires are shown in the figure below.

  • Then, I have chosen a common wire in each pair from which the resistance to the other two wires is common.
  • I have checked the resistance from the common wire to the both of the other wires of the same pair.
  • I found that the resistance from the common wire to both of the other wires is same.
  • We can see in the figure above the blue, pink and white wires belong to the same pair out of which white is a common wire.
  • Here is the screen shot of the figure when I found the resistance between white and blue wire and I found it to be 8.0 ohms.
  • The screen shot of the above steps is shown in the figure below.
  • After that. I checked the resistance between white and pink wire and found it to be 8.1 which is almost the same as 8.0 so, this shows that the white wire is common to both of the blue and pink wire.
  • Here is the screen shot of the above step.
  • Then I found the resistance between pink and blue wire and it was 15.6 which is exactly the double of the earlier resistance.
  • It is shown in the figure below.
  • I have connect the both common wires as shown in the figure below.

  • Here's the video in which I have discussed it in detail How to identify the wires of Stepper Motor:
  • The remaining four wires are used to generate pulses which are also know as steps
  • I have connected theses four wires to the output pins OUT1, OUT2, OUT3 and OUT4 of the L298 micro controller.
  • Input pins of L298 micro controller In1, In2, In3 and In4 are connected to the pin no 7, 6, 5 and of the Arduino UNO's board respectively.
Note:

I have also controlled the stepper motor using PIC micro controller so I would suggest all of you to first go through that tutorial before going into the details of this tutorial.

Block Diagram
  • I have made a simple block diagram for Stepper Motor Direction Control using Arduino, which will be helpful to clearly understand the algorithm and the assembling of the components of Stepper Motor Direction Control using Arduino.
  • The screenshot of the block diagram is shown in the figure below.
  • First of all we need a power supply to run the project properly.
  • Arduino reads the commands from the serial port and sends to the L298 motor driver to rotate the stepper motor.
  • The commands got printed on the LCD (Liquid Crystal Display).
Arduino Source Code Description
  • The main function of the Stepper Motor Direction Control using Arduino is given below.
#include <LiquidCrystal.h>//Library for LCD
#include <Stepper.h> //Library for Stepper motor

const int stepsPerRevolution = 255;  

// initialize the stepper library on pins
Stepper myStepper(stepsPerRevolution, 4, 5, 6, 7);
char data;
//LCD pins assigning
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
void setup() {
  // set the speed at 60 rpm
  myStepper.setSpeed(60);
  // initialize the serial port:
  Serial.begin(9600);

lcd.begin(20, 4);//LCD type

lcd.setCursor(3,0);//setting LCD cursor and printing on it
lcd.print("Stepper Motor");
lcd.setCursor(5,1);
lcd.print("Direction");
lcd.setCursor(5,2);
lcd.print("Control");
lcd.setCursor(2,3);
lcd.print("via Arduino UNO");

delay(3000);

lcd.clear ();//Clearing the LCD screen

lcd.setCursor(0,2);
lcd.print("www.TheEngineering");
lcd.setCursor(4,3);
lcd.print("Projects.com");
}

void loop() {
  if(Serial.available())
  {
    data = Serial.read(); //Reading the data from serial port
  }
  
    if(data == 'C'){Clockwise();}//Clockwise rotation
    if(data == 'A'){AntiClockwise();}//Anti-clockwise rotation
    if(data == 'S')//stopping the stepper motor
    {
      data = 0; 
      lcd.setCursor(3,0);
      lcd.print("No rotation");}
    
}
  • In the code given above we have first initialized the LCD and Stepper motor libraries.
  • Then, I assigned stepper motor pins at which it is connected to the Arduino.
  • After that I initialized the LCD pins at which it is connected to Arduino UNO.
  • Then I have made three different if statements, for the clockwise, for the anti clockwise rotation and for the no rotation.
  • Then in the loop I called clock wise and anti clockwise functions whose source code will be give and explained below.
  • Then, I cleared the serial data in order to stop the rotation of the motor.
  • The source code of the clockwise function is given below.
void Clockwise()//function for clockwise rotation
{
    Serial.println("clockwise"); //printing on the serial port
    Serial.println("");//prints blank line on the serial port
    myStepper.step(stepsPerRevolution);//counter clockwise rotation
    lcd.setCursor(3,0);//setting LCD cursor
    lcd.print("Clockwise"); //printing on LCDa
}
  • The source code for the anti clockwise function is given below.
void AntiClockwise()//function for anti clockwise rotation
{
  Serial.println("anti-clockwise");//print on the serial
  Serial.println("");//prints a blank line on the serial
  myStepper.step(-stepsPerRevolution);//clockwise movement
  lcd.setCursor(3,0);//setting LCD cursor
  lcd.print("Anti-clockwise");//printing on LCD
}
  • Now, open your Arduino software, just copy and paste the source code given above.
  • Run the program and open the Serial Port at the top right of the Arduino software.
  • Now, when you enter the command stepper motor will start running in clockwise direction.
  • If you send the command through the serial port stepper motor will start to rotate in counter clockwise direction.
  • If you send the command the rotation of the stepper motor will be stopped.
Actual Hardware Setup
  • The actual hardware operating setup for Stepper Motor Direction Control using Arduino is given in the figure below:
  • Now, if you send the command  through the serial port the stepper motor will start to rotate in clockwise direction and the command will also be printed on the LCD.
  • The screenshot of the printed command on LCD is shown in the figure below.
  • Now, if you send the command  through the serial port the stepper motor will start to rotate in anti clockwise direction and the command will also be printed on the LCD.
  • The screenshot of the printed command on LCD is shown in the figure below.
  • Now, if you send the command  through the serial port the stepper motor will show no more rotation and the command will also be printed on the LCD.
  • The screenshot of the printed command on LCD is shown in the figure below.
  • Here's the complete video demonstration of Stepper Motor Direction Control using Arduino, I hope it will help as well:
That's all from the tutorial Stepper Motor Direction Control using Arduino. I hope you enjoyed this tutorial. If you face any sort of problem, you can ask me anytime without feeling any kind of hesitation. I will try my level best to solve your problem in a better way if possible. I will explore Arduino by making different projects on it. Till then, Take care :)

DC Motor Direction Control with Arduino in Proteus

Hello friends, hope you all are fine and having fun with life. Today, I am going to share DC Motor Direction Control with Arduino. I have designed a complete simulation in Proteus, which will help you in understanding the controlling of DC motor. I would recommend you to first read How to Control relay in Proteus ISIS which will help you in understanding the functionality of relays because in today's tutorial, I have used relays to do the DC Motor Direction Control. I have already posted a tutorial on DC Motor Drive Circuit in Proteus ISIS.

So, for DC Motor Direction Control, I have used Arduino UNO baord, so you should also download this Arduino Library for Proteus so that you can use Arduino boards in Proteus software. I have also provide the simulation and the code for DC Motor Direction Control but I would recommend you to design it on your own so that you learn from it. If you have any problem then ask in comments and I will try to resolve them. In this project, I have used Serial Terminal. So, whenever someone, sends character "C" on serial terminal then the motor will move in Clockwise Direction and when someone sends character "A" then it will move in Anti-clockwise Direction and will stop on character "S". Anyways, lets get started with DC Motor Direction Control with Arduino in Proteus ISIS.

DC Motor Direction Control with Arduino in Proteus ISIS

  • You can download the Proteus simulation for DC Motor Direction Control by clicking the below button:
Download Proteus Simulation for DC Motor

  • So, now let's move on with designing it, first of all get the below components from Proteus and place them in your workspace:
  • Now, design a circuit in Proteus software, as shown in below figure:
  • You can see in the above figure that I have used two relays which I have used for DC Motor Direction Control.
  • Moreover, there's a Virtual Terminal through which I am sending the commands.
  • I have used Arduino UNO board for DC Motor Direction Control through Virtual Terminal. You should download the Arduino Library for Proteus so that you can use it in Proteus.
  • Now upload the below code in your Arduino software and get the hex file. You should read how to get the Hex file from Arduino.
int Motor1 = 2;
int Motor2 = 3;

void setup() {
  pinMode(Motor1, OUTPUT);
  pinMode(Motor2, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  if(Serial.available())
  {
    char data = Serial.read();
    Serial.println(data);
    if(data == 'C'){MotorClockwise();}
    if(data == 'A'){MotorAntiClockwise();}
    if(data == 'S'){MotorStop();}
  }
}

void MotorAntiClockwise()
{
  digitalWrite(Motor1, HIGH);
  digitalWrite(Motor2, LOW);
}

void MotorClockwise()
{
  digitalWrite(Motor1, LOW);
  digitalWrite(Motor2, HIGH);
}

void MotorStop()
{
  digitalWrite(Motor1, HIGH);
  digitalWrite(Motor2, HIGH);
}
  • In the above code, I have designed three functions which I am calling on Serial receive.
  • The code is quite self explanatory but if you got problem then ask in comments and I will resolve them.
  • Once everything's done then run your simulation and if you have done fine then it will start working as shown in below figure:
  • Obviously, you can't see a moving DC motor in an image but you can get the idea from Relays position in above figure. :)
  • The below video will give you the better idea of How it works.

So, that's all for today. Hopefully now you have got the idea of How to do DC Motor Direction Control with Arduino in Proteus ISIS. In the next tutorial, I am gonna add speed control of DC Motor. So, till then take care and have fun. :)

Design a Buzzer in Proteus ISIS

Hello friends, hope you all are having fun and enjoying life. Today's post is quite a simple one and is about designing of circuit diagram of buzzer in Proteus ISIS. Buzzer is quite a common electrical component which is used in almost every Embedded Systems project. For example, you have seen a simple UPS, it gives a beep each time the light goes off or it has depleted its battery. Buzzer is normally used for given some indication and normally this indication is kind of a warning.

Proteus has a builtin component for buzzer and its an animated component means it gives a sound (beep) when its turned ON. So, I am gonna use that one and will give you an actual beep on it. So, it won't be much difficult and quite a simple procedure. In this post, I am not gonna interface it with any Microcontroller i.e. Arduino or PIC Microcontroller but if you want then you can quite easily control it using any of them. You simply need to give pulse to it and you can control it. If I get time then I will post the control of buzzer with Arduino. So, let's start with it.

Design a Buzzer in Proteus ISIS

  • First of all, get components from the Proteus library as shown in below figure:
 
  • Now after selecting these components, design a circuit diagram in Proteus as shown in below figure:
  • In the above circuit, I have used an optocoupler PC817 in order to control the buzzer.
  • The optocoupler is controlled by a simple logic operator, now when you change the logic operator from 1 to 0 the buzzer will turn on.
Note:
  • Optocoupler is working here on inverse logic i.e. when we send 1 then its OFF and when we send 0 then its ON.
  • If you are designing it on hardware then you can use PC817 Optocoupler.
  • So now if everything's fine then simply run the simulation and then click on the logic operator and you will get the below results:
  • You can see in the above figure, there are two states.
  • In the Buzzer ON state LED is OFF but the buzzer will be ON and you will hear a beep like sound, which obviously can't be heard here in the image. :)
  • While in the OFF state LED is ON but the buzzer will be OFF and you wont hear anything.
That's quite a simple tutorial and quite easy to understand but still if you have any problem, then ask in comments. Till next tutorial, take care and have fun.

Design a 5V Power Supply in Proteus

Hello friends, hope you all are fine and enjoying in your life. In the previous post, we have seen How to use Oscilloscope in Proteus ISIS, today I am going share a new and a very important Tutorial which is How to Design a 5V Power Supply in Proteus? This project is very simple and of basic level but importance of this project is that it is used as a base in almost all large electronics project, designed now-a-days. When I start working on any project then the first thing, I need to design is this DC power supply, because without powering up the components, we can't use them. :)

While designing a 5V Power Supply in Proteus ISIS, we will be using Voltage Regulator IC, which is commonly known as 7805. This voltage regulator is used to regulate or change the voltage level of supply voltage. As we all know, most of the batteries available in market are of 12 volts. For example, if you have UPS at your homes then check its battery, it will be of 12V. Similarly, the battery of car or motorcycle is also of 12V. So, 12V has become the standard of electrical batteries. Now, we have known that all batteries are of 12V but the problem comes when we are dealing with sensitive electronic components because they are all designed to operate on 5 volts. Now, as I described earlier that, voltage source available is 12 volts and the operating equipment needs 5 volts to operate. So, we need an intermediate source or such type of DC Power Supply, which can convert the source voltage (12 volts) to operating voltage (5 volts). This problem is eliminated by using 7805 IC, and that’s why it is called Voltage Regulating IC.

So dear Friends, today we will design a 5V power supply, which will be able to change Voltage Level and will provide us our desired voltage. But as I always say, that practice makes a man perfect. Try to design it yourself so that, you also get to know the real application of Voltage Regulator IC. So, let's get started with designing of 5V power supply in Proteus ISIS.

How to Design a 5V Power Supply in Proteus

  • You can download the complete simulation of 5V Power Supply in Proteus by clicking the below button:
Design a 5V Power Supply in Proteus

  • Voltage Regulating IC 7805 has 3 pins.
    • Pin # 1 is used as input pin and it is connected to supply voltages. It is marked as (VI). DC +12 volts are applied to this pin.
    • Pin # 2 is called common or ground pin. It is marked as (GND). The whole circuit's common is applied to this pin.
    • Pin # 3 is the output pin of 7805. If 12 volts are applied to its input than it automatically generates 5 volts on this pin. This pin is marked as (VO).
  • Now, moving towards the designing of the hardware, first of all place all the components in Proteus workspace, as shown in image below:
  • In Hardware implementation, first off all apply source voltage (12 volts) to the input pin of 7805 IC. 2 capacitors are also connected in parallel with the source voltage and their ratings are 1000 uf and 100pf respectively.
  • On the other side of IC, we also connect 2 capacitors parallel to the gained output voltage (5 volts), and their ratings are 100pf and 100uf respectively. And a LED is also connected in parallel on the load side.
  • If you have placed all the components in their perfect place and all the connections are OK, then the resultant proteus simulation will look like as shown in the below image:
  • Now if you closely observe the above image then you will notice that Capacitors connected across the 12 volts are of HIGH rating while the Capacitors connected across LED are of LOW rating. The purpose of applying capacitors is to remove noise from our DC voltages. As, we all know that DC voltage source available in market is not that much pure. So, to get pure DC wave Capacitors are connected across it.
  • Now when you will run the final simulation then it will look like, as shown in the image given below:
  • As you can see that when i ran the simulation, the LED started to glow. Now here is an important thing to note that i have applied a resistance in series with LED. The value of resistance is very low, and very low voltages appear across this resistor. This resistor limits the current and if we directly connect the LED then, their will be chances that the LED may burn out.
  • We can justify it as: From ohms law : V=IR, and by rearranging it, we get : I=V/R .
  • Now if we remove resistor then R=0, which means: I=V/0 and it lead us to conclude that: I= infinity or maximum in this case. So the only purpose of the resistor is to limit current.

Alright friends, that’s all for today, I hope now you can design a 5V power supply quite easily in Proteus. If you have some queries, then ask in comments. Subscribe us via email to get these tutorials straight in your inbox. In the next tutorial, I have discussed Variable Voltage Modulation using LM317 in Proteus ISIS.

 

LM317 Voltage Regulator in Proteus

Hello friends, hope you all are fine and having fun. In today's post we are gonna have a look at LM317 Voltage Regulator in Proteus. In the previous post, we have seen how to design a 5V Power Supply in Proteus ISIS, which I have designed using IC regulator 7805. Today I am going to share How to design LM317 Voltage Regulator Circuit in Proteus. This DC power supply is a variable one means you can set its output voltage to any level you want. In order to change its output value we have used a variable resistor and by changing its value you can change the output value. It is a basic level project and very simple but used as a base to design large industrial projects. In this project, we are going to control the speed of a DC Motor and the corresponding voltages, appearing across it. The reason for designing this variable DC power supply is that, when you are working on some engineering project then each electronic module has its own power level i.e. xbee module works on 3.3V while Arduino board works on 5V. So, there's a need to design such power supply which can provide variable voltages and we can set them according to our demand. So, for all Microcontrollers like Arduino or PIC Microcontroller or 8051 Microcontroller, I designed 5V Power supply using 7805 but for 3.3V modules like XBee, NRF24L01 etc I design this variable DC power supply using LM317. I hope now you got the importance of this LM317 Voltage Regulator.

To design this, we will be using LM317k. Basically, it is a Voltage Regulator IC. It has 3 pins. Pin # 2 is for input voltages, marked as VI. Pin # 3 is for output voltages, marked as VO, and pin # 1 is used for Regulating Voltages and it is marked as ADJ. Further, if you notice the circuit diagram, which is given in the figure, then you will see that pin # 1 is connected to a Potentiometer. Potentiometer is a Variable Resistor device and it is also known as Voltage Divider. The feature of this electronic device is that, we can adjust the voltage through it according to our own choice. It operates on 12 Volts and it gives us ease that, we can adjust its voltages from 0 to MAXIMUM (which is 12 volts in most cases). Further if we notice the circuit, then we will see that a LED is connected in parallel with a simple DC motor and a voltmeter is also connected in parallel with Motor to monitor the voltages appearing across it. Above information was a little demo about the individual components of the circuit, now let’s be practical and move towards Hardware and see how actually Electronic components respond. You should also have a look at Introduction to LM317, if you wanna read all the basics about it. So let's get started with LM317 Voltage Regulator in Proteus:

LM317 Voltage Regulator in Proteus ISIS

  • You can download this complete LM317 Voltage Regulator simulation by clicking the below button but I recommend you to design it on your own so that you learn most from it.

Download Proteus Simulation

  • First of all, place all the components in Proteus workspace, as shown in image:

  • A 12-Volt DC supply is provided to input pin (# 2) of LM317 and potentiometer is connected to Adjustable pin of LM317, which is, pin # 1.

  • At output pin we have connected DC Motor and a Voltmeter is also connected in parallel with Motor.
  • The complete circuit, ready for simulation is shown below in image:

Stage # 1
  • Set the potentiometer at 0% and run the simulation, you will notice that Motor will rotate very slowly in clock-wise direction and 1.25 volts will appear on the voltmeter across it. If all the connections are OK, and when you will run the simulation, LM317 Voltage Regulator simulation will look like as shown in the image below:

Note:
  • If you don't want to use the variable resistance, then you should use this LM317 Calculator to get value of your second resistance.
Stage # 2
  • Now, set the potentiometer value to 11% and you will see that, Motor will start to rotate with a faster rate and on voltmeter scale, we will see 6.40 volts. In this setting, the interesting thing is, LED will start to Flash and it will turn ON & OFF automatically. This phenomenon can be seen in images below:

  • Stage # 2 is our transient stage. When the potentiometers setting is below 11%, voltage appears across the motor and it also rotates but LED doesn’t glow. On the other hand, when potentiometers setting is above 11%, then LED glows continuously while motor also rotates as before, and voltmeter also gives some particular values of voltages appearing across the motor.
Stage # 3
  • Now at final stage, set potentiometer to 100% and you will observe that motor is rotating with full speed and voltmeter reading will be 10.6 volts while LED is glowing continuously. This stage of the simulation can be seen in the image below:

Now, we can conclude that, LM317 is the monitoring device of this circuit. We can set the value of potentiometer according to our own choice and by this, the speed of motor can be controlled and also the corresponding voltages, appearing across it.

Here's the video in which I have given the detailed introduction of LM317 and have also run its simulation:

Alright friends, that's all for today and I hope now you can easily design this LM317 Voltage Regulator. In the next post, I have discussed DC Motor Drive circuit in Proteus ISIS . Till than take care and be safe !!! :)

How to Control Relay in Proteus ISIS

Hello friends, hope you all are fine and having fun. In the previous posts, we have discussed DC motor Control in Proteus ISIS and after that we have discussed the Stepper Motor Control in Proteus ISIS and finally we had a look at Servo Motor Control in Proteus ISIS. Now when you talk about motors control then first thing came in mind is Relay, because relay is the best way of controlling any motor. In today's post, we are gonna have a look at How to Control Relay in Proteus ISIS. Relay is a key components of any electronics or electrical circuit and is usually a problem for the engineers and students. Although, its not as difficult as it seems so I thought to post about it.

In today's post, we will first simulate the Relay in a simple circuit in which when you run the simulation, the relay will automatically got activated and after that we will go in a bit detail and will control relay using a logic, i.e. when you provide +5V to it then the relay will go activated and when you give GNd then it will de-energize. I will explain it below in detail how to use it with Microcontroller. Moreover, if you are planning to work on Relay then you should also check What is a Relay and How to use it? and should also have a look at Relay Interfacing with Microcontroller using ULN2003 and finally must check this one as well Relay Control using 555 timer in Proteus ISIS.If you have any questions. related to it then ask in comments and I will try my best to reply your queries. Let's get started with designing of control relay in Proteus ISIS.

Simple Control Relay Circuit in Proteus ISIS

  • First of all, we are gonna simulate a simple control relay circuit in which we will manually turn on or off the relay.
  • Open Proteus ISIS and select the below components, as shown in below figure, from the components library of Proteus, if you don't know how to do it then check our earlier posts on Proteus.
  • Now, design a circuit as shown in below figure:
  • The circuit is self explanatory, first we have used a simple 12V battery to power up the simulation, after that there's a small led attached, which will indicate that whether proper power is supplied to the system or not. Next is our relay, which is named as RL1 in the above figure.
  • After the relay, we have placed a simple 12V lamp, so now when the relay will be energized, this lamp will glow up and when the relay is de-energized, the lamp will remain off. As in the above figure, the simulation is off, that's why the lamp isn't glowing.
  • After designing the circuit, now click on the run button and if everything goes fine, then the lamp will glow as shown in below figure:
  • So, now you can see the small led is also ON, I have used green that's why its showing green color indicating that power supply is working.
  • If you compare the off state and on state simulation then you will see that the Relay is now connected with second terminal and thus completing the circuit for lamp and lamp is also now glowing.

Complex Relay simulation in Proteus ISIS

  • Now, we are gonna design a bit more complex control  relay simulation in Proteus ISIS, it's not much complicated but needs a bit more care while simulating.
  • In previous section, we have seen a simple circuit which is operated manually means in order to turn it on or off you have to turn on or off the power supply but normally, it is required that the relay must be controlled by some microcontroller automatically.
  • As the microcontrollers normally work on 5V so in order to control a 12V relay using 5V microcontroller, we need to use transistor. In that case, when you give +5V the relay got actuated and when you give GND then relay get turned off.
  • So, first of all get these components from the Arduino components library.
  • Now, design the circuit as shown in the below figure:
  • As this tutorial is about relays so I haven't used microcontroller here, instead I used this logic state, it will work same as microcontroller. So the above circuit is quite similar to the simple circuit we have seen in the above section. The only difference here is the NPN transistor.
  • Now, we are not providing the supply directly to the relay, instead we are providing it via this transistor. So, when the logid state is zero means ground, the transistor won't work and the supply cant reached to the relay and when we make the logic 1 means +5V on the base of transostor, then the relay circuit will complete and the relay will be energized.
  • Now run the simulation, the off state is shown below:
  • In the above figure, you can see that the led goes on because the power is supplied to the circuit but the lamp is still OFF and the relay is also not energized because the logic state is a low level i.e. 0.
  • Now click on the logic state to make it on high level i.e. +5V, the on state is shown in below figure:
  • Now you can see that as we make the logic state high, now relay got connected and the lamp is also ON. So by comparing both ON and OFF states, you can easily get the idea how the relay is operating.
Note:
  • If you are planning on using the relay with microcontroller, then simply remove this logic state and connect the base of transistor with the output pin of microcontroller and when you low the microcontroller pin relay will get de energized and and when you make the pin high, it will get energized.
    • That's all for today, hope you have got something out of it. In the next post I will show how to simulate a DC motor using relay. Till then take care. :))
Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir