Go Down

Topic: Idea: Home guardian sends e-mail when door stays open (Read 4366 times) previous topic - next topic

K5CZ


...


Thank for helping me, I do this and it works as requested!

Code: [Select]

#include <avr/pgmspace.h>

//do not exceed 80 characters per line!
static char buffer[80+1]; // must be big enough for longest string and the terminating null
char TextMailSubject[] PROGMEM = "Garage alarm: door not closed at Street/City!";
char TextMailBodyLn1[] PROGMEM = "This is an automated message - please do not reply directly to this email!\r\n";
char TextMailBodyLn2[] PROGMEM = "Hi there!";
char TextMailBodyLn3[] PROGMEM = "Garage door at Street/City stays accidentally left open.";
char TextMailBodyLn4[] PROGMEM = "Please take appropriate steps to remedy the situation.\r\n";
char TextMailBodyLn5[] PROGMEM = "My sincere thanks for your time and consideration, your Arduino\r\n";
char TextMailBodyLn6[] PROGMEM = "Date and time of incident:";
char* TextItemPointers[] PROGMEM = {
  TextMailSubject, TextMailBodyLn1, TextMailBodyLn2, TextMailBodyLn3, TextMailBodyLn4, TextMailBodyLn5, TextMailBodyLn6};
String Message = "";

void setup(){
  Serial.begin(9600);
};

int GetFreeRAM() {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

/* function to return string by index */

String GetTextFromFlashMemory(int ItemIndex)
{
  int i = 0;
  char c;
  while (c != '\0')
  {
    c = pgm_read_byte(pgm_read_word(&TextItemPointers[ItemIndex]) + i);
    buffer[i] = c;
    i++;
  }
  buffer[i] = '\0';
  return String(buffer);
}

void loop(){
  Serial.print(F("Free SRAM: "));
  Serial.print(GetFreeRAM());
  Serial.println(F(" bytes"));
  int thisItem;
  for (thisItem = 0; thisItem < 7; thisItem++) {
    Message = "Item #"+String(thisItem);
    Serial.println(Message);
    Message = GetTextFromFlashMemory(thisItem);
    Serial.println(Message);
  };
  Serial.print(F("Free SRAM: "));
  Serial.print(GetFreeRAM());
  Serial.println(F(" bytes"));
  delay(5000);
};
Arduino Uno R3, Arduino Mega 2560 R3, Ethermega (R3), and some Ethernet Shields (R3), Chronodots, TMP36 sensors, DS18B20 sensors, LCDs/TFTs, RS232C to learn and play...

K5CZ

Next attempt: attached program sends e-mail with timestamp (IP leased form DHCP, current time obtained from NTP)
memory (SRAM) consumption: about 1,5 KB
sketch size: about 20 KB
Arduino Uno R3, Arduino Mega 2560 R3, Ethermega (R3), and some Ethernet Shields (R3), Chronodots, TMP36 sensors, DS18B20 sensors, LCDs/TFTs, RS232C to learn and play...

K5CZ

#17
Jul 31, 2013, 11:41 pm Last Edit: Jul 31, 2013, 11:43 pm by K5CZ Reason: 1
The figures below shows the scheme of electrical circuit as I currently use when debugging my program


click to enlarge


click to enlarge

It is working well, but only one I/O pin left unused. I have not tried SD card yet (so A0 and A1 are free too).
Arduino Uno R3, Arduino Mega 2560 R3, Ethermega (R3), and some Ethernet Shields (R3), Chronodots, TMP36 sensors, DS18B20 sensors, LCDs/TFTs, RS232C to learn and play...

marque



It is working well, but only one I/O pin left unused. I have not tried SD card yet (so A0 and A1 are free too).


While connected to internet the hardware RTC is superfluous, you can drop the RTC and use software RTC with NTP sync every hour.

K5CZ

My first project is a bit closer to implementation, so this is way how I connected the RGB LED to Crib for Arduino. The LED can be disconnected or easy replaced.

Arduino Uno R3, Arduino Mega 2560 R3, Ethermega (R3), and some Ethernet Shields (R3), Chronodots, TMP36 sensors, DS18B20 sensors, LCDs/TFTs, RS232C to learn and play...

K5CZ

Arduino Uno R3, Arduino Mega 2560 R3, Ethermega (R3), and some Ethernet Shields (R3), Chronodots, TMP36 sensors, DS18B20 sensors, LCDs/TFTs, RS232C to learn and play...

Go Up