Thursday, 22 May 2014

                       Ultrasonic range finder using arduino                      HC-SR04 ultrasonic range finder module is used as the sensor here. The display consists of a three digit multiplexed seven segment display. This range finder can measure up to 200 cm and has an accuracy of 1cm. There is an option for displaying the distance in inch also. Typical applications of this range finder are parking sensors, obstacle warning system, level controllers, terrain monitoring devices etc. Lets have a look at the HC-SR04 ultrasonic module first.


HC SR04 ultrasonic module.

HC SR04 is an ultrasonic range finding module with an accuracy of 0.3cm. The sensing range of this module is from 2cm to 5 meter. Working current of this sensor is 15mA and the measuring angle is 15°. The photograph of front and back side of the HC-SR04 sensor is shown in the figure below.

HC-SR04 has four pins. Their names and functions are explained below.
  • Vcc: 5V supply voltage is given to this pin.
  • Trigger: A 10uS long pulse is given to this pin for triggering the transmission. Upon receiving a valid trigger pulse, the HR-SR04 issues eight 40KHz pulses. Time taken by these pulses to reflect back is measured and the distance is calculated from it.
  • Echo: At this pin the HC-SR04 outputs a signal whose high time is proportional to the range.
  • Ground : Ground is connected to this pin.
The timing diagram of  HC-SR04 is shown in the figure below.

Circuit diagram.

Full circuit diagram of the ultrasonic range finder using arduino is shown in the figure below.
Trigger pin of the ultrasonic range finder module is connected to digital pin 0 of the arduino. Echo pin of the ultrasonic module is connected to the digital pin 13 of the arduino. SPDT switch S1 is used to select the unit of the measurement shown in the display. Pole of the SPDT switch S1 is connected to digital pin 4 of the arduino. If digital pin 4 is held high, the output will be in centimeters and if the digital pin 4 is held low, the output will be in inches. Digit driver transistor Q1, Q2 and Q3 of the arduino are interfaced to digital pins 1, 2 and 3 of the arduino. Multiplexed segments a to dp are interfaced to digital pins 5 to 12 of the arduino. The arduino board can be powered through the +9V jack given on the board. 5V supply needed in some other parts of the circuit can be obtained from the 5V source available in the arduino board. Resistors R9, R10 and R11 limits the base current of the corresponding transistors. 330 ohm resistors R1 to R8 limits the current through the corresponding segments. Pin out of an E1-3056ASR1 three digit MUX seven segment display in shown in the figure below.

Program.


#include <NewPing.h>
#define trig 0
#define echo 13
#define maximum 200
int a;
int unit;
int usec;
int input=4;
int disp1=1;
int disp2=2;
int disp3=3;
int segA=5;
int segB=6;
int segC=7;
int segD=8;
int segE=9;
int segF=10;
int segG=11;
int segDP=12;
NewPing sonar(trig, echo, maximum);
void setup()
{
  pinMode(disp1, OUTPUT);
  pinMode(disp2, OUTPUT);
  pinMode(disp3, OUTPUT);
  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);
  pinMode(segDP, OUTPUT);
  pinMode(input, INPUT);
}
void loop()
{
 delay(20);
 usec=sonar.ping(); //sends ping and estimates the duration of echo in uS
 unit= digitalRead(input); //reads the status of cm/inch selector switch
 if(unit==1)
 {
 usec=usec/58; // distance in cm
 }
 else
 {
   usec=usec/148; // distance in inch
 }
  a=usec%10;
  digitalWrite(disp1,LOW);
  digitalWrite(disp2,LOW);
  digitalWrite(disp3, HIGH);
  digitalWrite(segDP,HIGH);
  display(a);
  delay(4);
  usec = usec/10;
  a = usec%10;
  digitalWrite(disp3,LOW);
  digitalWrite(disp2,HIGH);
  digitalWrite(segDP,HIGH);
  display(a);
  delay(4);
  usec=usec/10;
  a=usec;
  digitalWrite(disp2,LOW);
  digitalWrite(disp1,HIGH);
  digitalWrite(segDP,HIGH);
  display(a);
  delay(4);
  }
  int display (int a)
  {
  switch (a)
  {
    case 0:
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segE, LOW);
    digitalWrite(segF, LOW);
    digitalWrite(segG, HIGH);
     break;

    case 1:
    digitalWrite(segA, HIGH);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, HIGH);
    digitalWrite(segE, HIGH);
    digitalWrite(segF, HIGH);
    digitalWrite(segG, HIGH);
    break;

    case 2:
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, HIGH);
    digitalWrite(segD, LOW);
    digitalWrite(segE, LOW);
    digitalWrite(segF, HIGH);
    digitalWrite(segG, LOW);
    break;

    case 3:
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segE, HIGH);
    digitalWrite(segF, HIGH);
    digitalWrite(segG, LOW);
    break;

    case 4:
    digitalWrite(segA, HIGH);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, HIGH);
    digitalWrite(segE, HIGH);
    digitalWrite(segF, LOW);
    digitalWrite(segG, LOW);
    break;

    case 5:
    digitalWrite(segA, LOW);
    digitalWrite(segB, HIGH);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segE, HIGH);
    digitalWrite(segF, LOW);
    digitalWrite(segG, LOW);
    break;

    case 6:
    digitalWrite(segA, LOW);
    digitalWrite(segB, HIGH);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segE, LOW);
    digitalWrite(segF, LOW);
    digitalWrite(segG, LOW);
    break;

    case 7:
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, HIGH);
    digitalWrite(segE, HIGH);
    digitalWrite(segF, HIGH);
    digitalWrite(segG, HIGH);
    break;

    case 8:
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segE, LOW);
    digitalWrite(segF, LOW);
    digitalWrite(segG, LOW);
     break;

    case 9:
    digitalWrite(segA, LOW);
    digitalWrite(segB, LOW);
    digitalWrite(segC, LOW);
    digitalWrite(segD, LOW);
    digitalWrite(segE, HIGH);
    digitalWrite(segF, LOW);
    digitalWrite(segG, LOW);
    break;
  }}

About the program.

For communicating with the ultrasonic range finder module, library function <NewPing.h> is used. The job of sending the 10uS trigger pulse, waiting for the echo and measuring the width of the echo etc are done by the library function. Just one line of code usec=sonar.ping()will make the arduino to do all the jobs said above and  the width of the echo pulse  in micro seconds will be stored in the variable usec. Dividing the pulse width in uS by 58 will give the distance in cm and dividing the pulse width in uS by 148 will give the distance in inch. An “if – else” loop is used for selecting the unit according to the position of the SPDT selector switch(S1).
The <NewPing.h> library can be downloaded from here: NewPing_v1.5. Download this zip file, unzip it into a folder, name it NewPing or something and copy it into the …….Program Files/Arduino/Library folder.

Wednesday, 21 May 2014

                   TEMPERATURE DISPLAY USING LCD


Here is a Simple Temperature Display Circuit using LCD ( Liquid Crystal Display ). For Heat Sensor we have used IC LM35 (Precision Centigrade Temperature Sensors ) whose Output voltage is linearly proportional to the Celsius (Centigrade) temperature. Output of LM35 IC is 10mv/degree centigrade for eg if temperature is 35 degree then the output of sensor will be 350mv or 0.35V
For working with LCD it is necessary to have Microprocessor. We have used Arduino Controller Board which is AN OPEN-SOURCE ELECTRONICS PROTOTYPING PLATFORM.
Output of LM35 is feed to Arduino Analog input pin 0.
Further Data is Processed by the C Program. Output of Micro-controller is connected to the 16X2 LCD
Below is the Simple Programme which is used here :-

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int inPin = 0;
void setup()
{
lcd.begin(16, 2);
}
void loop()
{
int x = analogRead(inPin);
lcd.setCursor(0, 1);
float millivolts = (x / 1024.0) * 5000;
float celsius = millivolts / 10;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(celsius);
lcd.print(” C”);
lcd.setCursor(0,1);
lcd.print((celsius * 9)/ 5 + 32);
lcd.print(” F”);
delay(1000);
}




Circuit Diagram of Digital Thermometer
If you are new to Arduino then follow below Instruction while making this Project :
1. After Buying Arduino Controller Board. Make sure it is working correctly. Just by connecting to USB computer will notify “New Hardware Found Message” You have to Install Driver and Software for it. You may need to do Jumper Setting on some board to switch between USB or External Power Source.
2. After above steps open Arduino Software and select correct board type (Very Imp) from Menu Tools -> Board . You can identify Your Arduino Board by reading main IC number.
3. To make sure above step is completed and all are functioning well, upload a simple Basic programme from the Arduino Library Examples. You have to add one resistance and LED. for eg you can do Blink Programme ( Turns on an LED on for one second, then off for one second) or LED Fade Programme.
4. Next Connect your Arduino Kit to 16X2 LCD. Here you have to add one more part which is 10K Variable Resistance. You will get absolutely nothing Charactor displayed on LCD if 10K preset is not adjusted correctly. If you are not sure then adjust it near about .5 Volt and latter it can be fine tuned for better contrast.
5. For easy connection and Preset soldering I recommend use of PCB. which is shown below. You can save this for printing on copper clad Board. You can make your own PCB by Heat Transfer method or by screen printing method otherwise use Dot Matrix Board or Bread Board. This PCB will help you in all project which used 16X2 LCD by reducing LCD Pin from 16 to 8 and easy connection.