PIR Sensor Arduino Interfacing

Hello everyone! I hope you all will be absolutely fine and having fun. Today, I am going to provide the detailed discussion on PIR Sensor Arduino Interfacing. PIR basically stands for Passive Infrared Sensor. Basically PIR is an electronic equipment which is often used to measure the infrared light radiating from the different objects in their field of view. It detects the infrared energy released from animals as well as from human beings, when this energy is higher than the certain threshold level PIR sensor shows an indication correspondingly. The energy detected by PIR sensor is usually in the form of heat i.e. emitted by humans as well as from animals. We can also test and verify our results in Proteus using PIR sensor. I have already shared PIR Sensor Library for Proteus. PIR sensor is most of the time used for sensing the motion of the different objects. It can sense the different objects up to 10 meters. It has three different pins. Each pin is assigned with the different task to be performed when the sensor is in working condition. PIR sensor has several different features like wide voltage supply ranges, automated induction, photosensitive control, low micro-power consumption, high output signal and many more. PIR (Passive Infra Red) sensor is most of the time used in security systems. Moreover, it can be used in OEM applications, automatic illuminating devices, building detection, building automation, alarm & security systems and at a lot more places in real life. The further detail about PIR Sensor Arduino Interfacing will be given later in this tutorial.

PIR Sensor Arduino Interfacing

PIR sensor stands for Passive Infra Red sensors. As it is clear from its name that PIR is an electronic device or sensor used to measure the infrared energy emitted by animals and human beings. This energy is emitted in the form of heat. When this energy is above the certain level, there is algorithm to show an an indication that the desired level has be reached. This tutorial is based on PIR interfacing with Arduino. PIR sensor is shown in the figure below along all of its pin names.
1. PIR Sensor Pins
  • PIR sensor has three pins voltage, output and ground respectively.
  • All of the pins are provided in the table shown in the figure given below.
2. PIR Sensor Pins Description
  • Each pin has different task to perform while the sensor is in working condition.
  • PIR sensor pin descriptions are listed in the table shown in the figure below.
3. PIR Working Principle
  • PIR sensor has two different slot which are sensitive to infrared light/energy.
  • When the sensor is in normal condition, both of the slots measure the same amount of infrared energy radiated by walls etc.
  • When a warm body e.g animals and human beings crosses its coverage area, they first cross PIR sensors's first slot, which produces positive differential change between two slots.
  • When an animal or human being leave from the sensing area, a corresponding negative differential change is produced.
  • By detecting these types of changes PIR sensor can detect the motion of different objects which radiates infrared energy.
  • I have tried to elaborate the PIR working principle through some visuals shown in the figure given below.
  • I have also provided the visuals about how PIR sensor generates an output signal after sensing different objects/
  • PIR sensor object sensing is given in the figure shown below.
4. PIR Sensor Schematic Diagram
  • To understand the internal structure of any electronic device, we must have a look at its schematic diagram.
  • PIR sensor schematic diagram is shown in the figure given below.
5. Apparatus Required
A list of apparatus required for PIR interfacing with Arduino is given below.
  • PIR (Passive Infra Red) Sensor
  • Arduino (Microcontroller)
  • Jumper wires
6. PIR Interfacing with Arduino Wiring Diagram
  • I have already shared a brief article on Interfacing PIR sensor with Arduino.
  • Now, this is a detailed article about the similar topic.
  • I have provided wiring diagram for PIR interfacing with Arduino.
  • You can make the similar wiring diagram and can test and verify your results as well.
  • PIR Sensor Arduino Interfacing wiring diagram is shown in the figure given below.
7. PIR Sensor Arduino Interfacing Source Code and Description
  • If you have never use Arduino software for programming then you should first go through How to Write Arduino Code.
  • I have provided the complete source code for PIR interfacing with Arduino.
  • You just need to copy and paste the entire code and upload it to your Arduino board and observe the results.
  • You can also made the same simulation on Proteus as well and can verify the results.
  • In case of Proteus simulation you must need to know about How to get Hex File from Arduino.
int LED = 13;                
int inputPin = 2;               
int PIR_STATE = LOW;             
int VALUE = 0;                   
 
void setup() {
  pinMode(LED, OUTPUT);      
 
  Serial.begin(9600);
}
 
void loop(){
  VALUE = digitalRead(inputPin); 
  if (VALUE == HIGH) {           
    digitalWrite(LED, HIGH); 
    if (PIR_STATE == LOW) {
      // we have just turned on
      Serial.println("Motion has been detected!");
      PIR_STATE = HIGH;
    }
  } else {
    digitalWrite(LED, LOW); 
    if (PIR_STATE == HIGH){
      // we have just turned of
      Serial.println("Motion has been stopped!");
      PIR_STATE = LOW;
    }
  }
}
  • I have initialized the LED pin, PIR state pin and the pin and a variable for reading sensor's data.
  • Then I have checked whether the detected value from the sensor is above or below the certain level.
  • Then I have decide to be print the certain values on Serial Monitor.
  • If it is above the certain level a message "Motion has been detected" will be displayed on the serial monitor through Serial Communication.
  • If the detected value is below the certain level then the message "Motion has been stopped" will be displayed on the serial monitor in Arduino software.
  • So, that was the brief description of the source code designed for PIR interfacing with Arduino.
  • You can download the complete wiring diagram along with the complete Arduino source code here by clicking on the button below.

8. PIR Sensor Interfacing with Arduino Actual Circuit Diagram
  • I have also provided the actual circuit diagram for PIR interfacing with Arduino.
  • Actual circuit diagram is shown in the figure given below.
9. PIR Sensor Ratings
  • To know the power, current and voltage requirements of an electronic device can be known through its ratings.
  • PIR sensor ratings are listed in the table given in the figure shown below.
10. PIR Sensor Features
  • A device can be popular on the basis of its amazing and unique features, which make it different from other devices.
  • PIR sensor some of the main features are listed in the table given in the figure shown below.
11. PIR Sensor Applications
  • PIR sensor has several different real applications.
  • Some of common applications associated with PIR sensor are provided in the table shown in the figure given below.
  • I have provided a circuit designed for security alarm system, which is its most common application.
  • The complete circuit design for security alarm system is given in the figure shown below.
  • PIR sensor's another application is making a timer circuit using PIR.
  • I have provided timer circuit using PIR sensor, shown in the figure given below.
  • Another most common application of PIR sensor is the motion detection.
  • Motion detection circuit diagram using PIR sensor is shown in the figure given below.
12. PIR Sensor Advantages
  • There are a lot of advantages associated with Passive Infrared Sensor, few of them are given below.
13. PIR Sensor Disadvantages
  • Infrared sensors also have some disadvantages but they are in a very small as compared to its disadvantage.
  • Infrared sensor disadvantage are listed in the table given in the figure shown below.
The tutorial PIR Sensor Arduino Interfacing has provided the detailed discussion about the interfacing of PIR sensor with Arduino. If you feel any problem in PIR Sensor Arduino Interfacing, you can ask me in comments anytime. I will try me level best to entertain you and to solve your problems. I will share further informative topic in my later tutorials. Till then take care and bye :)

Flame Sensor Arduino Interfacing

Hello everyone! I hope you all will be absolutely fine and having fun. Today, I am going to provide a detailed discussion on Flame Sensor Arduino Interfacing. Flame sensor is an electronic device which is capable of sensing/detection of fire or a high temperature zone. It gives an indication through an LED attached at its top, just after sensing the fire. These type of sensors are usually used for short ranges. They are able to detect the fire up to 3 feet. Flame sensors is the most common device available in the market these days due to its good results and cost efficiency. You should also have a look at Flame Sensor Library for Proteus. Flame sensors are available in the market in two types one having three pins and the other having four pins respectively. Both of the sensors can be easily interfaced to any micro-controller. I am using four pin flame sensor in this tutorial. You will see the complete wiring diagram for interfacing flame sensor with Arduino and the complete Arduino source code and its description as well. Flame sensor can detect fire or any other light sources whose wavelength is in the range of 760nm to 1100nm. This device consists of and IR sensor, an LED for indication, operational amplifier circuit and a potentio-meter. The device is sensitive to flame so when it detects the flame it turns on its LED to show an indication. The sensitivity of the flame sensor can be adjusted according to the requirements. It can be used at different places e.g. in offices, home, institutions, industrial applications.

Flame Sensor Arduino Interfacing

Flame Sensor is an electronic device which is used to sense the fire or any other light having wavelength between 700nm to 1100nm. It consists of either three or four pins both of them are compatible with all micro-controllers. It is sensitive to flame and gives the indication for the presence of the flame. It can be sued in homes, offices, industrial applications. Flame sensor along with its pi names are shown in the figure below.
1. Flame Sensor Pins
  • Flame sensor has four pins with different individual function.
  • Flame sensor pins are given in the figure shown below.
2. Flame Sensor Pins Description
  • Each pin has different tasks to perform.
  • Flame sensor pin descriptions are listed in the table shown in the figure given below.
3. Flame Sensor Working Principle
  • Flame sensor is very sensitive to flame and other lights.
  • Its analog output provides real time output voltage on the thermal resistance.
  • When the temperatures reaches at the certain threshold the output high and low signal threshold adjustable via potentio-meter , Its the task of digital output.
4. Flame Sensor Circuit Diagram
  • Flame sensor diagram is shown in the figure given below.
5. Apparatus Required for Flame Sensor Interfacing with Arduino
  • Arduino UNO (Micro-controller)
  • Flame Sensor
  • Jumper wires
  • Wero board
  • Light or another flame sensor
6. Flame Sensor & Arduino Pin Connections
  • Connections between Arduino and flame sensor pins are given in the table shown in the figure below.
7. Flame Sensor Arduino Interfacing - Wiring Diagram
  • Before hardware interfacing, you can also test your result on Proteus.
  • For Proteus simulation, you need to know about How to get Hex File from Arduino.
  • I have shared a brief tutorial on Interfacing of Flame Sensor with Arduino in my previous tutorial.
  • I have given a completely labeled wiring diagram for Flame Sensor Arduino Interfacing.
  • You can test & verify your results by making the same wiring diagram.
  • Wiring diagram for Flame Sensor Arduino Interfacing is shown in the figure given below.
8. Flame Sensor Interfacing with Arduino Source Code & Description
  • If you haven't written Arduino code ever, you must go through How to Write Arduino Code.
  • You just need to copy & to paste the complete source code given below in your Arduino software.
  • And just upload the code onto your Arduino board in order to verify the results.
int led_pin = 13 ;// initializing the pin 13 as the led pin

int flame_sensor_pin = 2 ;// initializing pin 7 as the sensor output pin
int flame_pin = HIGH ; // state of sensor

void setup ( )  {

  pinMode ( led_pin , OUTPUT ); // declaring led pin as output pin
  pinMode ( flame_sensor_pin , INPUT ); // declaring sensor pin as input pin for Arduino
  Serial.begin ( 9600 );// setting baud rate at 9600
}

void loop ( ) {
   flame_pin = digitalRead ( flame_sensor_pin ) ;  // reading from the sensor
  if (flame_pin == LOW )  // applying condition
  {
    Serial.println ( " FLAME , FLAME , FLAME " ) ;
    digitalWrite ( led_pin  , HIGH ) ;// if state is high, then turn high the led
  }
  
  else
  {
    Serial.println ( " no flame " ) ;
    digitalWrite ( led_pin , LOW ) ;  // otherwise turn it low
  } 
}
  • First of all I have defined the pins for led and the flame sensor.
  • The I have printed the digital information on the Serial Monitor obtained from the flame sensor.
  • The messages are displayed on the serial monitor via Serial Communication.
9. Flame Sensor Interfacing with Arduino
  • The actual circuit diagram for flame sensor interfacing with Arduino.
10. Flame Sensor Applications
  • Flame sensor has a lot of different applications.
  • Some of them are given below.
The tutorial Flame Sensor Interfacing with Arduino has explained the entire necessary detail about the flame sensor interfacing with Arduino. If you have any kind of problem you can ask me in comments anytime. I will try my level best to solve your issues. I hope you have enjoyed this tutorial. I will share other informative topics in my upcoming tutorials. Till my next tutorial take care and bye :)

Arduino Keypad Interfacing

Hello everyone! I hope you all will be absolutely fine and having fun. Today, we are going to work on Arduino Keypad Interfacing. First of all, I would like to tell you a bit about the keypad. After getting the basic idea about the keypad, we will start our discussion about Arduino Keypad Interfacing.  You should also have a look at Interfacing of Keypad with PIC Microcontroller.

In this tutorial, I am going to use a 4×4 keypad. It has sixteen buttons having four alphabetic characters. Let's have a look at the Arduino Keypad Interfacing:

Where To Buy?
No.ComponentsDistributorLink To Buy
1Jumper WiresAmazonBuy Now
2Keypad 4x4AmazonBuy Now
3Arduino UnoAmazonBuy Now

What is Keypad?

  • The keypad consists of multiple buttons, arranged in the form of a matrix(rows & columns) and is used in embedded projects.
  • They are cost-efficient and are easily available from online electronic stores.
  • Keypads are normally available in a 3×3, 4×3 and 4×4 format.
  • Keypad has several applications in real life based projects e.g. mobile phones, calculators, laptops, personal computers, television remote, toy remote, microwave oven, photocopy machine, bank’s ATM machine, tablets and a lot more.
  • A simple 4x4 Keypad is shown in the figure given below:
 

Keypad Pinout

  • I am using a 4×4 keypad in this tutorial, it has total of eight (8) pins.
  • All of these pins are provided in the table shown in the figure below:
  • From the above table, we can see that keypad’s first four pins are associated with its four rows.
  • The last four pins are assigned to the four columns of the keypad.
  • 4×4 Keypad’s pins functions are listed in the table provided in the figure given below.

Components Required for Arduino Keypad Interfacing

  • Components required for this project are:
    • Arduino UNO.
    • 4x4 Keypad.
    • Jumper Wires(Male to Female).

Keypad & Arduino Connections

  • The connections between the keypad and Arduino are provided in the figure given below:

Circuit Diagram of Keypad Arduino Interfacing

  • I have made a circuit diagram for keypad interfacing with Arduino.
  • A complete labeled circuit diagram is given in the figure shown below:
  • You can make a similar diagram and can easily test & verify your results on the serial monitor.

Arduino Code

  • You just need to copy this code into your Arduino software.
  • After successfully uploading the code to your Arduino board you will be able to verify the results.
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

void setup(){
  Serial.begin(9600);
}
  
void loop(){
  char customKey = customKeypad.getKey();
  
  if (customKey){
    Serial.println(customKey);
  }
}
  • First of all, I have defined the number of rows and columns of the keypad.
  • Then I have declared the complete keypad characters in terms of rows and columns.
  • After that, I have defined the row and column pin of the keypad attached to the Arduino pins.
  • Then I have simply read the data sent from the keypad and displayed it on the serial monitor.
  • You can download a completely labeled wiring diagram and Arduino source code here by clicking on the below button:
Wiring Diagram & Arduino Code

In the tutorial Keypad Interfacing with Arduino, I have explained the basics of the keypad as well as the keypad interfacing with Arduino UNO. I have tried my level best to cover up all the necessary information. If you found something missing, please let me know then. I will update my tutorial correspondingly as soon as possible. I hope you have enjoyed the complete tutorial and I am hoping for your positive response. If you have any problem you can freely ask as in comments anytime. I will share different topics in my upcoming tutorials. Take care and bye till the next tutorial :)

Servo Motor Control using Arduino

Hello everyone! I hope you all will be absolutely fine and having fun. Today, I am going to tell you about how to design an algorithm for Servo Motor Control using Arduino. First of all I would like to tell you a bit about the servo motors. Servo motors are small devices having an output shaft. We can adjust this shaft in different angular positions by continuously sending the servo coded signal. Servo motor maintains the angular position of the shaft as long as the coded signal is present at the input. If the applied coded signal changes, angular position of the shaft of a servo motor also changes correspondingly. If you are working on Servo Motor then i would suggest you to must have look at this tutorial Servo Motor control in Proteus, as its always a best practice to design simulation first. In my previous tutorials I have controlled the direction and speed of the both DC as well as of the stepper motor. Ordinary DC motor has only two input terminals. When power is supplied it simply starts to rotate continuously. In comparison to the DC motor servo motor has three wires. Using servo coded signal we can send commands to the servo motor that in what direction and with what angle it has to rotate. If we want to add motion in our electrical projects, servo motor will be an easy way to do so. Servo motor has a wide range of applications in our daily life e.g elevator, cars, robotics, puppets, remote controlled airplanes and cars, conveyor belts, solar tracking system, antenna positioning, textiles etc.Moreover, I have also controlled the Servo Motor with PIC Microcontroller, so if you are using PIC Microcontroller then have a look at that one.

Servo Motor Control using Arduino

In the tutorial Servo Motor Control using Arduino, I will tell you step by step procedure for connecting the servo motor with Arduino and how to design a algorithm in Arduino software to control its angular position with the help of servo coded signal. First of all I would like to tell you about the hardware components necessary for Servo Motor Control using Arduino.
  • You can download the complete Arduino source code here by clicking on the button below.

  • Just download .rar file, extract it and enjoy the complete source code.
Hardware Required
A complete list of the hardware equipment necessary for this task is given below.
  • Computer/Laptop
  • Arduino UNO (Micro Controller)
  • Appropriate USB Cable
  • Servo Motor (4.8 to 6.0V with 2.5 kgf-cm torque)
  • Jumper Wires (Cables)
Arduino UNO acts as the backbone of this task. It sends the servo encoded signal to the servo motor to control its angular movement. Arduino UNO board is shown in the figure below. Servo Motor having torque of 2.5kgf-cm and 4.8-6.0v is used for this project. The selected servo motor is shown in the figure below. Power of 5V is supplied to the servo motor from the Arduino UNO board. Jumper Wires are used to make the connections of the all the components in order to make the complete circuit with proper working. Jumper wires are shown in the figure below.
Circuit Diagram
  • The circuit diagram for Servo Motor Control using Arduino is shown in the figure below.
  • I have supplied 5V to red wire of the servo motor as shown in the above figure.
  • The black wire is the attached to the GND pin of the Arduino UNO.
  • Yellow wire is basically the wire used to control the angular motion as well as the angle of the servo motor.
Source Code Description
  • The complete Arduino source code for Servo Motor Control using Arduino is given below.
  • You have to just copy the code given below and to past it in your Arduino software.
  • By uploading the source code to your Arduino board you will be able to control the servo motor using Arduino.
#include <Servo.h> //library for servo motor

Servo myservo;  // servo motor object for its control

int ang = 0;    // a variable to store the servo angle

void setup() {

  Serial.begin(9600);
  
  myservo.attach(8);  // servo motor is attached to pin no 8 og Arduino

}

void loop() {

  for (ang = 0; ang <= 180; ang += 5) // goes from 0 degrees to 180 degrees with a step og 5 degree
  { 
    myservo.write(ang);              // rotates the servo to rotate at specific angle
    delay(50);     // adding delay of 50 msec
    Serial.println("Motor has started its rotation from 0 to 180 degress");
      }
  for (ang = 180; ang >= 0; ang -= 5) // goes from 180 degrees to 0 degrees with a step of 5 degree
  { 
    myservo.write(ang);              // rotates the servo to rotate at specific angle
    delay(50);                      // adding delay of 50 msec
    Serial.println("Motor has started its rotation from 180 to 0 degress");
      }
}
  • First of all I have inserted the library for servo motor.
  • Then I have created a servo object and declared the initial angle of the servo motor.
  • After that I have have adjust the baud rate, the rate at which Arduino communicates with the laptop/computer.
  • Then I have defined the pin at which the servo motor is attached to the Arduino UNO's board.
  • Inside the main loop, I have applied the condition that in between 0 and 180 degrees, the servo motor's angle will be increased with different steps and each step has 5 degrees of angular movement.
  • When maximum limit is reached, the angle will be reduced from 180 to 0 degree with different steps, each step having 5 degrees of angular movement.
  • That was the brief description of the Arduino complete source code designed for Servo Motor Control using Arduino.
That is all from the tutorial Servo Motor Control using Arduino. I hope you all have enjoyed this tutorial. If you face any sort of problem you can ask me freely in comments any time you want without even feeling any kind of hesitation. I will try my level best to solve your issues in a better way, if possible. I will explore Arduino by making different projects on it and will share all of them with all of you as well in my later tutorials. Till then, Take care :)

Stepper Motor Speed Control using Arduino

Hello everyone! I hope you all will be absolutely fine and fun. Today, I am going to tell you that how to make a simple algorithm for Stepper Motor Speed Control using Arduino. I have already discussed with you about DC Motor Direction Control using Arduino, Matlab and NI LabVIEW. Moreover, I have also discussed the DC Motor Speed Control using Arduino,Matlab and LabView. If you are working on Stepper Motor, then you must have a look at Stepper Motor Direction Control using Arduino, Stepper Motor Direction Control using Matlab and Stepper Motor Direction Control using NI LabVIEW. Now, in this tutorial I will explain you about the program which will helpful for Stepper Motor Speed Control using Arduino. Before going into the details of this tutorial you must have go through my previous tutorials because I am using the same hardware. So, they will be a lot helpful for the better understanding of this tutorial. In this tutorial I will explain you about making an Arduino program for Stepper Motor Speed Control using Arduino with the help of the serial communication. If the stepper motor is rotating at its maximum speed and you are continuously sending the command through the serial port to reduce its speed, it s speed will be reduced in proportion to the number of command sent through the serial port. Similarly the same procedure will be followed to increase the speed of the stepper motor.

Stepper Motor Speed Control using Arduino

In the tutorial Stepper Motor Direction Control using Arduino, I will explain you about making an algorithm to run the stepper motor at different speed. If the stepper motor is already running at its maximum speed and you want want to accelerate it further then nothing will happen to the speed of the stepper motor. If the stepper motor is rotating slowly and you enhance its speed, then the speed of the motor will increase in proportion to the number of accelerating command sent through the serial port.
  • You can download the complete Arduino source code here by clicking on the button below.

Download Arduino Code

  • Download .rar file, extract it and enjoy the complete source code.
Flow Chart
  • I have made a flow chart so that you can easily understand the entire algorithm because sometimes it becomes difficult to understand the algorithm with the help of the source code.
  • Flow chart for the Stepper Motor Speed Control using Arduino is shown in the figure below.
  • First of all we need to start the serial port so that our communication could be started.
  • Then there is a method to check the speed, if the speed is greater than the maximum speed of the stepper motor then the program will wait for the next command.
  • If the stepper motor is not rotating with its maximum speed then we can increase its speed.
  • Similarly if the minimum speed of the stepper motor is reached then the program will rotate for the next commands.
  • If the minimum limit of the speed of the stepper motor is not reached then we have a option to reduce its further.
  • At the end we should close the serial port so that exchange of unnecessary commands through the serial port could be avoided.
Block Diagram
  • Block diagram will be helpful for use for the better understanding of the exchange of information.
  • It tells us that how the information is exchanged sequentially among all the components used.
  • Block diagram is shown in the figure below.
  • Arduino UNO communicates with the L298 motor controller to control the speed of the stepper motor.
  • L298 Motor controller manipulates the Arduino's commands and starts to control the speed of the stepper motor.
Arduino Code Description
In this section of the tutorial Stepper Motor Speed Control using Arduino, I am going to elaborate you about the Arduino source.
  • I have made two different functions for increasing (accelerating) the speed of the stepper motor and for decreasing (deaccelerating) the speed of the stepper motor respectively.
  • I have declared a variable named as count.
  • In Accelerate function, you have to send the command through the serial port to increase the speed of the stepper motor.
  • In this function, I am continuously increasing the value of the count i.e as many times you send the command the speed of the stepper motor will increase continuously.
  • The source code of the Accelerate function is given below.
   void Accelerate_Motor()
   { 
    count=count+10; //Speed will increase continuously as we continue to press H
    if (count>120)  //Speed must not be greater than 120
    {
      count=120;
      }
    Serial.println("Accelerating"); //printing on the serial port
    Serial.println("");//prints blank line on the serial port
    myStepper.step(stepsPerRevolution);//counter clockwise rotation
    myStepper.setSpeed(count); //Updating the speed of the motor
    lcd.setCursor(3,0);//setting LCD cursor
    lcd.print("Acelerating"); //printing on LCD
   }
  • In Deaccelerate function, you have to send the command through the serial port to increase the speed of the stepper motor.
  • In this function, I am continuously reducing the value of the count i.e as many times you send the command the speed of the stepper motor will reduce continuously.
  • The source code of the Deaccelerate function is given below.
void Deaccelerate()
{
  count=count-10; //reducing the speed of the motor
  if (count<20) //speed of the motor must not be less than 20
  {
    count=20;
    }
  Serial.println("Deaccelerating"); // prints on the serial port
  Serial.println(""); //prints blank line on the serial port
  myStepper.step(stepsPerRevolution);
  myStepper.setSpeed(count); //Updating the speed of the motor
  lcd.setCursor(3,0);  //setting cursor on LCD
  lcd.print("Deaccelerating"); //prints the command on LCD
  }
  • In the main source inside the loop I am calling both of these Accelerate and Deaccelerate functions.
  • The executed commands will also be printed on the LCD (Liquid Crystal Diode).
  • The main source code 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;
int count = 120;
//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);// rate at which the arduino communicates

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

lcd.setCursor(3,0);//setting LCD cursor and printing on it
lcd.print("Stepper Motor");
lcd.setCursor(6,1);
lcd.print("Speed");
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");
      Serial.println("No rotation");//print on the serial
      }   
     if(data == 'H'){Accelerate_Motor();}
     if(data == 'L'){Deaccelerate();}
}
Complete Hardware Setup
  • In this section of the tutorial, I will show you the complete hardware setup that I have used for this project.
  • Hardware consists of 12V power supply, Arduino UNO, L298 motor controller.
  • When you upload the code to the Arduino board the system will look like the figure shown below.
  • When you press to increase the speed of the stepper motor, the statement accelerating will be printed on the LCD.
  • The printed executed command is printed on the LCD and is shown in the figure below.
  • When you press to reduce the speed of the stepper motor, the statement Deaccelerating will be printed on the LCD.
  • The printed executed command is printed on the LCD and is shown in the figure below.
That is all from the tutorial Stepper Motor Speed Control using Arduino. I hope you all have enjoyed this tutorial. If you face any sort of problem regarding anything you can ask me anytime without even feeling any kind of hesitation. I will try my level best to solve your issues in a better way if possible. I will explore Arduino by making further projects and I will share them with all of you as well in my later tutorials. So, till then, Take Care :)

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 :)

Interfacing of Flame Sensor with Arduino

Hello friends, I hope you all are fine and having fun with your lives. Today, I am going to share a new tutorial which is Interfacing of Flame Sensor with Arduino. I have recently posted a tutorial in which I have shared the Flame Sensor Library for Proteus. Now in this tutorial, I am gonna use that Flame Sensor Library and will interface this Flame Sensor with Arduino. So, if you haven't downloaded this file then I suggest you to download this Flame Sensor Library so that you can easily simulate this flame Sensor in Proteus.

I am sharing interfacing of this Flame Sensor with Arduino today, but soon I will also post a tutorial on Interfacing of Flame Sensor with PIC Microcontroller. If you guys have any questions then ask in comments. I have also given the Simulation file and the Programming code below to download. But I would recommend you to design this proejct on your own so that you make mistakes and then learn from them. So, let's get started with Interfacing of Flame Sensor with Arduino:

Interfacing of Flame Sensor with Arduino

  • You can download the complete Proteus Simulation along with Arduino programming code from the below button:

Download the Simulation

  • Now design a small Arduino code as given below:
#include <LiquidCrystal.h>

LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

int Flame = 7;

void setup() {
  Serial.begin(9600);
  pinMode(Flame, INPUT_PULLUP);
  lcd.begin(20, 4);
  lcd.setCursor(0,0);
  lcd.print("Flame : ");
  lcd.setCursor(1,2);
  lcd.print("www.TheEngineering");
  lcd.setCursor(4,3);
  lcd.print("Projects.com");
}

void loop() {
  if(digitalRead(Flame) == HIGH){lcd.setCursor(8,0);lcd.print("Detected    ");}
  if(digitalRead(Flame) == LOW ){lcd.setCursor(8,0);lcd.print("Not Detected");}
  
}
  • Add this code in your Arduino software and compile it to get the Hex File from Arduino Software.
  • Upload this hex file in your simulation and then run your simulation and if everything goes fine then you will get something as shown in below figure:
  • In the above figure, you can see the sensor is off that's why in the LCD its written that no smoke detected.
  • Now, let's bring some Flame by clicking the Logic State on Flame Sensor and you will see the below results:
  • Now you can see in the above figure that when the Flame is detected then the LCD indicated that Flame has detected.
  • That's how we can easily simulate the Flame Sensor with Arduino.
  • I have explained this project in detail in the below video:
That's all for today. I hope you have enjoyed this project and now you can easily interface your Flame Sensor with Arduino in Proteus ISIS.

Arduino Bluetooth Communication using HC05

Hello friends, hope you all are fine and having fun with your lives. Today, I am going to share a new project in which we are gonna do Arduino Bluetooth communication. The Bluetooth module I have used for this project is HC-05, which is a serial Bluetooth module. We can quite easily perform the Bluetooth communication with this module using Arduino board. I have worked on many projects in which I have to send the data from sensors to my computer via Bluetooth. So, in such projects I normally use this Bluetooth module which is connected with the sensors and then Arduino gets the data from these sensors and then send this data to computer via Bluetooth module. In this project, I have used Arduino board but you can use PIC Microcontroller or 8051 Microcontroller as well. Because they both have the Serial pins on them.

Note:

Before reading any further, I think you must have a look at the below post from where you can download the Bluetooth Library for Proteus, using this library you can easily simulate HC-05 or , HC-06 in Proteus software:

I have also done Bluetooth communication with Android mobiles. In these projects I have sent the data from this Bluetooth module to Android mobiles but in such projects I have also designed Bluetooth app on which this data is received. Anyways, that's a topic of another tutorial. Today, I am gonna connect this Bluetooth module with Arduino board and then will send some data to my computer using Bluetooth. So, let's get started with Arduino Bluetooth communication using HC-05 module.

Arduino Bluetooth Communication using HC-05

  • First of all, what you need to do is to buy the Arduino board. I have designed this project using Arduino UNO board but you can buy any of the Arduino Microcontroller board.
  • Next thing you are gonna need is Bluetooth module which is HC-05. But this tutorial will also work for HC-06 or HC-07.
  • Now if you have seen HC-05 then the pins are written on it so connect them with your Arduino board as shown below:
  • This pin configuration is also shown in the below figure:
  • Now that you have connected your Arduino board with the Bluetooth module HC-05 so you are ready to do the Arduino Bluetooth communication.
  • Now upload the below code in your Arduino board:
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3);

void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop() 
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}
  • Its a simple software serial code in which we are sending data from our Serial terminal to Bluetooth means whatever you write in your serial terminal will be sent over to Bluetooth and whatever you receive on your Bluetooth will be shown in serial terminal.
  • Now, download this Serial monitor software, I have designed this software and its quite simple one. You can use any other serial monitor like Virtual Terminal in Proteus or Hyper Terminal in Windows XP.
  • We are gonna use this software to get the data on our computer via Bluetooth and you computer must have the Bluetooth in your computer. :P
  • So, download this software by clicking the below button and you can read more about it Microsoft Visual Basic 2010 - Com Port Tutorial.

Download Serial Terminal

  • Now turn on your Arduino and search for the Bluetooth device in your Bluetooth settings and paired with it as shown in below figure.
  • The default pin code for HC-05 is 1234.
  • Now you can see I have paired the HC-05 device.
  • Now, open this software and connect with the COM port of your Bluetooth device.
  • The Bluetooth device generates two COM ports in my case it generated COM11 and COM12 but COM11 worked.
  • So, I connected with COM11 and then whatever I entered in my software is shown on the serial monitor of my Arduino and whatever I entered in the Serial monitor of Arduino is shown in the serial terminal software.
  • Its quite simple and you can do it quite easily.

So, that's all for today and I hope you are gonna make it work in the single attempt. If still having problems then ask in comments and I will resolve them. So, today we have done Arduino Bluetooth communication using HC-05 module.

Interfacing of Keypad with Arduino

Hello friends, hope you all are fine and having fun with your lives. In today's post we will have a look at How to interface keypad with Arduino in Proteus ISIS. Keypad is used almost in every engineering project. If you even look around you will find keypad in many electronic appliances. For example, a simple ATM machine has a keypad on it using which enter our pin code and give commands to the ATM machine. Similarly, calculator also has keypad on it. So, in short there are numerous applications of keypad. You should also read the Real Life examples of Embedded Systems and you will find Keypad in them as well.

Keypad is used where you need to used numerical buttons or you need to use lots of buttons for sending commands so like in some application I need to use 10 buttons so instead of using separate 10 buttons I would prefer to use keypad instead as it will save a lot of time both in hardware as well as programming. So today we will have a detailed look on How keypad works and How we can Interface keypad with Arduino in Proteus ISIS. Proteus also gives keypad component in its database using which we can easily simulate it in Proteus and can save our time. So first simulate it and then design the hardware. After today's post I will also share an Automatic Lock system project using keypad. Anyways let's get started with Interfacing of Arduino with keypad:

How keypad works ??

  • Keypad uses matrix system in order to work.
  • For example, I am using a keypad which has 12 buttons on it as shown in below figure:
  • Now you can see its a 12 button keypad so it has total 3 columns and 4 rows and similarly there are 7 pins to control these 12 buttons.
  • So, the simple formula is total number of pins = Number of Rows + Number of Columns.
  • Now if we look at the internal circuitry of this 12 button keypad then it will look something as shown in below figure:
  • Columns and rows are connected with each other now suppose I press button "1" on the keypad then first row and the first column will get short and I will get to know that button "1" is pressed.
  • Same is the case with other buttons, for example I press button "8" then second column and the third row will get short so this code will remain unique for each button.
  • In simple words, on each button press different column and row will get short we need to detect which one gets short in order to get the pressed button.
Quite simple, isn't it ?? You should also have a look at these Arduino Projects for Beginners. So that's how a keypad works, now let's have a look at How to Interface this keypad with Arduino in Proteus ISIS.

Interfacing of Keypad with Arduino in Proteus ISIS

  • So, now we are gonna interface this keypad with Arduino in Proteus ISIS which is as always my favorite simulator.
  • In Proteus design a circuit as shown in below figure:
  • So, we have an Arduino UNO board along with keypad and LCD.
  • So I have done the programming in such way that whenever you press any button on the keypad, it will get displayed on the LCD.
Note:
  • Now, copy the below code and paste it in your Arduino software and get the hex file from it.
#include <LiquidCrystal.h>
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
    {'1','2','3'},
    {'4','5','6'},
    {'7','8','9'},
    {'*','0','#'}
};

byte rowPins[ROWS] = {10, 9, 8, 7}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {13, 12, 11}; //connect to the column pinouts of the keypad

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);
  lcd.setCursor(1,2);
  lcd.print("www.TheEngineering");
  lcd.setCursor(4,3);
  lcd.print("Projects.com");
  lcd.setCursor(0,0);
}

void loop() {
char key = keypad.getKey();

    if (key) {
        lcd.print(key);
    }
}
  • Now upload the hex file in your Arduino UNO in Proteus ISIS and hit the RUN button.
  • If everything goes fine then you will get something as shown in below figure:
  • Now, when you press any button on the keypad it will also appear on the LCD as shown in below figure:
That's all for today. In the coming post I am gonna share a small project in which we will design a automatic locking system using this keypad. So stay tuned and have fun. :)

How to Reset Arduino Programmatically

Hello friends, hope you all are fine and having fun with your lives. Today's post is about How to Reset Arduino Programmatically. Sounds a bit weird, yes it is :) but literally in some cases, this technique is the only choice you have. It recently happened to me in one of my projects, that's why I know How important it is. Before going into details, let's first have a look at the resetting feature of Arduino.

If you have worked on any Arduino board, then you must have noticed the RESET pin in Arduino and you may wonder what's the use of this pin. So, today this pin is gonna get useful. Moreover, you have also noticed that when you upload the code to your Arduino board then the Arduino resets, another way of resetting Arduino is by opening the Serial Terminal in Arduino software, while connecting your Arduino board to your computer. As you open the Serial Terminal, the Arduino automatically gets reset. The third way of resetting Arduino is by pressing the push button. When you press and release the push button, Arduino gets reset. You should also have a look at How to get Hex File from Arduino.

So till now we have seen three ways of resetting Arduino but you have noticed that all of these methods are manual, you have to manually push the button or to open the Serial Terminal or to upload the code. Now in some projects, we have to reset Arduino Programmatically, like we don't do anything and it just reset itself automatically. Now how can we do that, that's the topic of today's tutorial. So, I am gonna share two methods today using which we are gonna reset Arduino programmatically. So, let's start with them.

Where To Buy?
No.ComponentsDistributorLink To Buy
1Jumper WiresAmazonBuy Now
2Arduino UnoAmazonBuy Now

Reset Arduino Programmatically using RESET Pin

  • In the first method, we are going to reset Arduino Programmatically using the RESET Pin available on the Arduino board.
Note:
  • If you haven't bought your Arduino UNO yet, then you can buy it from this reliable source:
  • So, first of all, connect Arduino Reset Pin with any of the digital pins as I have connected it with Pin#4 shown in the below figure:
  • Now upload the below code to your Arduino board:
 
int Reset = 4;

void setup() {  
  digitalWrite(Reset, HIGH);
  delay(200); 
  pinMode(Reset, OUTPUT);     
  Serial.begin(9600);
  Serial.println("How to Reset Arduino Programmatically");
  Serial.println("www.TheEngineeringProjects.com");
  delay(200);
}
void loop() 
{
  Serial.println("A");
  delay(1000);               
  Serial.println("B");
  delay(1000);               
  Serial.println("Now we are Resetting Arduino Programmatically");
  Serial.println();
  delay(1000);
  digitalWrite(Reset, LOW);
  Serial.println("Arduino will never reach there.");

}

  • Once you have uploaded the code then and open your Arduino Serial Monitor and you will get something as shown in the below figure:
  • As you can see in the above figure, our Arduino is not displaying the line "Arduino will never reach there" and got reset and then display from start. So that's how it's going to work.
  • Now let's have a look at the second method of How to Reset Arduino Programmatically.

Reset Arduino Programmatically using reset Function

  • In this method, we are not going to use any hardware pin, instead, we will do everything in programming.
  • So, if you don't know much about Arduino Programming then you should have a look at Getting Started with Arduino Programming.
  • Arduino has a built-in function named as resetFunc() which we need to declare at address 0 and when we execute this function Arduino gets reset automatically.
  • So, no need of doing anything in hardware and simply upload the below code to your Arduino board.
void(* resetFunc) (void) = 0;
 
void setup() {     
  Serial.begin(9600);
  Serial.println("How to Reset Arduino Programmatically");
  Serial.println("www.TheEngineeringProjects.com");
  delay(200);
}

void loop() 
{
  Serial.println("A");
  delay(1000);               
  Serial.println("B");
  delay(1000);               
  Serial.println("Now we are Resetting Arduino Programmatically");
  Serial.println();
  delay(1000);
  resetFunc();
  Serial.println("Arrduino will never reach there.");
 
}
  • Now open your Arduino Serial Terminal and you will get the same output as we get in the first method and shown below:
  • In the code you have seen that we defined the function resetFunc() and then where we call that function, our Arduino gets reset at that point.
It was quite a simple tutorial, but if you have any problems then ask in the comments and I will try to resolve them. So that's all for today and will meet in the next tutorial. 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