-The working code for gsm sim900a
Purpose
- generate and testing the code
Description
#include <SoftwareSerial.h>
SoftwareSerial mySerial(12, 13);
LiquidCrystal lcd(6,7,8,9,10,11);
//int LED = 13;
const int pulse = 7;
float watt = 0.0, price = 0, unit = 0;
int pinState = 0 ;
unsigned int i=0, j=0, p=0;
unsigned long interval = 180000; //1000 1 sec - 60000 1 minutes - 3600000 1 hour
unsigned long intervalx = 10000; //1000 1 sec - 60000 1 minutes - 3600000 1 hour
unsigned long previousMillis = 0;
int sensorValue = 0; // variable to store the value coming from the sensor
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 4; // select the pin for the LED
int light_sensitivity = 700;
void setup()
{
//pinMode(LED, OUTPUT);
pinMode(pulse, INPUT);
pinMode (ledPin, OUTPUT);
mySerial.begin(9600);
Serial.begin (9600);
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("WELCOME TO AUTO");
lcd.setCursor(0,1);
lcd.print("BILLING SYSTEM");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("GSM DINIE");
lcd.setCursor(0,1);
lcd.print(" START ");
delay(2000);
lcd.clear();
}
void loop()
{
unsigned long currentMillis = millis();
pinState = digitalRead(pulse);
if (pinState==HIGH)
{
//digitalWrite(LED, HIGH);
i++;
delay(200);
}
if(currentMillis-previousMillis >=interval)
{
j=1;
previousMillis=currentMillis;
}
if(j==1)
{
watt = (i*0.3125);
unit = watt/100;
price = unit*0.0218;
mySerial.begin(9600);
mySerial.print("\r");
delay(800);
mySerial.println("AT+CMGF=1/r");
delay(800);
mySerial.println("AT+CMGS=\"+60196907858\"\r");
delay(800);
mySerial.println("Unit");
delay(800);
mySerial.println(unit,6);
delay(800);
mySerial.println("Price");
delay(100);
mySerial.println(price,6);
delay(100);
mySerial.println("RM");
delay(10);
mySerial.write(0x1A);
delay(100);
j=0;
}
if(currentMillis-previousMillis >=intervalx)
{
p=1;
previousMillis=currentMillis;
}
if(p==1)
{
sensorValue = analogRead (sensorPin);
Serial.println (sensorValue, DEC);
if(sensorValue > light_sensitivity)
{
sensorValue = analogRead (sensorPin);
digitalWrite (ledPin, LOW);
Serial.println (sensorValue, DEC);
mySerial.begin(9600);
mySerial.print("\r");
delay(800);
mySerial.println("AT+CMGF=1/r");
delay(800);
mySerial.println("AT+CMGS=\"+60196907858\"\r");
delay(800);
mySerial.println("LAMPU ON ");
delay(800);
mySerial.write(0x1A);
delay(100);
p=0;
}
else
{
sensorValue = analogRead (sensorPin);
digitalWrite (ledPin, HIGH);
Serial.println (sensorValue, DEC);
p=0;
}
}
}
No comments:
Post a Comment