NRF24L01+ with Arduino - Response Timed Out

Hello friends, hope you all are fine and having fun with your lives. Today I am going to share a problem and also its solution with you guys. A few days ago, I bought new NRF24L01 modules as they were needed for a project. So, today when I started working on them, I encountered a very strange problem. When I interfaced my NRF24L01 with Arduino and uploaded the transmitting and receving codes in them, I couldn't get anything on my serial terminal as I explained in my previous post Interfacing of NRF24L01 with Arduino. That was quite strange for me as I have worked on this module many times and it never troubled me before. So I keep on working on it but no luck. I even changed my RF modules as I thought may be they are faulty modules but still no luck. :(

So, the next thing came to my mind is to upload the Getting Started example from the RF24 library which I have also given in my previous post Interfacing of NRF24L01 with Arduino, and now when I checked the serial terminal, I got this error:

  • Failed, response timed out.

The screenshot of this response is as follows:

As you can see in the above figure, in the last lines we are getting error that "Now sending 4679...failed. Failed, response timed out." So, that was the problem which I encountered almost for half an hour and then I finally realized what I am missing and how to solve it. Before going to the solution, let me first tell you the types of this modules.

Types of NRF24L01 Module

  • When I encountered this problem, and instead of lot of efforts and not being able to resolve it, I finally thought of using the old module, so I searched for it and luckily I found one of them.
  • So, now I plugged this new module with another Arduino and I checked the properties of both these modules (i.e. the old one and the new one) and for that I simple uploaded the below sketch in both of my Arduino boards and opened the serial terminal.
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"

RF24 radio(9,10);

const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

typedef enum { role_ping_out = 1, role_pong_back } role_e;

const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"};

role_e role = role_pong_back;

void setup(void)
{
 
    Serial.begin(57600);
    printf_begin();
    
    radio.begin();
    radio.setRetries(15,15);
    
    radio.openReadingPipe(1,pipes[1]);
    
    radio.startListening();
    
    radio.printDetails();
}

void loop(void)
{
}
  • In this sketch, I simple print the details of NR24L01 module, so I uploaded the above sketch in both the Arduinos, one with old NRF24L01 module and the one with new NRF24L01 module, and I got the below response.

  • Now I got the reason that why I am not getting the response for the same code, which worked on the old one, because the old module model was NRF24L01 while this new module is NRF24L01+ which is slightly different from NRF24L01.
  • So that's the reson why I was constantly getting the Failed, response timed out error for this module. So, now lets have a look on how to resolve this issue.

How to resolve "Failed, response timed out" for NRF 24L01+ with Arduino

  • So, now one thing I knew that my module is NRF24L01+ and not NRF24L01 so I need to interface NRF24L01+ with Arduino. :)
  • So, I started looking online and get its datasheet which helped a lot and finally I got the thing.
  • NRF24L01+ draws more current than NRF24L01 while starting up and Arduino couldn't provide that required current to it. That's the reason NRF24L01+ failed to initialize and couldn't send or receive the response.
  • So, in order to remove this issue, I simply placed a Capacitor of 100uF between 3.3V and GND of Arduino and it did the magic. :)
  • Detailed circuit diagram is as follows:
  • So, that's the simple solution which kept me on for around an hour and then I finally got it.
  • As you can see in above figure, its exactly the same circuit diagram and the only addition is the capacitor placed between 3.3V and the GND.
  • After that I uploaded both the codes for receiver and transmitter which I have already posted in my old post Interfacing of NRF24L01 with Arduino and it worked like charm. :)

That's all for today, will meet you guys in the next tutorial soon. Take care!!! :)

Interfacing of LM35 with Arduino in Proteus ISIS

Hello friends, I hope you all are fine and enjoying yourself. Today I am going to share a new project titled Interfacing of temperature sensor LM35 with Arduino UNO in Proteus ISIS. So far, I have only worked on temperature sensor DS18B20 for temperature measurements and I have also uploaded a tutorial on Interfacing of Temperature Sensor 18B20 with Arduino.

Recently I got a chance to work on a project regarding temperature sensing but the condition of this project was that to use only LM35 for temperature detection. Then, I get to know much about LM35, its operating conditions and features. So I thought I should also upload its tutorial as it will also be advantageous for engineering students. Because learning new things is always a charm.

An excellent thing about LM35 is that it's quite cheap as compared to other temperature sensors. And as it's cheap, that's why it's not very reliable, if you personally ask me then I will prefer DS18B20 over LM35 because of its accurate readings. Now, let's move towards its interfacing and its practical applications. First of all, let's have a quick look at the introduction of LM35 and then we will design it in Proteus ISIS.

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

Introduction of LM35 Temperature Sensor

  • LM35 is an embedded sensor, used to measure the temperature of its surroundings and is famous because of its low cost.
  • Its output is generated in the form of an Electrical signal and this electrical signal is proportional to the temperature, which it detects.
  • Lm35 is much more sensitive than other temp measuring devices (not accurate).
  • The internal circuitry of this embedded sensor is sealed inside a capsule.
  • LM35 is a 3 pin IC and it is used for temperature detection. The physical appearance of LM35 is shown in the image given below:

  • As you can see in the above image that LM35 is a 3 pin IC:
    1. The first pin is Vcc, so it should be connected to 5V.
    2. The center pin is its Data Pin and LM35 gives its output when it measures temperature.
    3. The third pin is GND and should be connected to the ground of the battery/source.

LM35 Arduino Interfacing

  • As my today's tutorial is about interfacing LM35 with Arduino so let's start it.
  • I have connected LM35 with Arduino microcontroller and it is shown in the image given below:

  • As you can see in the above image, I have connected an LM35 sensor with Arduino UNO.
  • The VCC pin of LM35 is connected to +5V of the Arduino board.
  • Since LM35 generates an analog value at its output pin that's why I have connected this pin to the 'A0' pin of the Arduino board.
  • This pin of Arduino board is used to receive analog data from an external source.
  • And the last pin is connected to the GND pin of the Arduino board.

Arduino Code for LM35

  • After connecting the circuit, now upload the below code to your Arduino board.
#define TempPin A0

int TempValue;

void setup()
{
  Serial.begin(9600); // Initializing Serial Port
}
void loop()
{
  TempValue = analogRead(TempPin); // Getting LM35 value and saving it in variable
  float TempCel = ( TempValue/1024.0)*500; // Getting the celsius value from 10 bit analog value
  float TempFarh = (TempCel*9)/5 + 32; // Converting Celsius into Fahrenhiet

  Serial.print("TEMPRATURE in Celsius = "); //Displaying temperature in Celsius
  Serial.print(TempCel);
  Serial.print("*C");
  Serial.print("    |    ");

  Serial.print("TEMPRATURE = "); // Displaying Temperature in Fahrenheit
  Serial.print(TempFarh);
  Serial.print("*F");
  Serial.println();
  
  delay(1000);

}

LM35 Arduino Simulation in Proteus ISIS

  • Now let's do this project in Proteus. Proteus also has an LM35 sensor in its database which we are going to use here.
  • Moreover, we also know about Arduino Library for Proteus V2.0, so using that library we are going to interface LM35 with Arduino in Proteus ISIS.
  • First of all, design the same circuit as shown in the above figure in Proteus software as shown below:
  • It's the same circuit as we designed before, the only addition is the virtual terminal. We are using it to check the values.
  • It's simply like the Serial Monitor we use in Arduino software.
  • So, now using the above code, create the hex file and upload it in Proteus.
  • Now hit run and if everything goes fine then you will get results as shown in the below figure:
  • You can see the Virtual Terminal is showing the same value as shown on the sensor which is 33 in Celsius and later I converted it to Fahrenheit.
It's quite simple and I have also commented on the code but still if you find trouble then ask in comments and I will resolve them. Will meet in the next tutorial, till then take care!!! :)

Traffic Signal Control using Arduino

Hello friends, hope you all are fine and having fun with your lives. Today, I am going to share a Traffic Signal Control using Arduino. Few days earlier, I have posted the same tutorial but it was Traffic Light Signal Using 555 Timer in Proteus ISIS and today we will do the same thing but using Arduino programming. Its quite a simple but good starting project on Arduino. So, if you are new to Arduino then must give it a try.

Traffic Signal Control is quite a usual thing. We see traffic signals daily on our roads and usually engineers are asked to design such projects in their initial semesters. If we look at the traffic signals then we can see they are simply turning ON and OFF lights at some fixed regular intervals. and the pattern is quite simple as well. so I have simply followed that pattern and design the code. You should also have a look at Arduino 3 Phase Inverter. So let's start with designing this project named as Traffic Signal Control using Arduino.

Traffic Signal Control using Arduino

  • First of all, design a circuit in Proteus for Traffic Signal Control using Arduino as shown in the below figure:
  • Its quite a simple project so the circuit is quite simple as well. You can see I have just placed an Arduino board and plugged three LEDs with it and obviously they are Green, Yellow and Red in color.
  • These LEDs are attached to pins 2,3 and 4 of Arduino UNO.
  • Now next step is to write the Arduino Code for Traffic Signal Control using Arduino, so I have written and it is shown below:
#define GreenLed 4 #define YellowLed 3 #define RedLed 2 void setup() { pinMode(GreenLed, OUTPUT); pinMode(YellowLed, OUTPUT); pinMode(RedLed, OUTPUT); } void loop() { digitalWrite(GreenLed, HIGH); digitalWrite(YellowLed, LOW); digitalWrite(RedLed, LOW); delay(5000);delay(5000); digitalWrite(GreenLed, LOW); digitalWrite(YellowLed, LOW); digitalWrite(RedLed, HIGH); delay(5000);delay(5000); digitalWrite(GreenLed, LOW); digitalWrite(YellowLed, HIGH); digitalWrite(RedLed, LOW); delay(3000); }
  • That's the complete code for this project Traffic Signal Control using Arduino and I think its quite self explanatory plus I have also changed the color accordingly.
  • First of all Green LED is ON and the rest are OFF which is shown in green color.
  • Next Red LED is ON and the rest are OFF after around 10 seconds which you can change by changing these delays.
  • Finally the Yellow LED will be ON and you can see it goes OFF just after 3 sec because it has short delay, you can change these delays quite easily.
  • Below is the flow chart of above programming for Traffic Signal Control using Arduino which will clear the theme properly.
  • Now compile your Arduino code and get the hex file.
Note:
  • Now when you upload the hex file into your Arduino, it will give output as shown below:
  • So that's how it will work, I hope you got this clearly as its quite simple, will meet you soon in the next tutorial. Till then take care!!! :)

Interfacing of RFID RC522 with Arduino

Hello friends, hope you all are fine and having fun with your lives. Today's post is about interfacing of RFID module RC522 with Arduino. RC522 is very simple yet effective module. It is an RFID module and is used for scanning RFID cards. Its a new technology and is expanding day by day. Now-a-days it is extensively used in offices where employees are issued an RFID card and their attendance is marked when they touch their card to rfid reader. We have seen it in many movies that when someone places ones card over some machine then door opens or closes. In short, its a new emerging technology which is quite useful.

I recently get a chance to work on a project in which I have to use RFID reader to scan cards. In this project I have used it for for student attendance so I thought to share it on our blog so that other engineers could get benefit out it.

Let's first have a little introduction of RFID and then we will look into how to interface RC522 with Arduino. RFID is the abbreviation of Radio frequency identification. RFID modules use electromagnetic fields to transfer data between card and the reader. Different tags are attached to objects and when we place that object in front of the reader, the reader reads that tags.Another benefit of RFID is that it doesn't require to be in a line of sight to get detected. As in barcode, the reader has to be in the line of sight to the tag and then it can scan but in RFID there's no such restriction. So, let's get started with Interfacing of RFID RC522 with Arduino.

You should also read:

Interfacing of RFID RC522 with Arduino.

Now let's start with the interfacing of RFID RC522 with Arduino. There are many different RFID modules available in the market. The RFID module, which I am gonna use in this project, is RFID-RC522. Its quite easy to interface and works pretty fine. This module has total 8 pins as shown in the below figure:

  • SDA
  • SCK
  • MOSI
  • MISO
  • IRQ
  • GND
  • RST
  • 3.3V
It normally works on SPI protocol, when interfaced with Arduino board. Interfacing of Arduino and RC522 module is shown in below figure:
  • The pin configuration is as follows:
  • Now, I suppose that you have connected your RFID module with Arduino as shown in above figure and table, which is quite simple. You just need to connect total 7 pins, IRQ is not connected in our case.
  • Now next step is the coding, so first of all, download this Arduino library for RFID RC522 module.
Note:
  • Its a third party library, we haven't designed it, we are just sharing it for the engineers.

  • Now coming to the final step. Upload the below code into your Arduino UNO.
#include <SPI.h> #include <MFRC522.h> #define RST_PIN         9 #define SS_PIN          10 MFRC522 mfrc522(SS_PIN, RST_PIN); void setup() { SPI.begin(); mfrc522.PCD_Init(); } void loop() { RfidScan(); } void dump_byte_array(byte *buffer, byte bufferSize) { for (byte i = 0; i < bufferSize; i++) { Serial.print(buffer[i] < 0x10 ? " 0" : " "); Serial.print(buffer[i], HEX); } } void RfidScan() { if ( ! mfrc522.PICC_IsNewCardPresent()) return; if ( ! mfrc522.PICC_ReadCardSerial()) return; dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size); }
  • Now using this code, you can read the RFID no of your card quite easily. Now the main task is to use that number and distinguish them so for that I changed the dump_byte_array function a little, which is given below:
#include <SPI.h> #include <MFRC522.h> #define RST_PIN         9 #define SS_PIN          10 MFRC522 mfrc522(SS_PIN, RST_PIN); int RfidNo = 0; void setup() { SPI.begin(); mfrc522.PCD_Init(); } void loop() { RfidScan(); } void dump_byte_array(byte *buffer, byte bufferSize) { Serial.print("~"); if(buffer[0] == 160){RfidNo = 1;Serial.print(RfidNo);} if(buffer[0] == 176){RfidNo = 2;Serial.print(RfidNo);} if(buffer[0] == 208){RfidNo = 3;Serial.print(RfidNo);} if(buffer[0] == 224){RfidNo = 4;Serial.print(RfidNo);} if(buffer[0] == 240){RfidNo = 5;Serial.print(RfidNo);} Serial.print("!"); while(1){getFingerprintIDez();} } void RfidScan() { if ( ! mfrc522.PICC_IsNewCardPresent()) return; if ( ! mfrc522.PICC_ReadCardSerial()) return; dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size); }
  • Now using the first code I get the card number for all RFID cards and then in second code I used these numbers and place the check now when first card will be placed it will show 1 on the serial port and so on for other cards.
  • So, what you need to do is to use the first code and get your card number and then place them in second code and finally distinguish your cards.
  • Quite simple and easy to work.
  • Hope I have explained it properly but still if you get any problem ask me in comments.

NRF24L01 Arduino Interfacing

Hello friends, I hope you all are fine and enjoying. I have been working on a project these days and one portion of my current project includes the NRF24L01 Arduino Interfacing. So, I thought why not share this knowledge with you people, I hope you will learn something new and more interesting. If you don't know much about it, then you should have a look at Introduction to NRF24L01.

Few days ago, I have also posted a tutorial on XBee Arduino Interfacing, in which we have seen how to make wireless communication between two XBee Modules which is also an RF module. So, now we are gonna have a look at How to make Wireless Communication between two NRF24L01 modules. I hope you are gonna enjoy this nrf24l01 arduino Interfacing. Here's the video demonstration of NRF24L01 Arduino Interfacing:

Basics of NRF24L01

Before staring this interfacing of Arduino with 24L01, lets have a little introduction of nrf24l01 module. NRF24L01 is, in fact, a Radio Transceiver module and it operates on 2.4 GHz frequency. This module is a by default half- duplex fabricated module and it has the capability to send and receive data simultaneously. It's a very cheap & small sized module but it's features are astonishing. For example this module is capable of sending from 1 to 25 bytes of raw data simultaneously and the data transmission rate is up to 1 mega bytes per second. If we summarize all the features of this small size but big capability module then, we can say that:

  • By using this NRF24L01 module we can send a message to a particular receiver.
  • We can receive a message from some particular sender. (remember as I told earlier, we can do both the steps simultaneously).
  • During sending the message through this module, we will have to specify the message sender's and receiver's address.
  • Also we will have to specify the size of that particular message, which we are going to transmit through this module.
  • In some particular applications, we also have to perform switching between the receiver and sending state. For example, if you are received a particular message then, we will stop the communication first and will read it and then you will send it. So in such situations, we have to perform the switching while sending or receiving data through this module.
Now above discussion was a brief introduction about NRF24l01 module. Now lets move towards the major theme of our project which is Interfacing of arduino with NRF24l01 module. Note:
  • I encountered a problem of "Failed, response timed out" with NRF24L01+ while interfacing it with Arduino, if you got the same problem then read this post Interfacing of NRF24L01+ with Arduino - Response Timed Out. This nrf24l01 arduino example will help you in understanding this Response Timed Out problem.

NRF24L01 Arduino Interfacing

Arduino is a very powerful and versatile microcontroller board and it gives us the ease to perform multitasking. NRF24l01 has total 8 pins. The pin configuration and the function of each pin is described below:
  • The very first pin is for GND and through the pin#1 of this module, ground is provided to module.
  • Pin#2 of this module is to provide power supply. This pin is designated as VCC. This module generally needs 1.9 to 3.6 volts for its operation. And in most cases we will apply 3 volts to it.
  • Pin#3 is designated as CE and it is used to select the mode of operation. Either you are using this module to transmit data or to receive data.
  • Pin#4 is designated as CSN and it is used to enable the SPI chip, embedded on the module.
  • Pin#5 is used to provide SPI clock to the module. When this pin is HIGH then, clock is enabled and when this pin is LOW then, the clock to this module is disabled.
  • Pin#6 is designated as MOSI and it is used to transmit data from this module to the external circuit.
  • Pin#7 is designated as MISO and if we wish to receive data through this module from any external source then, this pin is enabled.
  • Pin#8 is the last pin of this module and it is designated as IRQ pin.
In order to do this Arduino with NRF24L01 communication, you will need two Arduino boards and two NRF24L01 modules. Now I suppose that you have these 4 items in your hand. So, first of all, let's do the transmitter side of NRF24L01 Arduino Interfacing.
NRF24L01 As Transmitter
  • Connect your NRF24L01 with Arduino as shown in the below figure:
  • Total 7 pins of NRF24L01 will be connected while the 8th pin IRQ doesn't need to connect.
  • Now, next thing you need to do is to download this RF24 Library of Arduino and place it in the libraries folder of your Arduino software so that we could compile our code of nrf24l01 arduino example.

Arduino Library for NRF24L01

  • We haven't designed this library, we are just sharing it for the engineers to use it in their projects.
  • Now upload the below sketch into your Arduino which you want to act as Transmitter.
    #include <SPI.h>
    #include "nRF24L01.h"
    #include "RF24.h"

    RF24 radio(9,10);

    const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
    unsigned long Command = 1;
    void setup()
    {
    Serial.begin(57600);

    radio.begin();
    radio.setRetries(15,15);
    radio.openReadingPipe(1,pipes[1]);
    radio.startListening();
    radio.printDetails();
    radio.openWritingPipe(pipes[0]);
    radio.openReadingPipe(1,pipes[1]);
    radio.stopListening();
    }

    void loop(void)
    {
    radio.stopListening();

    radio.write( &Command, sizeof(unsigned long) );

    radio.startListening();

    delay(1000);
    }
  • In this code, I have marked the variable Command, this is the variable which I am sending via NRF24L01, rite now its value is 1 which you can change.
  • So, if you want to send 3 you can change its value to 3.
  • Now lets design the receiver side.
NRF24L01 As Receiver
  • Again connect your Arduino with NRF24L01 as shown in below figure. Its same as we did for Transmitter side.
  • Now upload this below code into the Receiver and you will start receiving the value coming from transmitter.
    #include <SPI.h>
    #include "nRF24L01.h"
    #include "RF24.h"

    RF24 radio(9,10);

    const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };

    typedef enum { role_ping_out = 1, role_pong_back } role_e;

    const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"};

    role_e role = role_pong_back;

    void setup(void)
    {
    Serial.begin(57600);
    radio.begin();
    radio.setRetries(15,15);
    radio.openReadingPipe(1,pipes[1]);
    radio.startListening();
    radio.printDetails();
    radio.openWritingPipe(pipes[1]);
    radio.openReadingPipe(1,pipes[0]);
    radio.startListening();
    }

    void loop(void)
    {

    if ( radio.available() )
    {
    unsigned long data = 0;
    radio.read( &data, sizeof(unsigned long) );
    Serial.println(data);

    delay(20);
    }
    }
  • Now open your Serial Monitor of Receiver side and you will see that you are getting "1" in the Arduino Serial Monitor, which is the value of Command variable we set in the Transmitter side, as shown in below figure:
  • Its quite easy and I hope you will make it work in the first attempt but if you still got problem then ask in comments.
  • I will share more Arduino Projects on this RF module soon.
So, that's all for today and I hope now you can easily Interface Arduino with NRF24L01 and can do the RF communication. If you have any problem in this Interfacing of Arduino with NRF24L01 then ask in comments and I will try my best to resolve them. Take care. :)

Interfacing PIR sensor with Arduino

Hello friends, i hope you all are fine and enjoying. Today i am going to share a new project tutorial which is Interfacing PIR sensor with Arduino. First of all lets, have a little introduction about the basics and working of the PIR sensor. PIR sensors are in fact a Passive Infrared Sensor. PIR sensors are actually electronic sensors and they are used for motion detection. They are also used to detect the Infrared waves emitting from a particular object. You should also have a look at PIR Sensor Library for Proteus, using this library now you can easily simulate your PIR Sensor in Proteus software.

PIR sensors are widely used in motion detection projects now a days. Since my today's tutorial is about interfacing of PIR sensor with Arduino micro controller. Before going to that it is necessary that we should first understand the construction and working principle of PIR sensor. So i am going to divide my tutorial into different blocks and i will describe PIR sensor from its construction to practical applications. So first of all, lets see the construction and operating principle of PIR sensor.

Construction of PIR sensor

The construction of PIR sensor is very simple and easy to understand. In the bottom or you can say in the core of the PIR sensor we have a set of sensors which are made of pyro-electric materials. The properties of this material is that when this material is exposed to heat then, it generates energy. Different methods are used to to measure this energy generated by PIR sensor. On the top of the PIR sensor and above the internal sensors we have a small screen through which infrared radiations enters into sensor. When these radiations falls on the pyro-electric material then it generates energy. Generally the size of this sensor is very small and it is available in the form of thin film in market. Many other materials are also used in collaboration with pyro-electric material like galliam nitrite and cesium nitrate and all these materials take the form of an small integrated circuit.

Operating Principle of PIR sensor

The modern studies in the field of quantum physics tells us the fact each and every object when it is placed at a temperature above absolute zero, emits some energy in the form of heat and this heat energy is in fact the form of infrared radiations.  So an other question comes into mind that why our eyes can't see these waves? It is because that these waves have infrared wavelengths and his wavelength is invisible to human eyes. if you want to detect these waves then, you have to design a proper electronic circuit.

If you see closely the name of PIR sensor which is Passive Infrared Sensor. Passive elements are those elements that don't generate their own voltages or energy. They just only measures things. So we can say that this sensor is a passive infrared sensor and it doesn't generate anything by itself. It is only capable to measure the rediations emitted by other objects around it. It measures those raditions and do some desired calculations on them.

Interfacing of PIR Sensor with Arduino

PIR sensor have total 3 pins. The configuration of each pin is shown in the image given below:
  1. Pin#1 is of supply pin and it is used to connect +5 DC voltages.
  2. Pin#2 is of output pin and this pin is used to collect the output signal which is collected by PIR sensor.
  3. Pin#3 is marked as GND pin. This pin is used to provide ground to internal circuit of PIR sensor.
This whole configuration is also shown in the image given below:

The pin configuration of a PIR sensor is shown in the image given above. Since we have to interface the PIR sensor with Arduino micro controller. The image showing the interfacing of PIR sensor with Arduino is shown below as:

Interfacing Code

The code for interfacing Arduino micro controller with PIR sensor is given below as:
    #define pirPin 2

    int calibrationTime = 30;
    long unsigned int lowIn;
    long unsigned int pause = 5000;
    boolean lockLow = true;
    boolean takeLowTime;
    int PIRValue = 0;

    void setup()
    {
    Serial.begin(9600);
    pinMode(pirPin, INPUT);
    }

    void loop()
    {
    PIRSensor();
    }

    void PIRSensor()
    {
    if(digitalRead(pirPin) == HIGH)
    {
    if(lockLow)
    {
    PIRValue = 1;
    lockLow = false;
    Serial.println("Motion detected.");
    delay(50);
    }
    takeLowTime = true;
    }

    if(digitalRead(pirPin) == LOW)
    {

    if(takeLowTime){lowIn = millis();takeLowTime = false;}
    if(!lockLow && millis() - lowIn > pause)
    {
    PIRValue = 0;
    lockLow = true;
    Serial.println("Motion ended.");
    delay(50);
    }
    }
    }

Applications of PIR sensor

PIR sensors possess a no of applications and due to their low cost and much advanced features they are the main focus of different projects being made now a days. Some of their features and practical applications are listed below as:

  • They are able to sense the detection of people and other objects.
  • PIR sensors are also used in automatic lightening systems. In these type of systems, when a person comes in the vicinity of the sensor then, the lights are automatically turned ON.
  • They are used in outdoor lightening systems and also in some lift lobbies. You may have observed that when a person comes in front of the lift and if the doors are being closed then, the doors are opened again. This is all due to PIR sensors.
  • They are widely used in underground car parking system. At every parking position a PIR sensor is installed and when that position is vacant then, a green light glows over that place which means you can park here. And if that position has been occupied then, a red light will glow, representing that this position is already occupied.
  • PIR sensor is much compatible sensor and it has the ability to detect a particular motion and the output of this system is very sensitive and doesn't have any kind of noise in it.
Alright friends, that was all from today's post. If you have any questions, fell free to ask. Till next tutorial Take Care!!! :)  

Display ADC value on LCD using Arduino

Hello friends, hope you all are fine and having good life. In today's project, we will see how to display ADC value on LCD using Arduino in Proteus ISIS. Its quite a simple project in which we are gonna measure the voltage of ADC pins and then will display them over to LCD. The microcontroller I am using in this project is Arduino. The simulation is designed in Proteus ISIS. IF you are working on PIC Microcontroller then you should have a look at How to Display ADC value on LCD using PIC Microcontroller in Proteus ISIS.

Arduino has 10 bit ADC pins so whenever you apply voltage on these pins it will give you a value ranging from 0 to 1023 depending on the voltage provided. One can easily get this value using a simple function in Arduino analogRead(); but the real problem is to convert this analog value into the actual voltage present on the pin. Suppose you are using A0 pin of arduino and you are providing 3.3V over to this pin, now when you use this analoagRead() function then it will give you some value say 543, but you wanna know what's the actual voltage at this pin which is 3.3V so now converting this 543 to 3.3 is a bit tricky part. It's not difficult but involves a little calculations, which I am gonna cover today in detail. Before going any further, make sure you have already installed the Arduino Library For Proteus, if not then first do it because without this library you won't be able to use Arduino board in Proteus. So, let's get started with How to Display ADC value on LCD using Arduino.

Display ADC value on LCD using Arduino in Proteus ISIS

I have divided this tutorial on How to Display ADC value on LCD using Arduino in few steps, follow these steps carefully and if you get into some trouble then ask in comments and I will try my best to resolve them, all the materials are provided at the end of step 1 for download but I suggest that you design your own so that you do mistakes and learn from them. Moreover, you should also have a look at these Arduino Projects for Beginners. Anyways, let get started:

Step1: Circuit Designing in Proteus
  • First of all, I have designed a circuit in Proteus for Displaying ADC value on LCD using Arduino.
  • In this circuit, I have used two transformers which I have named as Potential Transformer and Current Transformer. I am supplying 220V to these transformers which is then converted into 5V.
  • I have set the turn ratio of these transformers such that they give maximum 5V at the output.
  • Now,rest of the circuit is simple, I have just connected the LCD with Arduino so that we could display these ADC value over to LCD.
Note:
  • Here's the circuit diagram of displaying ADC value on LCD using Arduino in Proteus ISIS:
  • You can download the Proteus Simulation and the Arduino hex file for Displaying ADC value on LCD using Arduino by clicking on below button:

Download Proteus Simulation and Arduino Hex File

  • It's quite simple and self explanatory. After designing the circuit diagram, now let's move to second step, which is code designing for Displaying ADC value on LCD using Arduino.
Step 2: Arduino Code Designing
  • Now copy the below code and paste it into Arduino software. Compile your code and get the Arduino hex file.
  • If you dont know How to get the hex file from Arduino then read Arduino Library for Proteus, I have explained it in detail there.
#include <LiquidCrystal.h>
#define NUM_SAMPLES 10

int sum = 0;
unsigned char sample_count = 0;
float voltage = 0.0;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int PT = A0;
const int CT = A1;
float Cur;
float Vol;
float Power;

void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
// Print a message to the LCD.
lcd.setCursor(6,1);
lcd.print("Welcome To");
lcd.setCursor(5,2);
lcd.print("Energy Meter");
//delay(5000);
lcd.clear();

Constants();
}

void loop() {
lcd.setCursor(0, 2);
ShowVoltage(9, 0, PT);
Vol = voltage;
ShowVoltage(9, 1, CT);
Cur = voltage;
Power = Vol * Cur;
lcd.setCursor(7,2);
lcd.print(Power);
}

void Constants()
{
lcd.setCursor(0,0);
lcd.print("Voltage: ");
lcd.setCursor(0,1);
lcd.print("Current: ");
lcd.setCursor(0,2);
lcd.print("Power: ");
lcd.setCursor(14,0);
lcd.print("V");
lcd.setCursor(14,1);
lcd.print("A");
lcd.setCursor(12,2);
lcd.print("W");
}

void ShowVoltage (int x,int y, unsigned int value)
{
while (sample_count < NUM_SAMPLES)
{
sum += analogRead(value);
sample_count++;
delay(10);
}

voltage = ((float)sum / (float)NUM_SAMPLES * 5.015) / 1024.0;
lcd.setCursor(x, y);
lcd.print(voltage);
sample_count = 0;
sum = 0;
}
  • The code is quite simple and self explanatory, the only difficulty is in ShowVoltage function. In this function, I have first taken an average of 10 ADC values and after that I have applied a simple formula over it and then it will start start giving the voltage value which I have simply displayed over the LCD.
  • Now everything's done, so Get your Hex File from Arduino Software and let's check the results whether it displayed ADC value on LCD using Arduino or not
Step 3: Result
  • We have designed the electronic circuit in Proteus and have also designed our code and uploaded the hex file in Arduino.
  • Now press start button and you will see something like this:
  • Now if you compare the voltages in voltmeter and on LCD, you can see they are exactly the same. You can check the value of variable resistor and the values in LCD will also change as the voltage in voltmeter change.
That's all for today, hope I have conveyed some knowledge today and now you can easily Display ADC value on LCD using Arduino. In the next post we will explore more Arduino features. Till then take care and have fun !!! :)

What is Arduino ?

Hello friends, today I am posting a very basic tutorial on what is Arduino ??? In this tutorial I am gonna explain the basics of Arduino for the beginners. I am writing this tutorial because I got a lot of requests from the engineers in which they ask questions like what is Arduino ? What's the difference between Arduino and PIC? How to use Arduino? etc etc. So I thought of writing this topic. It's a very basic tutorial so if you are already familiar with this board and know the answer of this simple question What is Arduino ??? then you can skip this tutorial but again you must read it once, may be you get something out of it. :)

I have posted a tutorial on Arduino Projects, in which I gave all the links of Arduino projects and tutorials posted on my blog, that's another reason for posting this tutorial. I am treating that Arduino Projects page as an ebook on Arduino so I am gonna post everything about Arduino as much as I can. And an ebook must have an intro chapter, which will be this one. So, let's get started.

What is Arduino ???

  • Arduino is nothing but a simple microcontroller board which is normally used in engineering projects where there's a need to automate something.
  • You can interface sensors with this board, can drive motors with this board, can plug switches in it etc.
  • In old ages ( not old enough :P ), people used simple switches for turning ON a bulb so like you click the switch and the bulb is ON, it was quite a simple circuit, after that relays are invented and then engineers used 555 timer circuits in order to turn ON lights on some specific time. But the 555 timer circuits are quite big in size, so finally engineers discovered Microcontrollers in which there are simple OUTPUT and INPUT pins, so now if you want to turn on light at some certain time then you just simply plug the blub on output pin of microcontroller and then do some programming and add a timer to automatically turn on the bulb.
  • So, the benefit of microcontroller is the circuit is quite simple and small in size.Moreover, its flexible, suppose you want to change the time of turning ON bulb then what you need to do is simply change the coding and it will be changed, but in 555 timer circuits you need to change the components in order to do so.
  • Now, we know the use of microcontroller and also their benefit but thing is what is Arduino ??? In microcontrollers like PIC or Atmel, there's a small drawback.
  • Suppose you want to work on PIC then you have to first design its basic circuit also need to design a power circuit to supply power to it and after that in order to upload the code in it, you have to buy a programmer/ burner as well. So, first of all you need to write the code for PIC Microcontroller and after that you need to upload code in it using a programmer and then plce PIC microcontroller back into the circuit and test, which is quite lengthy plus also got hectic when you are working on some project because you have to test code again and again.
  • By the way, now advance programmers like PICkit2 and PICkit3 can be plugged on board but still you have to design the basic circuit so coming to bottom line, in order to do project with PIC or Atmel microcontroller you have to do soldering etc.
  • But that's not the case with Arduino Board, Arduino has built in programmer and the basic circuit in it. So what you need to do is simply plug in Arduino with your computer via usb cable, get its software and start uploading code and also start testing.
  • So, you don't need to plug unplug or do anything, simply upload the code and test. Moreover, it also has some very efficient tools using which you can test your output as well quite easily. Arduino board also has the pins on which you can simply plug your devices and can turn them ON or OFF. So, hats off to Arduino team for providing us a simple board which has everything on it.
  • Another advantage of Arduino is that, because of its popularity all the electronic components also have the Arduino libraries which are free and using them you can operate that electronic component quite easily with Arduino. Its open source and hence its developing day by day.

Types of Arduino Boards

  • There's a long range of Arduino boards available online, the basic Arduino board is named as Arduino UNO which is most widely used in projects.
  • Arduino UNO has total 13 digital pins and 6 analog pins which are used for connecting sensors with them.
  • Suppose you have a project in which you want to interface 30 sensors, then what you need to do ?? Now you need to buy another Arduino board named as Arduino Mega 2560. This board has around 70 pins on it which can be used as output or input and hence you can plug your sensors quite easily.
  • Moreover, Arduino have also developed different shields like Arduino Ethernet shield. Using this shield you can provide internet access via Ethernet to your project.
  • Then they have Arduino Wifi shield which is used for providing Wifi access to your project.
  • They have also developed Arduino GSM shield for GSM or GPRS purposes, in short there's a wide range of Arduino boards available online.
  • So which Arduino board you need to buy depends on the requirements of your project.

How to use Arduino ??

  • Now I think you have got the basic idea of what is Arduino ? and why is it so popular ? So now lets have a look at how to use Arduino.
  • When you order for your Arduino board, you will get a package similar to the image below:
  • Along with this box, you will also have the USB cable, now take your Arduino board out of this box and plug the cable in it, connect the Arduino with your computer and you are ready to start working on it.
  • In order to connect Arduino with your computer you have to install the Arduino drivers in Windows.
That's all for today, hope I have conveyed some knowledge and you now know the basics of Arduino i.e. what is Arduino ? and why to use Arduino.

Interfacing of Seven Segment with Arduino in Proteus

Hello friends, today we are gonna have a look on how to interface Seven Segment with Arduino in Proteus. In my last post, I have posted an Arduino Library for Seven Segment Display, which is designed by our team and is quite basic in functionality. So, if you haven't checked that post then first of all check that one and download the Arduino Library for Seven Segment Display as I am gonna use that library in today's post. Moreover, in order to run this library you are also gonna need to download Arduino Library for Proteus, using this library you will be able to use Arduino board in Proteus so also read that post and download this library and install it in your Proteus.

Again I am mentioning that its the first library designed by our team so its in basic stages, it has few functions and will only display the numeric on the seven segment display which is normally required. I am planning on adding more examples in the library for future use, which will increase the functionality. Anyways that's a future talk, let's start today's post.

What is Seven Segment Display?

Let's first have a look at what is Seven Segment Display. Seven Segment display is nothing but an electronic device used for displaying the numeric data. It's a complex form of LED matrix and is normally used in clocks, LCD displays, calculators etc where there's a need to display the numeric data. It has total seven leds in it which you can also count from above image and by turning these LEDs ON or OFF we can display any numeric on it. For example, have a look at the below image. In this image I have shown numeric 0 on seven segment. Now in order to do so, I just simply turn OFF the centered LED and turn ON all the corner LEDs and it becomes 0.

How does Seven Segment Work?

Now, let's have look at how it works. So, we have seen that Seven Segment is named seven segment because it has total seven LEDs on it so now what we need to do is to control these seven LEDs, also named as segments, and then we can display any character on it. There are two types of seven segments available in the market and named as:

  • Common Cathode
  • Common Anode
They both work exactly the same and has only a slight difference. They both has total seven pins and each pin is used to control each led and they have an extra pin which is named as Common Pin. In Common Cathode you have to GND this Common Pin, while in common Anode, you have to give +5V to this Common Pin. Have a look at this below image, we have labelled leds with respect to the pins.

Interfacing of Seven Segment with Arduino in Proteus

  • Now we know all about Seven Segment Display and know how it works so let's interface Seven Segment with Arduino in Proteus.
  • Now, I am assuming that you have installed the Arduino Library for Proteus and have also installed the Arduino Library for Seven Segment display.
  • So, now open your Arduino Software and go to File>Examples>SevenSegment>Counting.
  • Open this example, in this example I have added a counter which will start counting from 0 to 9 and once it reached 9 then it will start counting again.
  • If you can't find this example then you must be making some mistake in installing the library, anyways the code is shown below.
Note:
/* Counting This Arduino example is for Seven Segent display. It will start the counter from 0 and will end up at 9 and will start again from 0. This example code is in the public domain. Created by Syed Zain Nasir at 14 March 2015. You can get the explanation and latest version of this library at: http://www.TheEngineeringProjects.com/ */ #include "SevenSegment.h" SevenSegment tep = SevenSegment(0,1,2,3,4,5,6); char arr [10] = {'0','1','2','3','4','5','6','7','8','9'}; int index; void setup(){ index = 0; } void loop(){ tep.display(arr[index++]); delay(1000); if(index == 11) index = 0; }
  • Now open you Proteus Software and design the circuit in it as shown in below figure, I have also attached the file for download at the end.
  • Now compile the code and gt the hex file and upload it in your Arduino Properties.
  • Now Run the Proteus software, and you will see the seven segment display will start counting, a glimpse of it is shown in the below figure:
  • Below is attached the Proteus file and the hex file for the counting example which you simply start and run but again I suggest that you should design it by yourself so that you get something out of it.

Download Proteus Simulation of Seven Segment with Arduino

  • One last thing, any kind of contribution to this library from the readers is highly appreciated, design your projects and share codes with us and we will post them on our blog for other readers to get knowledge as knowledge is all about sharing.
That's all for today, hope it will help you in some way. Take care and have fun. :)

Arduino Library for Seven Segment Display

In today's post, I am gonna share a new Arduino Library for Seven Segment Display. In my recent project, I got a chance to work on seven segment displays, I have worked on them using PIC microcontroller but haven't got a chance to use them with Arduino. So, now as usual when I started working on them, I started searching for Arduino Library but I kind of got disappointed after getting quite heavy libraries for seven segments, and after a lot of search I thought of designing my own Arduino library for seven segment display, which I am gonna share in this post. :)

It's not very advanced library as we know seven segment displays are not too complex, so its quite simple and using it you can quite easily display any numerical digit on the seven segment display. Moreover, I have also included an example with the library which will start the counter from zero on seven segment display and keep on incrementing till 9 and after that it will start again from zero. Moreover, I have also posted the example about Interfacing of Seven Segment Display with Arduino in Proteus using this library, it will help you in better understanding of How this library works. You can download the working Proteus Simulation as well as hex file from that post.

Download Arduino Library for Seven Segment Display

  • As I stated earlier, its a very simple Arduino Library for Seven Segment Display and it will only print the numeric on seven segment display, but I will work on it in future and will update it by adding more features in it.
  • So, first of all click the below button to download the Arduino library for seven segment display.

Download Arduino Library for Seven Segment Display

  • After downloading the library, place it in the libraries folder of your Arduino software.
  • Now close your Arduino software and open it again.
  • Go to File and then Examples and you will find SevenSegment in it and it will have an example which is named as Counting.

Functions in Arduino Library for Seven Segment Display

  • I have added quite few function in it which are very basic and are very easy to use.
  • The first function I have used is:
SevenSegment(int a,int b,int c,int d,int e,int f,int g);
  • In this function, you need to give the pins of Arduino with which you are attaching your seven segment display. It will called as shown below:
SevenSegment tep = SevenSegment(0,1,2,3,4,5,6);
  •  Now tep is our seven segment object and we are gonna use it in rest of the example.
  • The next function used in this arduino library for seven segment display is:
display(char c);
  • This function will display the numeric on seven segment display which you will provide it.
  • Moreover, it will automatically clear the screen before displaying any new character on the seven segment.
  • It is called in the example as shown below:
tep.display('1');
That's all for today, in this next post you can download the example of how to Interface Seven Segment Display Using Arduino in Proteus, it will help you in understanding of this library in detail.
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