Mail Checker Final Post – Marcin Wieczorek

on
The Mail Checker 

Disassembled project
Cables running from the pressure switch to the GSM board

Assembled project in clear case
Main Checker on the inside of the mailbox
Charging Mail Checker using outside USB





























Final Code




#include <SoftwareSerial.h>
#include <String.h>

SoftwareSerial mySerial(7,8);

  int fsrPin = 0; // the FSR and 10K pulldown are connected to a0
int fsrReading; // the analog reading from the FSR resistor divider
//int fsrVoltage; // the analog reading converted to voltage
//unsigned long fsrResistance; // The voltage converted to resistance, can be very big so make “long”
//unsigned long fsrConductance;
//long fsrForce;
int buttonState = LOW;         // current state of the button

void setup()
{
  mySerial.begin(19200);               // the GPRS baud rate  
  Serial.begin(19200);    // the GPRS baud rate
  delay(500);
}

void loop()
{
  //after start up the program, you can using terminal to connect the serial of gprs shield,
  //if you input ‘t’ in the terminal, the program will execute SendTextMessage(), it will show how to send a sms message,
  //if input ‘d’ in the terminal, it will execute DialVoiceCall(), etc.
 
   fsrReading = analogRead(fsrPin);
Serial.print(“Analog reading = “);
Serial.println(fsrReading);

  //if (Serial.available())
  //  switch(Serial.read())
  // {
   
   if (fsrReading > 20 ) {  //
    if (buttonState == LOW) {
     Serial.println(“sendimg messaage”);
         Serial.println(“HIGH”);
delay(50);
      SendTextMessage();
  buttonState = HIGH;
    }
   delay(500);
}

 if (fsrReading < 15 ) {
     buttonState = LOW;
      Serial.println(“LOW”);
  }
   
 //  }
 // if (mySerial.available())
  //  Serial.write(mySerial.read());
}

///SendTextMessage()
///this function is to send a sms message
void SendTextMessage()
{
  mySerial.print(“AT+CMGF=1r”);    //Because we want to send the SMS in text mode
  delay(100);
  mySerial.println(“AT + CMGS = “+17738160916″”);//send sms message, be careful need to add a country code before the cellphone number
  delay(100);
  mySerial.println(“Mail has arrived!”);//the content of the message
  delay(100);
  mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
  mySerial.println();
}

///DialVoiceCall
///this function is to dial a voice call
//void DialVoiceCall()
//{
//  mySerial.println(“ATD + +17738160916;”);//dial the number
//  delay(100);
//  mySerial.println();
//}
//
void ShowSerialData()
{
  while(mySerial.available()!=0)
    Serial.write(mySerial.read());

}