Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor flow air dan tekanan udara atau air secara bersamaan dengan menggunakan SMS gateway. alat ini menggunakan 2 buah sensor dan satu arduino serta modul sim900A. untuk lebih jelasnya berikut adalah proram dan daftar komponennya.
f. Program Arduino IDE
#include "SIM900.h"
#include <SoftwareSerial.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16,2);
int dataadc;
int x;
float v;
float kpa;
#include "sms.h"
SMSGSM sms;
byte sensorInterrupt = 0; // 0 = digital pin 2
byte sensorPin = 2;
float calibrationFactor = 4.5;
volatile byte pulseCount;
unsigned int frac;
float flowRate;
unsigned int flowMilliLitres;
float totalMilliLitres;
unsigned long oldTime;
float pressure_pascal;
float pressure_bar;
char string[160];
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
int presure;
char presstr[20];
void setup() {
Serial.begin(9600);
lcd.begin();
lcd.clear();
lcd.noCursor();
Serial.println("GSM Shield testing.");
if (gsm.begin(2400)) {
Serial.println("\nstatus=READY");
started=true;
} else Serial.println("\nstatus=IDLE");
if(started) {
// if (sms.SendSMS("085456789999", "Alat Ready"))
// Serial.println("\nSMS sent OK");
}
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0;
oldTime = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
void loop() {
if((millis() - oldTime) > 1000)
{
detachInterrupt(sensorInterrupt);
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
oldTime = millis();
flowMilliLitres = (flowRate / 60) * 1000;
totalMilliLitres += flowMilliLitres;
pulseCount = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
x = analogRead(A0);
v = x*(5.0/1023.0);
pressure_pascal = (3.0*(v-0.47))*1000000.0;
pressure_bar = pressure_pascal/10e5;
presure = pressure_bar;
lcd.setCursor(0, 0);
lcd.print("Bar= ");
lcd.print(pressure_bar);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print("ml/s= ");
lcd.print(flowMilliLitres);
lcd.print(" ");
delay(200);
dtostrf(pressure_bar,5,2,presstr);
sprintf(string,"Flow: %d Pressure: %s", flowMilliLitres, presstr);
int pos=0;
pos=sms.IsSMSPresent(SMS_ALL);
if(pos){
sms.GetSMS(pos,n,smsbuffer,100);
if(!strcmp(smsbuffer,"monitor")){
sms.SendSMS(n,string);
}
if(!strcmp(smsbuffer,"Monitor")){
sms.SendSMS(n,string);
}
delsms();
}
delay(100);
}
void pulseCounter()
{
pulseCount++;
}
void delsms()
{
for (int i=0; i<10; i++)
{
int pos=sms.IsSMSPresent(SMS_ALL);
if (pos!=0)
{
if (sms.DeleteSMS(pos)==1){}else{}
}
}
}
g. VIDEO HASILNYA
No comments:
Post a Comment