Arduino GSM Expandable Vehicle Connection Project


/* This sketch is created for use of a GSM board with an arduino. The sensors utilized are 1x DHT11 + 2x BOCHEN 3386 Potentiometer + 5k resistor +
5V solar Array + 2 aluminum foils connected to 10k OHM resistors.
Copyright: Bobby Lumia, may be used and modified for personal use only. No resale.
Please reference my project blog: http://bobbobblogs.blogspot.ca/ if useing this sketch in your work.
*/

#include // Library Needed for our capacitance readings
#include // Library Needed for the tempeature readings

dht11 DHT11; // Declare our sensor, I bid thee dht11 … the first

//============================= \/ DEFINE PINS \/ ==============

//Do Not use Pins A4 & A5 … reserved for LCD
//Do not use Pins 0 & 1 (digital pins) these are used for GSM data transmission

int LED_1 = 4;                 // BABY Led
int LED_2 = 9;                 // DAD Led

int sol = A0;         // analogue pin 0
#define DHT11PIN A1   // analogue pin 1
int pot1 = A2;        // analogue pin 2
int pot2 = A3;        // analogue pin 3

CapacitiveSensor   cs_DAD = CapacitiveSensor(11,12);    // 10M resistor between pins 11 & 12, pin 12 is sensor pin, add a wire and or foil if desired
CapacitiveSensor   cs_BABY = CapacitiveSensor(6,7);    // 10M resistor between pins 6 & 7, pin 7 is sensor pin, add a wire and or foil if desired

//============================= \/ DEFINE VARIABLES \/ ==============

int const SAMPLES = 5;                         // number of samples taken to average out capacitance
int s_val[SAMPLES];                            //array to store the 5 samples to average
int const Initial_SAMPLES = 20;                // number of samples to initilize capacitance with
float RAW_initializer_VALS[Initial_SAMPLES];   // Array to hold initial Capacitance Values

int HIGH_Thresh;     // Threshold to trigger Capacitace 1 HIGH
int LOW_Thresh;      // Threshold to trigger Capacitace 1 LOW
int HIGH_Thresh_2;   // Threshold to trigger Capacitace 2 HIGH
int LOW_Thresh_2;    // Threshold to trigger Capacitace 2 LOW

int i;              // loop counter
int triggered = 0;  // Baby text trigger … don’t want to send out too many texts

long start;         // Start the timer for performance monitoring
float Where_DAD;      // Start the Where’s DAD counter
float Cap_1;        // Capacitance Sensor – 1
float Cap_2;        // Capacitance Sensor – 2
float SolVolt;      // Solar Voltage value (0-5 Volt)
float Amb_Temp;     // Ambient temperature Variable
int chk;            // Checks the Temperature sensor status and possible faults
int pot1Value;      // Potentiometer 1 value — Used to calibrate Capacitor 1 Trigger sensitivity
int pot2Value;      // Potentiometer 1 value — Used to calibrate Capacitor 2 Trigger sensitivity
int T_multi = 4;    // Scaling factor for threshold (1 = 1024, 2 = 2048 MAX)

char str1[]={‘A’,’T’,’+’,’C’,’S’,’C’,’S’,’=’,'”‘,’G’,’S’,’M’,'”‘};  // AT+CSCS=”GSM”  — This sets:  GSM default alphabet
char str2[]={‘A’,’T’,’+’,’C’,’M’,’G’,’S’,’=’,'”‘,’1′,’7′,’7′,’8′,’8′,’8′,’2′,’1′,’8′,’6′,’7’,'”‘};  // AT+CMGS=”17788821867″  — This sets Phone number to Text
char hex1[]={0x1A};  // Stop Character used to signify the end of a Text Msg

void setup()                  
{
   Serial.begin(115200);
 
   pinMode(LED_1, OUTPUT);           // set pin to output
   pinMode(LED_2, OUTPUT);           // set pin to output
   pinMode(LED_1+1, OUTPUT);           // set pin to output
   pinMode(LED_2+1, OUTPUT);           // set pin to output
 
   Serial.println();
   Serial.println(“Starting GSM Communication…”); //Just an FYI … not really chacking anything
   Serial.println();
}

void loop()                  
{

    ReadSensors();               // All sensor readings grouped in a function
    Print_Sensor_Vals_Serial();  // Now print these values on the screen for all to see!
 
    if (Cap_2 > HIGH_Thresh_2) LED_1_ON();
    else LED_1_OFF();
 
    if (Cap_1 > HIGH_Thresh) LED_2_ON();
    else LED_2_OFF();
 
    delay(200); // no use reading less than half a second … it just confuses the sensors (mostly temp)
 
    if (Cap_2 > HIGH_Thresh_2){ // If Baby is in seat
      if (Cap_1 < LOW_Thresh) { // If daddy in not there
         if (triggered == 0){
           Where_DAD = millis(); // DAD, your timer has begin
           triggered = 1; // Level 1 trigger
           Serial.println();Serial.println();Serial.println(“Countdown Begins! Where are you dad?”);Serial.println();
         }
       
         if ((millis() – Where_DAD > (5.0 * 1000.0)) && triggered == 1){ // If daddy is still not there after 120 seconds
           Serial.println();
           SendTXT();  // Send dad a text to tell him that something is wrong
           triggered = 2; // Level 2 trigger
           Serial.println();Serial.println();Serial.println(“Baby on Board! Where are you dad? THIS IS AN ALARM”);Serial.println();
         }
      }
   
      if (triggered == 1){
         Serial.print((millis() – Where_DAD)/1000.0,1);Serial.print(” Seconds .. “);Serial.println();
         LED_1_OFF();
       }
     
       if ((millis() – Where_DAD > (5.0 * 1000.0)) && triggered == 1){ // If daddy is still not there after 120 seconds
         Serial.println();
         SendTXT();  // Send dad a text to tell him that something is wrong
         triggered = 2; // Level 2 trigger
         Serial.println();Serial.println();Serial.println(“Baby on Board! Where are you dad? THIS IS AN ALARM”);Serial.println();
       }
     
    }
 
    if ((Cap_2 HIGH_Thresh&& (triggered == 2 || triggered == 1))){ // Stop panic if, Baby is removed, or Dad has arrived … after an even was triggered
      triggered = 0;
      Serial.println();Serial.println();Serial.println(“Baby SAFE!”);Serial.println();
    }
}

void ReadSensors()
{
    start = millis();  
 
    Cap_1 = avg(); // DAD Read capacitor time constant 1
    Cap_2 = avg2(); // BABY Read capacitor time constant 2
 
    SolVolt = analogRead(sol) * (5.0 / 1023.0); // Read output voltage created by the SUN!
 
    pot1Value = analogRead(pot1);
    pot2Value = analogRead(pot2);
 
    chk = DHT11.read(DHT11PIN);
    Amb_Temp = DHT11.temperature;
 
    HIGH_Thresh = T_multi*pot1Value;
    LOW_Thresh = T_multi*pot1Value-100;
    HIGH_Thresh_2 = T_multi*pot2Value;
    LOW_Thresh_2 = T_multi*pot2Value-100;    
}

void Print_Sensor_Vals_Serial()
{
  if (triggered != 1){
    Serial.print(“performance:   “);
    Serial.print(millis() – start);        // check on performance in milliseconds
    Serial.print(“\t”);Serial.print(“\t”); // tab character for debug windown spacing

    Serial.print(“C1: “);
    Serial.print(Cap_1);Serial.print(“/”); // print sensor output 1 / Threshold
    Serial.print(HIGH_Thresh);
    if (Cap_1 > HIGH_Thresh) Serial.print(“*PROXI*”);
    else Serial.print(”       “);
    Serial.print(“\t”);                    // tab character for debug windown spacing
 
    Serial.print(“C2: “);
    Serial.print(Cap_2);Serial.print(“/”); // print sensor output  / Threshold
    Serial.print(HIGH_Thresh_2);
    if (Cap_2 > HIGH_Thresh_2) Serial.print(“*PROXI*”);
    else Serial.print(”       “);
    Serial.print(“\t”);                    // tab character for debug windown spacing
 
    switch (chk){
      case 0: Serial.print(“Temperature: “); Serial.print(Amb_Temp); Serial.print(” oC”); if (Amb_Temp > 38.0) Serial.println(“*TEMP*”); break;
      case -1: Serial.print(“Checksum ERR: data was received but may not be correct”); break;
      case -2: Serial.print(“Timeout ERR: communication has failed”); break;
      default: Serial.print(“Unknown ERR: this is the catch-all bucket … S.O.L. buddy”); break;
    }

    Serial.print(“\t”);                    // tab character for debug windown spacing
    Serial.print(“Solar Voltage: “);
    Serial.print(SolVolt, 2);
    if (SolVolt > 4.0) Serial.print(“*SUN*”);
    Serial.println();
  }
}

float avg()
{
  float sampleSum = 0;
  for(int i = 0; i < SAMPLES; i++) {
    s_val[i] = cs_DAD.capacitiveSensor(15);
    sampleSum += s_val[i];
    delay(1); // set this to whatever you want
  }
  float meanSample = sampleSum/float(SAMPLES);
  return meanSample;
}

float avg2()
{
  float sampleSum = 0;
  for(int i = 0; i < SAMPLES; i++) {
    s_val[i] = cs_BABY.capacitiveSensor(15);
    sampleSum += s_val[i];
    delay(1); // set this to whatever you want
  }
  float meanSample = sampleSum/float(SAMPLES);
  return meanSample;
}

void SendTXT()
{
      for(i=0;i<13;i++)
        Serial.print(str1[i]);//AT+CSCS=”GSM”  ==> It must be done this way due to double quotes
      Serial.println();
   
      for(i=0;i<21;i++)
        Serial.print(str2[i]);//AT+CMGS=”17788821867″  ==> It must be done this way due to double quotes
      Serial.println();
   
      Serial.print(“Baby may be in danger!”);
      delay(1000);
      Serial.print(hex1);
      delay(1000);
      Serial.println();
}

void LED_1_ON(){
  digitalWrite(LED_1, HIGH);       // turn on
  digitalWrite(LED_1+1, LOW);       //
}

void LED_1_OFF(){
  digitalWrite(LED_1, LOW);       // turn off
  digitalWrite(LED_1+1, LOW);       //
}

void LED_2_ON(){
  digitalWrite(LED_2, HIGH);       // turn on
  digitalWrite(LED_2+1, LOW);       //
}

void LED_2_OFF(){
  digitalWrite(LED_2, LOW);       // turn off
  digitalWrite(LED_2+1, LOW);       //
}

4 thoughts on “Arduino GSM Expandable Vehicle Connection Project”

  1. Hi, i think that i saw you visited my blog thus i came to “return the favor”.I’m trying to find things
    to enhance my website!I suppose its ok to use a few of
    your ideas!

  2. This is reeally interesting, You’re an overly skilled blogger.
    I’ve joined your feed and sit up for in thee hunt for extra of your
    wonderful post. Also, I’ve shared your web site in my social
    networks!

  3. I’ve gone to inform my little brother, that he should also go see your web site on regular basis to get updated from latest news.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s