Interfacing Flex Bend Sensor with Arduino

Interfacing Flex Sensor with Arduino
flexsensor1

Introduction

‘Flex Sensor’ or ‘Bend Sensor’ is a sensor that changes its resistance depending on the amount of bend on the sensor. They convert the change in bend into electrical resistance – the more the bend, the more the resistance value.  Flex sensors are widely used in various applications such as – Automotive controls, Medical Devices, Fitness Products, Virtual Reality gaming consoles, Animatronics, Robotics, etc.  This tutorial aims to provide a detailed guide to flex sensor and its interfacing with Arduino.

Description

The Flex sensor patented technology is based on resistive Carbon elements. As a variable printed resistor, the flex sensor achieves great form-factor on a thin flexible substrate. When the substrate is bent, the sensor produces a resistance output correlated to the bend radius – the smaller the radius, the higher the resistance value.

This is how a flex sensor looks like:
flexsensor2

They are usually in the form of a thin strip from 1”-5” long that vary in resistance range. It is obvious that longer strip would give more number of different resistances on bending. The change in resistance with increasing bend is depicted in the below snapshot:
flexsensor3

In simple words, flex sensors are analog resistors. They work as variable analog voltage dividers.
flexsensor4

Inside the flex sensor are carbon resistive elements within a thin flexible substrate. More carbon means less resistance.

Usually a flex sensor is used in voltage divider configuration. It is shown below:
flexsensor5

Interfacing with Arduino

NOTE: Although the active portion of the sensor (the area between the black squares) is quite sturdy, the pin-end of the sensor is susceptible to kinking and eventual failure. I recommend reinforcing or securing this area (for example, clamping or gluing down the sensor at the black square nearest the pins) to ensure that this area doesn’t flex along with the rest of the sensor.

Make the connections of the flex sensor in voltage divider configuration as shown above. Take your Arduino and connect the divider point to Analog Input of the board.

The analogRead() function will provide the sensor values.
flex = analogRead(1);
Serial.print(flex);

This will print values on the serial monitor.

Now we’ll show the amount of bend through LEDs. Connect the Red, Green and Blue LEDs to the Arduino Digital pins 4, 3 and 2 respectively, as shown in the circuit.

With no bend in the flex sensor, only Blue LED will Glow. When a small bend is applied, Green LED will glow (which is to indicate bend level). On applying large amount of bend, Red LED will glow, remaining two LEDs are OFF, which indicates large bend.

Circuit Diagram
flexsensor6

Images:
flexsensor7 flexsensor8

Code

#define blue 2

#define green 3

#define red 4

 

unsigned int f;

 

void setup()

{

 

pinMode(blue,OUTPUT);

pinMode(green,OUTPUT);

pinMode(red,OUTPUT);

Serial.begin(9600);

 

}

 

void loop()

{

f=analogRead(1);

Serial.println(f);

 

if(f>300)                          //No Bend; Blue LED Glows

{

digitalWrite(blue,HIGH);

digitalWrite(green,LOW);

digitalWrite(red,LOW);

}

else if((f<300)&&(f>260))          //Small Bend; Green LED Glows

{

digitalWrite(green,HIGH);

digitalWrite(blue,LOW);

digitalWrite(red,LOW);

}

else                              // Larger Bend; RED LED Glows

{

digitalWrite(red,HIGH);

digitalWrite(green,LOW);

digitalWrite(blue,LOW);

}

delay(50);

}

 

BlueTooth Interface with Arduino Uno

   bluetooth_1
This tutorial will demonstrate  how to configure and use the Serial Bluetooth Module with an Arduino Uno.  There are three types of Serial Bluetooth Modules, which are available in the market. They are:

1. Master-Slave (HC-03, HC-05) -user can change the firmware.
2.Master Only (HC-04-S, HC-06-S) -user cannot change the firmware,           factory default firmware.
3. Slave Only (HC-04-M, HC-06-M) -user cannot change the firmware,           factory default firmware.

To have a connection between two micro controllers, a master device is needed (e.g. the HC-05 can be configured as master or slave). For simple device to computer and device to Notebook communication Master-Slave Module is not necessary. It can be made possible by using simple Master or Slave Modules(HC-06,HC-04). The entire tutorial is based on the use of the HC-06 Bluetooth Module.

HC-06 Bluetooth Module:

bluetooth_2bluetooth_3

HC 06 is a slave Bluetooth to serial adapter. It measures a  dimensions of only 28mm x 15 mm x 2.35mm.It is easy to handle and can be used as wireless UART Communication from PC to any microcontroller. HC-06 is a slave only device. By default, HC-06 has

  • Baud Rate – 9600
  • Pairing Code – 1234
  • Name/ ID – linvor

The settings can be changed by using AT Commands.

Testing the Bluetooth Module:

Step1: Uploading the Code

Upload the below sketch to the Arduino Uno,

void setup ()

{

Serial.begin(9600);//set the baud rate

Serial.println(“start”);//send data to the android phone

}

void loop()

{

Serial.println(“Hiii, Android”);// send data to the android phone

delay(10000)

}

Step2: Connections

The HC-06 Module communicates with the Arduino Uno via serial connection. Four pins are used:

  • VCC -> VCC is used to power the module.  It is connected   to the Arduino 5v pin.
  • GND -> GND is the ground pin. It is connected to the Arduino Ground pin.
  • TX -> TXD is used to send data from the module to the Arduino. It is connected to the serial receive pin (RX) of the Arduino, which is pin 0 in case of the Uno. Incase different Arduino board is used, then its schematics has to be checked inorder to make sure that the right pins are used.
  • RX -> RXD is used to receive data from the Arduino. It is connected to the Arduino serial transmit pin (TX), which is pin 1 of Arduino Uno.
  • KEY -> This pin is used for changing the settings (AT Command Mode).At present, KEY pin is left open.

HC-06Arduino Uno

VCC  -> VCC (5V)
GND  ->GND
TX ->RX (D0)
RX  ->TX (D1)

bluetooth_4

Note: Make sure that the sketch is loaded from step 1 on the Arduino, before connecting the Bluetooth model to the phone.It is not possible to use the Arduino IDE serial monitor or upload sketches when the Bluetooth module is connected, as it uses the same RX/TX lines. Software Serial library is used to connect the Bluetooth module to any digital Arduino pin and keep the RX/TX line open.

Step 4: Pairing the Bluetooth and setting the Blueterm Software

  • After the power up of the Bluetooth device, turn on the Bluetooth in the android phone.
  • Search for the new devices. A Bluetooth device name is found. Click on the Bluetooth device name, a pairing window appears,which looks similar to the fig shown below. Type a password, say “1234”.

bluetooth_5

  • Install the Blueterm free Android app on the phone.

https://play.google.com/store/apps/details?id=es.pymasde.blueterm&hl=en

  • Open the Blueterm app and click on menu.Connect to the Bluetooth device.A message “Hi, Android” is displayed on the Blueterm Window continuously.

Changing the default Settings through AT Commands:

Step 1: Connection

  • Make “KEY” Pin of the Bluetooth Module HIGH by connecting KEY Pin to the VCC and the complete connection. It is shown below.

HC-06Arduino Uno

VCC  -> VCC (5V)
GND  ->  GND
TX  -> RX (D0)
RX   -> TX (D1)
KEY  -> VCC
Open the Serial Monitor and set the Baud Rate to 9600.

Step 2: AT Commands

  • Communication Test:

Test the Bluetooth Module by typing “AT” on Serial Monitor without an inverted coma(“”).After typing, press “Enter” on the keyboard. Incase Serial Monitor response is “OK”, then it is confirmed that Bluetooth Module is accepting the AT Commands, else double check the connections.

<- Sent: AT
-> Receive: OK

  • AT Command for Setting the Baud Rate:
    • Sets the Bluetooth UART Baud Rate. Baud Rate is set by an hexadecimal index from ‘1’ to ‘C’
    • Indexes are 1:1200, 2:2400, 3:4800, 4:9600, 5:19200, 6:38400, 7:57600, 8:115200, 9:230400, A:460800, B:921600, C:1382400
    • Send: AT+BAUD<index>
    • Response: OK<baud rate
  • Example:
    Sent: AT+BAUD1
    Receive: OK1200.
  • AT Command for Setting the Device Name:
    • Sets the Bluetooth Device Name
    • Send: AT+Name<device name>
    • Response: OKsetname
    • Example:
      Send: AT+NAMEBlueRock
      Response: OKsetname.
  • AT Command for Setting the Bluetooth PIN Code:
    • Sets the security code needed to connect to the device.
    • Send:AT+ PIN<4 digit code>
    • Response: OK<4 digit code>
    • Example:
      Send: AT+PIN4321
      Receive: OK4321
  • AT Command for checking the Firmware Version:
    • Get the Firmware Revision Number
    • Send: AT+VERSION
    • Response: Linvor V1.8

Soil moisture sensor Interface with arduino uno

Introduction:

Water is needed for the fundamental growth of plants. When sufficient amount of water is not present at the time of plant needs, then eventually the plant can prompt lessened quality or demise. Since it is very hectic for human to look after plants all the time, engineers designed soil moisture sensors to lessen the burden. Now using the sensor system designer can build any types of system that can look after the water needs of plant.

Sensor description:

This DFRobot soil moisture sensor has two probes through which current passes in soil, then read the resistance of soil for reading moisture level. We know that water make the soil more prone to electric conductivity resulting less resistance in soil where on the other hand dry soil has poor electrical conductivity thus more resistance in soil. Using these properties of electricity the sensor is designed. Inside the sensor there are circuitry for measuring the resistance and converting it into voltage as output.

Features:

  1. Supply voltage: 3.3v – 5v
  2. Output voltage: 0- 4.2 v
  3. Current: 35mA
  4. Low power consumption

Application:

  1. Irrigation controller
  2. Gardening
  3. Water sensor

Parts:

  1. Arduino uno (1pc)
  2. Soil moisture sensor (DFRobot)
    http://www.dfrobot.com/index.php?route=product/product&product_id=599#.U1PLxqLiO2Y
  3. Analog sensor cable (3 pin)

Pin configuration:

Moisture_1

Figure 1: Pin configuration of DFRobot soil moisture sensor

Wiring:

Moisture_2

Figure 2: soil moisture sensor interfacing with Arduino Uno

Arduino

Soil Moisture sensor

A0

S (pin 3)

5V

VCC (pin 1)

GND

GND (pin 2)

For this sensor no extra circuit is not required to construct so the data pin of soil moisture sensor which is pin 3 is directly connected with arduino uno’s analog I/O pin. In this project this pin is connected with arduino uno’s analog pin A0. However the question arises as to why analog pin? The reason behind using analog I/O pin is because the sensor provides analog voltage as output. Since arduino uno has analog-to-digital converter (ADC), it saves the hobbyist from hassles. Arduino uno do all the task using analogRead() function and show analog value.

Code:

/* # the sensor value description

# 0  ~300     dry soil

# 300~700     humid soil

# 700~950     in water*/

void setup(){

Serial.begin(9600);

}

void loop(){

int soil_moisture=analogRead(A0);  // read from analog pin A3

Serial.print(“analog value: “);

if(soil_moisture<30) {

Serial.println(“Dry soil”);

}

if((soil_moisture>300)&&(soil_moisture<700)) {

Serial.println(“Humid soil”);

}

if((soil_moisture>700)&&(soil_moisture<950)){

Serial.println(“water”);

}

}

Discussion:

According to the code sensor data is received by A3 pin of arduino uno. However any analog I/O pin can do the task. Also any arduino model will work for this code. The sensor manual luckily gave the conditions for identifying three types of soils: dry, humid, watery. However, if any user need more specific dissection then thy can experiment with the sensor by reading only analog value and tabulate them. After taking certain sample they can finally come to a conclusion.

Reference:

  1. http://www.dfrobot.com/wiki/index.php?title=Moisture_Sensor_%28SKU:SEN0114%29
  2. http://www.dfrobot.com/index.php?route=product/product&product_id=599#.U1PLxqLiO2Y

HSM-20G Interface with Arduino Uno

The HSM-20G is an analog humidity and temperature sensor that outputs analog voltage respects to relative humidity and temperature. However from this sensor relative humidity is found along with temperature. Relative humidity is the percentage of moistures of airs for a particular temperature [1].
Feature:
1. Storage range: -20°C to 70°C
2. Operating range: 0°C to 50°C

Application:
HSM-20g is considered as the most operating sensor compared to other similar products. This sensor is used in BTS (base transmission station) for weather forecasting. Also it is used in:
1. Air-conditioner
2. Automatic climate control system
3. Humidity data logger
4. Weather monitoring system

Pin configuration:
HSM20_pic1
Figure 1: Pin configuration of HSM-20G

Parts Needed:
1. Arduino uno (1pc)
2. HSM-20G (1pc)
3. Resistors- 100K, 10K
4. Capacitor- 47uF/10V

Wiring:
Usually for arduino interfacing sensor data pins are directly feed to arduino I/O pin. However for this HSM-20G sensor a particular circuit connection needed to be followed for getting desired result.
1. Connects all resistors and capacitor like in figure-2
HSM20_pic2
Figure 2: Circuit diagram for HSM-20g Interface with arduino

2. Then Connect humidity output with arduino analog pin A0 and temperature outpin pin with arduino analog pin A1. In this article, I used A0 and A1 pins, but user can select any of analog pins for communication.
3. If circuit connection is set accurately then the hardware is ready, however we need to do arduino coding.

Code:
Arduino Coding is done in Arduino IDE.


void setup()
{
Serial.begin(9600); // Serial monitor baud rate
Serial.println("setup");
}
void loop()
{
int humValue = analogRead(A0); // read humidity value from A0 pin
// eqn
int voltage = ((humValue*5.0)/1023.0); // convert analog value to voltage
//equation for humidity
int humidity= (3.71*pow(voltage,3))-(20.65*pow(voltage,2))+(64.81*voltage)-27.44;

Serial.print("Humidity: "+humidity);
Serial.println(" %");
delay(1000);
int tempValue = analogRead(A1); // read temperature value from A1 pin
int voltage_temp = ((tempValue*5.0)/1023.0); // convert analog value to voltage
//equation for temperature
int temperature=(5.26*pow(voltage_temp,3))-(27.34*pow(voltage_temp,2))+(68.87*voltage_temp)-17.81;
Serial.print("Temperature: "+temperature);
Serial.println(" C");
}

Discussion:
The Arduino board has an analog-to-digital converter from A0-A5 pin that reads this changing voltage and converts it to a number between 0 and 1023. So from A0 and A1 pin at first the analog values are converted to voltage. Since the sensor uses a specific connection for wiring, for getting desired value for humidity and temperature two equations are derived from the graphs given in datasheet.
From the given data table for output voltage respect to relative humidity in datasheet, a graph is plotted in Microsoft excel and an equation was found:
RH% = 3.71????3?20.65????2+64.81?????27.44
Also in the datasheet another table is given for resistance respect to temperature. So another graph is plotted and an equation is found
????=5.26????3?27.34????2+68.87?????17.81

Output Display:
HSM20_pic3
Figure 3: Serial monitor showing humidity and temperature value

After the circuit and arduino sketch is successfully constructed, user can see output in serial monitor. In this project Arduino uno is used, but any Arduino model can do the same task for this code. For data verification, they can check their local temperature and relative humidity.
References:

1. http://ww2010.atmos.uiuc.edu/%28Gh%29/guides/mtr/cld/dvlp/rh.rxml
2. Datasheet: http://www.seeedstudio.com/depot/datasheet/HSM-20G.pdf

Arduino Ultrasonic Distance Sensor

Arduino Ultrasonic Distance Sensor

Welcome to another article on a sensor which is so famous that Arduino has embedded codes to demonstrate this sensor within almost all of its very easy to use IDE versions as a default. You have probably seen this many times over with or without realizing its function.

This sensor is known as the Ultrasonic Distance Senor. As the name implies it is a sensor which is used to determine the distance of an object from the sensor. This sensor has a few version or models which are very common and widely seen. Three of them are shown below.

Ultrasonic_1
Fig a: TX and RX in one enclosure

 Ultrasonic_2Ultrasonic_3
Fig b & c: 3 pin and 4 pin version

There is many more variation of the above three. However there mode of operation are all same. Observe the following figure Ultrasonic_4Fig d: Working Principal from Parallex PING sensor datasheet

 In the above figure the famous Parallex PING Ultrasonic sensor is shown in action. It is a three pin version meaning that you control the TX and RX pulse via the same pin. Hang on what are the TX and RX pulses? You may be wondering this. Well then let’s go back to elementary physics of sound. Do you remember how the echo of a sound generated by a source could be used to measure the height of the water in a well? The same principal of echo is used by ultrasonic sensors. If you remember the range of sound people can perceive then you should know that we cannot hear above 20,000dB. Ultrasonic sounds work at much higher range meaning it is safe for us to work with.

Let’s look into a text book definition for ultrasonic sensors to get more clarity

“Ultrasonic sensors work on a principle similar to sonar which evaluates attributes of a target by interpreting the echoes from sound waves respectively. Ultrasonic sensors generate high frequency sound waves and evaluate the echo which is received back by the sensor. The time interval between the sent signal and received signal is determined to measure the distance from an object.”

The above definition simply says that you need to command the MCU (microcontroller) to send a TRIGGER or TX pulse for a defined amount of time and then LISTEN for the echo. If you remember the example of the well we calculated how long it took to hear the echo. Same is true for the ultrasonic sensor.  There is an onboard microcontroller on the ultrasonic sensor which converts the echo into time (in uS units). This time differential is then fed to the main microcontroller so that it could find out how long the echo took to come back which is a direct function of the distance. Technically the ultrasonic sensor’s MCU does the LISTENING but for ease of understanding most datasheet refers the time differential received by the main MCU as LISTENING. The onboard MCU is shown in the below figure

 Ultrasonic_5
Fig e: Onboard MCU (Middle) on PARALLEX PING SENSOR

Now let us look at some of the technical specifications of an ultrasonic sensor. I will discuss the Seeed Ultrasonic Sensor module but the specs are rarely different from other versions say example the Parallex PING sensor. The Seeed Ultrasonic sensor is shown below

Ultrasonic_6
Fig f: Seeed Ultrasonic Sensor

From the datasheet (link posted at the end of the article) the sensor is a 5V device that we connect Arduino’s 5V supply to its 5V pin. It can measure distance of an object accurately within 3cm to 4m. However if the body gets too close to the sensor, it fails to catch the echo and measure the time differential.

 Other key specs are, it needs 15mA of current, has a resolution of 1cm etc. But when looking for Ultrasonic sensor, pay special attention to the TRIGGER PULSE WIDTH and angle of sight i.e the area of line of sight of the sensor. This point is best explained by their practical performance chart given below Ultrasonic_7Fig g: Practical Performance Chart

Observe the chart, the sensor works best between 30 degree i.e when an object will be within this zone the Ultrasonic sensor will be able to accurately judge the distance of the object. Beyond this area the sensor will fail. This is very crucial if you plan on building collision avoidance robot or something similar.

If you go to the examples in the Arduino you can find the Ping sensor demo under the Sensor category. Just connect and experience the senor’s magic first hand. But I found this to be a little boring. Hence I came up with a bit trickier but more detailed version of the experiment. Just follow the instructions in the source code and hook up the circuit as described in the comment section. If done correctly you should be able to see the following results. What the leds does is show visually the range of object from the ultrasonic sensor.

 Ultrasonic_8
Fig: Full Circuit with No Obstacle

 Ultrasonic_9
Fig: With Obstacle at very close range

 Ultrasonic_10
Fig: Output at Serial Monitor with no objects

Ultrasonic_11
Fig: Output when object is very close to the sensor

I hope you enjoyed the article and the experiment. If you want to do the experiment in UNO board or any other board then you need to just change the following section after copy pasting the code into a new sketch in Arduino Ultrasonic_12Fig: Pin definitions

You can add even a lot more leds to give better visual representation just by manipulating the code a bit. If you do this experiment you may see an error but I will leave it up to you guys to solve it. Remember to use resistors with LEDS and NEVER connect them directly with Arduino. I used five 330ohm resistances.

Check out the following links if you want to get more data

1)    http://www.seeedstudio.com/depot/datasheet/Seeed%20Ultrasonic%20Sensor%20datasheet.pdf

2)    http://www.radioshack.com/graphics/uc/rsk/Support/ProductManuals/2760031_PM_EN.pdf

DOWNLOAD SOURCE CODE TO PROJECT BELOW OR COPY THE CODE BELOW
SOURCE CODE


                                                                //ULTRASONIC SENSOR IMPLEMENTATION WITH LEDS----VERSION 1.0//
                                                                // DATE 5TH DECEMBER 2013
                                                                // LICENSE: OPEN SOURCE/FREE

/*
-- A SIMPLE PROJECT BASED USING 5 LEDS, 1 PING ULTRASONIC SENSOR AND ARDUINO MEGA
-- DO NOT DIRECTLY CONNECT LEDS WITH ARDUINO!! USE A RESISTOR WITH EACH OF THE LEDS TO LIMIT THE CURRENT FLOW OTHERWISE BOTH THE LEDS AND THE BOARD MAY BE PERMANENTLY DAMAGED
-- THE LEDS ARE PROGRAMMED TO GIVE AN VISUAL CONFORMATION OF THE DISTANCE BETWEEN THE SENSOR AND THE OBJECT
-- IT IS PROGRAMMED TO SHOW LEVEL BETWEEN 3 - 150 CM.
-- DIGITAL PINS 21 TO 26 ARE SELECTED FOR DRIVING THE LEDS AND EACH OF THEM IS COUPLED WITH A 330ohm RESISTOR.
-- USB POWER SOURCE IS USED
-- THE SENSOR USED IN THIS EXPERIMENT ARE THOSE WHICH HAS 3 PINS VIZ:- GND, +5V AND SIGNAL.
-- PWM PIN 7 IS SELECTED AS THE BI-DIRECTIONAL PIN REQUIRED TO CONTROL AND READ DATA FROM THE ULTRASONIC SENSOR
-- THE SENSOR HAS A ERROR OF +-2% IN COMPARISON TO THE READINGS FROM THE BUILT IN EXAMPLE OF ARDUINO IDE AND WITH A LINEAR SCALE READING
-- 
-- EACH OF THE LED WILL CONSUME ABOUT 10-15mA OF CURRENT.
-- A USB JACK OF A COMPUTER CAN ROUGHLY SUPPLY ABOUT 500mA TOPS WHICH IS MORE THAN ENOUGH FOR THIS PROJECT
-- THE DISTANCE OF THE OBJECT WILL ALSO BE SHOWN IN THE SERIAL MONITOR
-- RED LED WILL LIGHT UP WHEN IT COMES IN A CERTAIN DISTANCE TO THE SENSOR
-- THIS SENSOR REQUIRES 5V SUPPLY.
-- FOR MORE INFORMATIONS ON THE BUILT IN FUNCTIONS AND LIBRARIES THAT ARE USED PLEASE REFER TO arduino.cc/reference 

-- A NOTE: WHEN DEFINING VARIABLES ASSOCIATED WITH PIN NUMBER YOU CAN USE INT BUT I PREFER CHAR AS IT TAKES LESS MEMORY SPACE CUZ IT IS 8BIT WHEREAS INT IS 16BIT.
-- THE TIME PERIOD FOR THE TRANSMITTED PULSE IS 10uS AND IT STARTS WITH HALF CYCLE LOW AND THE REST HALF CYCLE AS HIGH
-- THE CODE IS NOT THE MOST EFFICIENT BUT I WROTE IT INTENTIONALLY TO JUST GIVE AN EASY FRAMEWORK ON USING ULTRASONIC SENSORS AND TO SHOW HOW THE DATA CAN BE VERY EASILY MANIPULATED
-- AN ERROR WILL BE OBSERVD AND IT IS THE SENSOR CANNOT ACCURATELY DETECT RAPID RELATIVE MOTION BETWEEN THE OBJECT AND ITSELF FOR THAT REASON THE LAST RED LED LIGHTS UP CUZ THE OUTPUT VALUE IS SHOWN TO BE 1
*/

//---------------------------------------PIN DEFINITIONS---------------------------//
const char signalPIN=2; // Signal PIN of the paralex knockoff PING sensor is connected to the digital pin 2
const char ledPIN_5=26; // GREEN LED 1
const char ledPIN_4=25; // YELLOW LED 2
const char ledPIN_3=24; // YELLOW LED 1
const char ledPIN_2=23; // RED LED 2
const char ledPIN_1=22; // RED LED 1
//---------------------------------------------------------------------------------//



//--------------------------------------------GLOBAL VARIABLES-----------------------//
int distance; // An interger variable that will contain the distance measured from the returning pulse.
unsigned long pulseduration=0; // A long varible that will contain the number of milisecond of the returning pulse.
unsigned int i = 0; 



//---------------------------------------------FUNCTION PROTOTYPE---------------------//
void measureDistance();  // This function will convert the recevied pulse duration into cm.
void Ledcheck();         // A simple function which will allow you to see whether the connection to any led is missing or any led is fused or not. 

void Led_shutoff();




void setup()
{


pinMode(ledPIN_5, OUTPUT);
pinMode(ledPIN_4, OUTPUT);
pinMode(ledPIN_3, OUTPUT);
pinMode(ledPIN_2, OUTPUT);
pinMode(ledPIN_1, OUTPUT);

//CONFIGURING PINS CONNECTED WITH LEDS AS OUTPUT SO THAT WHEN THE CORRESPONDING PIN WILL BE HIGH THE CIRCUIT WILL BE COMPLETE AND THAT LED WILL LIGHT UP

Serial.begin(9600); // Initializing serial monitor.

Ledcheck(); // IN SETUP LOOP STATEMENTS WILL RUN ONLY ONCE AND THUS THE LEDCHK FUNCTION IS CALLED SINCE IT IS NEEDED TO BE RUN ONLY ONCE

}


void loop()
{

measureDistance(); // Function call to get the pulseduration
pulseduration=pulseduration/2; // The principle of sound and echo time to reach the object = total time / 2
distance = int(pulseduration/29); // THE LONG VALUE WILL BE AUTOMATICALLY CONVERTED INTO INTEGER

if ( distance >= 15)
  {
    Led_shutoff();
    digitalWrite (ledPIN_5, HIGH); 
    delay(500); // 1 second delay to make the led visible
  
  
  }
    else if (distance =12)
        {
            Led_shutoff();
            digitalWrite (ledPIN_4, HIGH); 
            delay(500); // 1 second delay to make the led visible
            
        }
          else if (distance =9)
            {
                Led_shutoff();
                digitalWrite (ledPIN_3, HIGH); 
                delay(500); // 1 second delay to make the led visible
            
            
            }
              else if (distance =4)
                {
                
                    Led_shutoff();
                    digitalWrite (ledPIN_2, HIGH); 
                    delay(500); // 1 second delay to make the led visible
                
                }
                else // Since the above conditions wasn't satisfied it means either the sensor is disabled or the object is too close to the sensor.
                  {
                        Led_shutoff();                
                        digitalWrite (ledPIN_1, HIGH); 
                        delay(500); // 1 second delay to make the led visible
                  
                  }



// Display on serial monitor

Serial.println("Distance-  ");
Serial.println(distance);
Serial.println(" cm");
delay(500);
}




//--------------------------------------------------FUNCTION BODY---------------------------------//
void measureDistance() 
{
  // set pin as output so we can send a pulse
  pinMode(signalPIN, OUTPUT); // Do not mistake this line as a code redundancy this is needed to reset the pin as output for next run
  // set output to LOW
  digitalWrite(signalPIN, LOW);
  delayMicroseconds(5);
 
  // now send the 5uS pulse out to activate Ping)))
  digitalWrite(signalPIN, HIGH);
  delayMicroseconds(5);
  digitalWrite(signalPIN, LOW);
 
  pinMode(signalPIN, INPUT); // Since the digital pins are BI-DIRECTIONAL their input/output characters can be switeced at any time using the software. Switched to input
  // THE TRIGGER PULSE AND THE ECHO ARE HANDELED BY 1 PIN IN THIS KIND OF ULTRA-SONIC SENSOR
 
  // finally, measure the length of the incoming pulse
  pulseduration=pulseIn(signalPIN, HIGH); // the length of pulse in microseconds.
}

void Ledcheck()
{
      digitalWrite(ledPIN_5,HIGH); // POWERING THE LED
      delay(1000); // Holding it for a second
      digitalWrite(ledPIN_5,LOW); // POWERING DOWN
 
      digitalWrite(ledPIN_4,HIGH); // POWERING THE LED
      delay(1000); // Holding it for a second
      digitalWrite(ledPIN_4,LOW); // POWERING DOWN 
  
      digitalWrite(ledPIN_3,HIGH); // POWERING THE LED
      delay(1000); // Holding it for a second
      digitalWrite(ledPIN_3,LOW); // POWERING DOWN 
   
   
      digitalWrite(ledPIN_2,HIGH); // POWERING THE LED
      delay(1000); // Holding it for a second
      digitalWrite(ledPIN_2,LOW); // POWERING DOWN 
    
      digitalWrite(ledPIN_1,HIGH); // POWERING THE LED
      delay(1000); // Holding it for a second
      digitalWrite(ledPIN_1,LOW); // POWERING DOWN  
    

  Serial.println("LED checking complete.");
  Serial.println(" ");
  Serial.println(" ");
  return ; 

}

void Led_shutoff()
{

  digitalWrite (ledPIN_5, LOW);
  digitalWrite (ledPIN_4, LOW);
  digitalWrite (ledPIN_3, LOW);
  digitalWrite (ledPIN_2, LOW);
  digitalWrite (ledPIN_1, LOW);
  //delay(100); // THIS DELAY WILL CAUSE BLINKING IN THE LEDS
}