Upload
sharif-mohd-zaki
View
28
Download
2
Embed Size (px)
DESCRIPTION
AC Project Report
Citation preview
FACULTY OF MECHANICAL ENGINEERING
BMM3613 AUTOMATIC CONTROL
PROJECT REPORT
Title : TEMPERATURE HISTORY GRAPH MONITOR USING ARDUINO
Lecturer’s Name : Dr. FADHLUR RAHMAN BIN MOHD ROMLAY
NAME MATRIC NO. SECTION NO.
Sharif Bin Mohd Zaki MH11016 01
Muhamad Magffierah Bin Razali MH11023 01
Ahmad Hakim Bin Badrul Hisham MH11017 01
Abstract
Description:
A history monitor graph is a special idea which makes to read the current ambient temperature and calculate an average, minimum and maximum and display all these to the LCD display.
Block diagram:
Platforms to be used:
Hardware: Arduino board, LM35 sensor, LCD Software: Arduino IDE
LM35 (Temperatur sensor)
Arduino Uno Display (LCD)
TABLE OF CONTENTS PAGES
ABSTRACT ii
CHAPTER I INTRODUCTION1.1 Background intro. 11.2 Aim of the project 11.3 Problem statement 11.4 Significance of this work 11.5 Conclusion 1-2
CHAPTER II ARDUINO2.1 Overview 32.2 Schematic and reference design 42.3 Summary 52.4 Power 5-62.5 Memory2.6 Input and Output2.7 Communication2.8 Programming2.9 Automatic reset2.10 USB Overcurrent protection2.11 Physical Characteristics
77-88
8-991010
CHAPTER III PROJECT DESCRIPTION3.1 Circuit diagram 11-123.2 Source code 12-203.3 Flow Chart 213.4 Program 22-26
REFERENCES 27
Chapter 1
INTRODUCTION
1.1 Introduction
This project is designed to be a temperature data logger measuring the following with respects to time:
1. Current Temperature2. Average Temperature3. Rate of Change in Temperature
1.2 Aim of the project
The aim of our project is to give information about surrrounding temperature, and displayed it into the display, using arduino.
1.3 Problem statement
1. How can we accurately and purposefully present temperature data to a user?
2. How can we allow so many hardware components to communicate with each other?
1.4 Significance of this work
Initial motivations were to allow the user to be able to monitor temperature conditions, both from their computer and in person.
Possible applications include:
Heating and Cooling Systems.
Geological/Environmental Temperature Surveying.
1.5 Conclusion
As the concluding part of this project, we would like to say that--
"Without proper action at proper time, danger awaits us with a bigger face." We must act on time when a person is injured. We must take care of person the way it is meant. otherwise, a
1
valuable life might be lost .We need to understand how precious lives of people are and what importance first-aid carries in saving these precious lives.
If this project imparts this idea in even one person, I would think that the project will be successful.
2
Chapter 2
ARDUINO
2.1 Overview
The Arduino Uno is a microcontroller board based on the ATmega328 . It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic resonator, a USB connection, a power jack, an ICSP header, and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get started.
The Uno differs from all preceding boards in that it does not use the FTDI USB-to-serial driver chip. Instead, it features the Atmega16U2 (Atmega8U2 up to version R2) programmed as a USBto-serial converter.
Revision3 of the board has the following new features:
1.0 pinout: added SDA and SCL pins that are near to the AREF pin and two other new pins
placed near to the RESET pin, the IOREF that allow the shields to adapt to the voltage
provided from the board. In future, shields will be compatible both with the board that
use the AVR, which operate with 5V and with the Arduino Due that operate with
3.3V. The second one is a not connected pin, that is reserved for future purposes.
Atmega 16U2 replace the 8U2.
"Uno" means one in Italian and is named to mark the upcoming release of Arduino 1.0.
The Uno and version 1.0 will be the reference versions of Arduino, moving forward. The
Uno is the latest in a series of USB Arduino boards, and the reference model for the
Arduino platform; for a comparison with previous version
3
The Arduino reference design can use an Atmega8, 168, or 328, Current models use an
ATmega328, but an Atmega8 is shown in the schematic for reference. The pin configuration is
identical on all three processors.
4
Schematic & Reference Design 2.2
2.3 Summary
Microcontroller ATmega328
Operating Voltage
Input Voltage
5V
(recommended) 7-12V
Input Voltage (limits) 6-20V
Digital I/O Pins 14 (of which 6 provide PWM output)
Analog Input Pins 6
DC Current per I/O Pin 40 mA
DC Current for 3.3V Pin 50 mA
Flash Memory 32 KB (ATmega328) of which 0.5 KB used by bootloader
SRAM 2 KB (ATmega328)
EEPROM 1 KB (ATmega328)
Clock Speed 16 MHz
2.4 Power
The Arduino Uno can be powered via the USB connection or with an external power supply. The
power source is selected automatically.
External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or battery.
The adapter can be connected by plugging a 2.1mm center-positive plug into the board's power
jack. Leads from a battery can be inserted in the Gnd and Vin pin headers of the POWER
connector.
The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V,
however, the 5V pin may supply less than five volts and the board may be unstable. If using
more than 12V, the voltage regulator may overheat and damage the board. The recommended
range is 7 to 12 volts. The power pins are as follows:
VIN. The input voltage to the Arduino board when it's using an external power source (as
opposed to 5 volts from the USB connection or other regulated power source). You can
supply voltage through this pin, or, if supplying voltage via the power jack, access it
through this pin.
5
5V.This pin outputs a regulated 5V from the regulator on the board. The board can be supplied
with power either from the DC power jack (7 - 12V), the USB connector (5V), or the VIN pin of
the board (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the regulator, and can
damage your board. We don't advise it.
3V3. A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50 mA.
GND. Ground pins.
IOREF. This pin on the Arduino board provides the voltage reference with which the
microcontroller operates. A properly configured shield can read the IOREF pin voltage
and select the appropriate power source or enable voltage translators on the outputs for
working with the 5V or 3.3V.
6
2.5 Memory
The ATmega328 has 32 KB (with 0.5 KB used for the bootloader). It also has 2 KB of SRAM
and 1 KB of EEPROM (which can be read and written with the EEPROMlibrary).
2.6 Input and Output
Each of the 14 digital pins on the Uno can be used as an input or output, using pinMode(),
digitalWrite(), and digitalRead()functions. They operate at 5 volts. Each pin can provide or
receive a maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of
20-50 kOhms. In addition, some pins have specialized functions:
Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data.
These pins are connected to the corresponding pins of the ATmega8U2 USB-to-TTL
Serial chip.
External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a
low value, a rising or falling edge, or a change in value. See the attachInterrupt() function
for details.
PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function.
SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication
using the SPI library.
LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH value,
the LED is on, when the pin is LOW, it's off.
The Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits of
resolution (i.e. 1024 different values). By default they measure from ground to 5 volts,
though is it possible to change the upper end of their range using the AREF pin and the
analogReference() function. Additionally, some pins have specialized functionality:
TWI: A4 or SDA pin and A5 or SCL pin. Support TWI communication using the Wire
library.
There are a couple of other pins on the board:
AREF. Reference voltage for the analog inputs. Used with analogReference().
7
Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset
button to shields which block the one on the board.
2.7 Communication
The Arduino Uno has a number of facilities for communicating with a computer, another
Arduino, or other microcontrollers. The ATmega328 provides UART TTL (5V) serial
communication, which is available on digital pins 0 (RX) and 1 (TX). An ATmega16U2 on the
board channels this serial communication over USB and appears as a virtual com port to software
on the computer. The '16U2 firmware uses the standard USB COM drivers, and no external
driver is needed. However, on Windows, a .inf file is required. The Arduino software includes a
serial monitor which allows simple textual data to be sent to and from the Arduino board. The
RX and TX LEDs on the board will flash when data is being transmitted via the USB-to-serial
chip and USB connection to the computer (but not for serial communication on pins 0 and 1).
A Software Serial library allows for serial communication on any of the Uno's digital pins.
The ATmega328 also supports I2C (TWI) and SPI communication. The Arduino software
includes a Wire library to simplify use of the I2C bus; see the documentation for details. For SPI
communication, use the SPI library.
2.8 Programming
The Arduino Uno can be programmed with the Arduino software.
The ATmega328 on the Arduino Uno comes preburned with a bootloader that allows you to
upload new code to it without the use of an external hardware programmer. It communicates
using the original STK500 protocol (reference, C headerfiles).
You can also bypass the bootloader and program the microcontroller through the ICSP (InCircuit
Serial Programming) header; see these instructions for details.
The ATmega16U2 (or 8U2 in the rev1 and rev2 boards) firmware source code is available .
The ATmega16U2/8U2 is loaded with a DFU bootloader, which can be activated by:
On Rev1 boards: connecting the solder jumper on the back of the board (near the map of Italy) and then resetting the 8U2.
On Rev2 or later boards: there is a resistor that pulling the 8U2/16U2 HWB line to ground,
making it easier to put into DFU mode.
You can then use Atmel's FLIP software (Windows) or the DFU programmer (Mac OS X
and Linux) to load a new firmware. Or you can use the ISP header with an external
8
programmer (overwriting the DFU bootloader). See this user-contributed tutorial for
more information.
2.9 Automatic (Software) Reset
Rather than requiring a physical press of the reset button before an upload, the Arduino Uno is
designed in a way that allows it to be reset by software running on a connected computer. One of
the hardware flow control lines (DTR) of theATmega8U2/16U2 is connected to the reset line of
the ATmega328 via a 100 nanofarad capacitor. When this line is asserted (taken low), the reset
line drops long enough to reset the chip. The Arduino software uses this capability to allow you
to upload code by simply pressing the upload button in the Arduino environment. This means
that the bootloader can have a shorter timeout, as the lowering of DTR can be well-coordinated
with the start of the upload.
This setup has other implications. When the Uno is connected to either a computer running Mac
OS X or Linux, it resets each time a connection is made to it from software (via USB). For the
following half-second or so, the bootloader is running on the Uno. While it is programmed to
ignore malformed data (i.e. anything besides an upload of new code), it will intercept the first
few bytes of data sent to the board after a connection is opened. If a sketch running on the board
receives one-time configuration or other data when it first starts, make sure that the software with
which it communicates waits a second after opening the connection and before sending this data.
The Uno contains a trace that can be cut to disable the auto-reset. The pads on either side of the
trace can be soldered together to re-enable it. It's labeled "RESET-EN". You may also be able to
disable the auto-reset by connecting a 110 ohm resistor from 5V to the reset line.
9
2.10 USB Overcurrent Protection
The Arduino Uno has a resettable polyfuse that protects your computer's USB ports from shorts
and overcurrent. Although most computers provide their own internal protection, the fuse
provides an extra layer of protection. If more than 500 mA is applied to the USB port, the fuse
will automatically break the connection until the short or overload is removed.
2.11 Physical Characteristics
The maximum length and width of the Uno PCB are 2.7 and 2.1 inches respectively, with the
USB connector and power jack extending beyond the former dimension. Four screw holes allow
the board to be attached to a surface or case. Note that the distance between digital pins 7 and 8
is 160 mil (0.16"), not an even multiple of the 100 mil spacing of the other pins.
10
Chapter 3
PROJECT DESCRIPTION
3.1 Circuit diagram
To connect and use the LCD Display with arduino we followed the Hello world example
from the Arduino Library Examples (http://arduino.cc/en/Tutorial/LiquidCrystal). While the
LCD has an 8bit parallel connection it is possible to display almost everything with just 4bits.
To wire your LED screen to your Arduino, connect the following pins:
• LCD RS pin to digital pin 12
• LCD Enable pin to digital pin 11
• LCD D4 pin to digital pin 5
• LCD D5 pin to digital pin 4
• LCD D6 pin to digital pin 3
• LCD D7 pin to digital pin 2
11
Here is a picture illustrating how to connect the LM35 temperature sensor.
3.2 Source code
// Arduino LCD Ambient Temperature and temperature history graph Monitor.
// Displays Current temp, Max and Min Temperature and graph 30 logged averages of 10 temperature points sampled at defined period over time.
// Graph is created using the custom characters of an HC44780 16x2 LCD disply.
// To wire your LED screen to your Arduino, connect the following pins:
//LCD RS pin to digital pin 12
//LCD Enable pin to digital pin 11
//LCD D4 pin to digital pin 5
//LCD D5 pin to digital pin 4
12
//LCD D6 pin to digital pin 3
//LCD D7 pin to digital pin 2
// Additionally, wire a 10K pot to +5V and GND, with it's wiper (output) to LCD screens VO pin (pin3).
// We used the on board power source (5v and Gnd) to power the LM35 and analog pin 0 (zero) to read the analog output from the sensor.
// 8/12/2014
// include the library code:
#include <LiquidCrystal.h> // include the LCD driver library>
//// PINS ////
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Set the connections of LCD with Arduino.
//// I2C ADDRESSES ////
// DS1307 RTC chip
#define clockAddress (B1101000) // Not used here. This is for the next part of the datalogger project
#define updatetime 300 // 6 box graph time = updatetime*10*30 milisec /1000 sec. This is the period in milis that each sample is stored to array in memory (or same logging storage in future)
unsigned int tempreadcount=0; // a counter for loops
byte test ;
float tempC = 0; // variable for holding Celcius temp (floating for decimal points precision)
float tempCp = 0; // variable for holding Celcius last temp (floating for decimal points precision)
int tempPin = 0; // Declaring the Analog input to be 0 (A0) of Arduino board for LM35.
float volt = 4.85; // Volts at supply pins of LM35. Need this so that LM35 can correctly read ambient temperature.
int ledPin = 13; // define the output for red led on Arduino board in this variable. Maybe in other pin in future.
unsigned long currentTime; // This variable is need to keep current value of milis(); function
unsigned long loopTime; // This variable is need to keep updated value of milis(); function for comparison reasons.
13
int temp = 0;
byte grafChar[8] = { // this is the array to feed to custom HC44780 lcd characted. Initialize as empty (nothing is displayed.)
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000,
B00000
}; // this is for the graph characher created
byte degChar[8] = { // array to feed custom LCD char to create the degrees symbol
B00110,
B01001,
B01001,
B00110,
B00000,
B00000,
B00000,
B00000
};
float temparray[10]; // array to hold 10 temperature samples temperature measurements. Evewytime is filled average of 10 is calculated and new point is added to graph.
int i=0; // counter for loops
int countcol; // column of custom character 5x8 array.
int mempos = 0; // custom LCD character number selection initialized , see setup for real value
int glcdpos = 0; // first graph character position initialized, see setup for value real value
int temparraycounter=0; // position indicator for temp array
float mintemp = 20; // set initial minimum Temperature
14
float maxtemp = 22; // set initial minimum Temperature
float average = 0; // variable to hold average of temparray when it's filled/
// FUNCTIONS TO MAKE LOOP CODE SIMPLER AND BE ABLE TO REUSE TO OTHER PROJECTS.
// function to get graph point height
int getheight ( float tempnow , float minT , float maxT ) { // takes measurements , minimum and maximum temperature and reurns a value from 0 to 7
if (tempnow <= minT) return 0; // lowest graph point
if (tempnow >= maxT) return 7; // highest graph point
if (tempnow > minT & tempnow < maxT) {
return (tempnow - minT)*8/(maxtemp - minT); // here is the way values from 1 to 6 are calculated
}
}
// function to make graph point in hc 77480 special characters
int createpoint (int row, int col, int hcchar) { // takes as input the row(height) , the column of custom char that it must be set, and custom character memory position at LCD.
lcd.setCursor(9, 1); // just to verify height . remove it afterwards
lcd.print(row); // just to verify height. remove it afterwards
row = 7 - row; // lcd character 0 is top left so invert coordinates
col = 4 -col; // lcd character 0 is top left so invert coordinates
while (row < 8 ){
bitSet(grafChar[row], col ) ; // this loop sets 1 the bit of the needed pixel and all below that at graphChar bitarray so as to display a bar!
row++;
}
lcd.createChar(hcchar, grafChar); // write to custom character the contents of grafChar array.
return 1; // not used
}
15
// function to set clear custom graph chararacter matrix (not an independent function, just to make loop code neater
void clearchar() { // a quick way to set all grafChar bits back to zero so as to creat a new one.
int countj=0;
while (countj < 8) {
grafChar[countj] = B00000;
countj++;
}
return;
} // end clear char
// function to clear range of LCD custom characters. Needs graph char to be set to nothing first (clearchar)
void clearcustomchar (int first , int second) { // clear the custom character LCD memory at the range given at function input.
int counter = first;
while (counter < second+1) {
lcd.createChar(counter, grafChar);
counter++;
}
return;
} // end clearcustomchar
// function to find average of temparray (not an independent function , just to clear the loop code)
void averagecalc() {
temparraycounter = 0; // initialize counter
average=0; // set average variable back to zero
while (temparraycounter < 10) { // add the 10 temparray elements and store sum to average
average = average + temparray[temparraycounter];
temparraycounter++; // increase temparrayposition
}
average = (average / 10); // get average of 10 measurements
temparraycounter = 0; // needs to be set again to zero because it's used in various places.
} // end averagecalc()
16
// function to update min and max temp values whenever average is calculated. (not an independent function , just to clear the loop code)
void minmaxupdate() {
if (average > maxtemp) { // update maximum temperature
maxtemp = average;
}
if (average < mintemp) { // update minimum temperature
mintemp = average;
}
} // end minmaxupdate
// END OF FUNCTIONS
void setup() {
pinMode(ledPin, OUTPUT); // sets the digital pin as output
currentTime = millis();
loopTime = currentTime;
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.createChar(0, degChar); // degrees Celcius symbol
// Intro text
lcd.setCursor(0, 0); // set LCD cursor position (column, row)
lcd.print("Gmen's second "); // print text to LCD
lcd.setCursor(0, 1);
lcd.print("Arduino project");
delay(5000); // wait 500ms
lcd.clear(); // clear LCD display
lcd.setCursor(0, 0);
lcd.print("Temp monitor with");
lcd.setCursor(0, 1);
lcd.print("6seg graph chart");
delay(5000);
lcd.clear();
17
// end intro text
clearchar(); // clear graph character array
clearcustomchar(1,6); // write the cleared grafchar array to custom LCD memory poitions
lcd.setCursor(10, 1); // set cursor to first graph LCD text elements.
lcd.write(1); // write to screen the first custom graph character.
lcd.setCursor(11, 1);
lcd.write(2);
lcd.setCursor(12, 1);
lcd.write(3);
lcd.setCursor(13, 1);
lcd.write(4);
lcd.setCursor(14, 1);
lcd.write(5);
lcd.setCursor(15, 1);
lcd.write(6);
countcol = 0;
mempos = 1; // defines first screen position for graph
glcdpos = 10; // first graph character position
lcd.setCursor(2, 1);
lcd.print((int)updatetime); // milis
} // end void setup
void loop () {
//get and print current temperature every second
tempC = ( volt * analogRead(tempPin) * 100.0) / 1024.0; // conversion math of LM35 sample to readable temperature and stores result to samples array. 1024 is the Bit depth (quantization) of Arduino.
// 5 is the supply volts of LM35. Change appropriatelly to have correct measurement. My case is 4.85Volts.
lcd.setCursor(9, 0);
18
lcd.print(tempC);
lcd.write(0);
lcd.print("C");
// update temparray every msec period set by updatetime constant
currentTime = millis();
if(currentTime >= (loopTime + updatetime)){
temparray[temparraycounter] = tempC; // store current temperature to temp array
digitalWrite(ledPin, !digitalRead(ledPin)); // toggles the LED on/off
lcd.setCursor(0, 1);
lcd.print(temparraycounter);
temparraycounter++; // increase temparrayposition
loopTime = currentTime; // Updates loopTime
}
// end of get and print current temperature every second
// create a graph point every 10 seconds
if (temparraycounter == 10) {
digitalWrite(ledPin, !digitalRead(ledPin)); // toggles the LED on/off
lcd.setCursor(0, 0);
lcd.print((int)countcol);
lcd.print(" ");
lcd.print((int)mempos);
averagecalc(); // calculate average
minmaxupdate(); // update min and max values from average
lcd.setCursor(6, 0); // set positition to print max average temperature to display
lcd.print((int)maxtemp); // print max average temperature to display
lcd.setCursor(6, 1); // set positition to print min average temperature to display
lcd.print((int)mintemp); // print min average temperature to display
temp = getheight(average,mintemp,maxtemp); // call my getheight function to calculate new point's heght value (0-7)
19
createpoint (temp,countcol,mempos); //gives graph column height,column and custom LCD character number to function (mempos-9 makes custom character 1 the first custom graph character).
countcol++; // increase column counter (0-4)
if (countcol == 5) { // if lcd element column is exceeded (5) then
mempos++; // go to next custom lcd char memory position
glcdpos++; // increase lcd element position
countcol=0; // go to new characters first column.
clearchar(); // clear the gradChar array
}
if (glcdpos == 16) { // if last graph elements is completed then
mempos = 1; //go to first custom lcd character
glcdpos = 10; // set the graph char position back to (10,1)
clearcustomchar(1,6); // erase all custom chars in LCD'S memory..
}
}
delay(100);
} // end void loop()
20
3.3 Flow Chart
21
3.4 PROGRAM
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include "SIM900.h"
#include "sms.h" SMSGSM sms;
boolean started= false;
// GPS parser for 406a
#define BUFFSIZ 45 // plenty big int ledpin = 13; int knockSensor = A0; // the piezo is connected to analog pin 0 int threshold = 30; // threshold value to decide when the detected sound is a knock or not int sensorReading = 0; char buffer[BUFFSIZ]; char *parseptr; char buffidx; uint8_t hour, minute, second, year, month, date; int latitude, longitude; uint8_t groundspeed, trackangle; char latdir, longdir; char status;
void setup()
{
if (ledpin)
{
pinMode(ledpin, OUTPUT);
}
pinMode(13, OUTPUT);
Serial.begin(9600); // prints title with ending line break Serial.println("GPS parser"); digitalWrite(ledpin, LOW); // pull low to turn on!
}
void loop()
{ int tmp; sensorReading = analogRead(knockSensor); if (sensorReading >= threshold)
{
Serial.print("\n\rread: "); readline(); // check if $GPRMC (global positioning fixed data) if (strncmp(buffer, "$GPRMC",6) == 0)
{
22
// hhmmss time data parseptr = buffer+7; tmp = parsedecimal(parseptr); hour = tmp / 10000; minute = (tmp / 100) % 100; second = tmp % 100; parseptr = strchr(parseptr, ',') + 1; status = parseptr[0]; parseptr += 2;
// grab latitude & long data
// latitude latitude = parsedecimal(parseptr); if (latitude != 0)
{
latitude *= 10000; parseptr = strchr(parseptr, '.')+1; latitude += parsedecimal(parseptr);
}
parseptr = strchr(parseptr, ',') + 1; // read latitude N/S data if (parseptr[0] != ',')
{
latdir = parseptr[0];
}
Serial.print(latdir);
// longitude
parseptr = strchr(parseptr, ',')+1; longitude = parsedecimal(parseptr); if (longitude != 0)
{
longitude *= 10000; parseptr = strchr(parseptr, '.')+1; longitude += parsedecimal(parseptr);
}
23
parseptr = strchr(parseptr, ',')+1; // read longitude E/W data if (parseptr[0] != ',')
{
longdir = parseptr[0];
}
Serial.print(longdir);
// groundspeed parseptr = strchr(parseptr, ',')+1; groundspeed = parsedecimal(parseptr);
// track angle parseptr = strchr(parseptr, ',')+1; trackangle = parsedecimal(parseptr);
// date parseptr = strchr(parseptr, ',')+1; tmp = parsedecimal(parseptr); date = tmp / 10000; month = (tmp / 100) % 100; year = tmp % 100;
Serial.print("\nTime: ");
Serial.print(hour, DEC); Serial.print(':');
Serial.print(minute, DEC); Serial.print(':');
Serial.println(second, DEC);
Serial.print("Date: ");
Serial.print(month, DEC); Serial.print('/');
Serial.print(date, DEC); Serial.print('/');
Serial.println(year, DEC);
Serial.print("Lat: "); if (latdir == 'N') Serial.print('+'); else if (latdir == 'S')
24
Serial.print('-');
Serial.print(latitude/1000000, DEC); Serial.print('\°'); Serial.print(' ');
Serial.print((latitude/10000)%100, DEC); Serial.print('\''); Serial.print(' ');
Serial.print((latitude%10000)*6/1000, DEC); Serial.print('.');
Serial.print(((latitude%10000)*6/10)%100, DEC); Serial.println('"');
Serial.print("Long: "); if (longdir == 'E') Serial.print('+'); else if (longdir == 'W')
Serial.print('-');
Serial.print(longitude/1000000, DEC); Serial.print('\°'); Serial.print(' ');
Serial.print((longitude/10000)%100, DEC); Serial.print('\''); Serial.print(' ');
Serial.print((longitude%10000)*6/1000, DEC); Serial.print('.');
Serial.print(((longitude%10000)*6/10)%100, DEC); Serial.println('"');
Serial.print(latitude); Serial.print(longitude); latitude=lati[10]; longitude=longi[10]; Serial.print(lati);
Serial.print(longi);
Serial.println(buffer); delay(1000);
Serial.println("GSM Testing to send SMS"); if (gsm.begin(9600))
{
Serial.println("\nstatus=READY"); started=true;
} else
{
Serial.println("\nstatus=IDLE");
} if(started)
25
{
if (sms.SendSMS("+919052378836", "accident has occured at")) if (sms.SendSMS("+919052378836", buffer))
Serial.println("\nSMS sent OK");
}
}
}
}
uint32_t parsedecimal(char *str)
{ uint32_t d = 0; while (str[0] != 0)
{ if ((str[0] > '9') || (str[0] < '0')) return d; d *= 10; d += str[0] - '0'; str++; } return d;
}
void readline(void)
{ char c;
buffidx = 0; // start at begninning while (1)
{ c=Serial.read(); if (c == -1) continue; Serial.print(c); if (c == '\n') continue;
if ((buffidx == BUFFSIZ-1) || (c == '\r'))
{ buffer[buffidx] = 0; return; }
buffer[buffidx++]= c;
}
}
26
BIBLIOGRAPHY
i. Intro to Embedded systems, By Shibu, 2009. ii.
GRIET Arduino manual
iii. Data sheet for GPS module from Rhydolabz
iv. Data sheet for GSM module from Simplelabz
27