Monday 19 November 2012

PROGRAMMING EARLY WARNING FAULT DETECTION SYSTEM

Coding for Early Warning Fault Detection System.

#include <GSM_Shield.h>
# define LED 13
# define BUTTON 7

GSM gsm;
int error;
int hits = 0;
float wheel_radius = 1;
volatile unsigned int current_time;
long time_interval = 1000; //how often do you want to know velocity (milliseconds)
float velocity; //this is the velocity in length units / time_interval

//**************************************************************************
char number[]="+60166638494";  //Destination number
char text[]="MOTOR OVERLOAD  SYSTEM TRIP  PLEASE CHECKING!!!    sent by GSM Arduino";  //SMS to send
byte type_sms=SMS_UNREAD;      //Type of SMS
byte del_sms=0;                //0: No deleting sms - 1: Deleting SMS
//**************************************************************************
 
void setup ()
{

  Serial.begin(9600);
  attachInterrupt(0, count, CHANGE);
  current_time = millis();
  Serial.println("system startup");
  gsm.TurnOn(9600);          //module power on
  gsm.InitParam(PARAM_SET_1);//configure the module
  gsm.Echo(0);               //enable AT echo
  pinMode (LED, OUTPUT);
  pinMode(BUTTON, INPUT);

}

void loop ()
{

  if ( millis() >= current_time + time_interval)
  {

    velocity = (hits*(wheel_radius * 392.7))/time_interval;//the constant is 2*pi*1000/16
    Serial.println(velocity);
    hits = 0;
    current_time = millis();
   
     if (velocity < 10)
    {

    digitalWrite(LED, HIGH);
    Serial.print("Send SMS to ");
    Serial.println(number);
    error=gsm.SendSMS(number,text);

    }

  }
}

void count()
{

 hits++;

}

No comments:

Post a Comment