The following system will measure the depth of the water and measured depth will be notified by two different ways. In section 5.2, depth will be displayed on the LCD display that is used and In section 5.3 depth will be sent to the given mobile number as a SMS.
5.1. Interfacing ultrasonic sensor with Arduino
Vcc pin of the Ultrasonic Sensor is connected to the 5V pin of
Arduino, GND
pin is connected to the GND pin, Trig pin is connected to
digital pin 8 of Arduino and Echo pin is connected to digital pin 7 of Arduino.
Ultrasonic
sensor
|
Arduino
|
Vcc
|
5V
|
Gnd
|
Gnd
|
Trig
|
pin 7
|
Echo
|
pin 8
|
5.2. Ultrasonic sensor with LCD
5.2.1 Circuit diagram:
5.2.2 Arduino Program:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int trig=7 ;
const int echo=8;
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
}
void loop()
{
lcd.clear();
long
timeDuration,cm;
pinMode(trig,OUTPUT);
digitalWrite(trig,LOW);
delayMicroseconds(4);
digitalWrite(trig,HIGH);
delayMicroseconds(10);
digitalWrite(trig,LOW);
pinMode(echo, INPUT);
timeDuration = pulseIn(echo, HIGH);
cm=
microTocms(timeDuration); //conversion of microseconds to centimeters
Serial.print(cm);
Serial.print("cm");
Serial.println();
lcd.print(cm);
lcd.print(" cm");
delay(1000);
}
long
microTocms(long microseconds)
{
// The speed of sound is
340 m/s or 29 microseconds per centimeter.
// The ping travels out
and back, so to find the distance of the
// object we take half
of the distance travelled.
return microseconds / (29 * 2);
}
5.2.3. Ouput of the System
5.3. Ultrasonic sensor with GSM
Following
system will use ultrasonic sensor to measure the water depth, then measured
distance will be sent to given mobile number.
5.3.2. Arduino Program:
const int trig=7
;
const int echo=8;
void setup()
{
Serial.begin(9600);
Serial1.begin(9600); //Baud
rate of the GSM/GPRS Module
Serial1.print("\r");
}
void loop()
{
long timeDuration,cm;
pinMode(trig,OUTPUT);
digitalWrite(trig,LOW);
delayMicroseconds(2);
digitalWrite(trig,HIGH);
delayMicroseconds(10);
digitalWrite(trig,LOW);
pinMode(echo, INPUT);
timeDuration = pulseIn(echo, HIGH);
cm=
microTocms(timeDuration);
Serial.print(cm);
Serial.print("cm");
Serial.println();
// delay(2000);
Serial1.print("AT+CMGF=1\r");
delay(1000);
Serial1.print("AT+CMGS=\"+919542081456\"\r"); //Number
to which you want to send the SMS
delay(1000);
Serial1.print(cm); //The
text of the message to be sent
Serial1.print("cm");
delay(1000);
Serial1.write(0x1A);
delay(20000);
}
long microTocms(long microseconds)
{
return microseconds / (29 * 2);
}
5.3.3. Output of the system
No comments:
Post a Comment