Go Down

Topic: Send an email or an SNMP-Trap if a digital input change from 0 to 1 (Read 1 time) previous topic - next topic


Is it possible to send an email or an SNMP-Trap if a digtial input change from 0 to 1.

I haven't bought a board yet. I'am interesting for Andruino Yun or Uno with a Ethernet-shield. Which board do you prefer for my application?

thanks for your support.


Sending event based email should be fairly easy like the bottom sample code. Below is some reading material.


Code: [Select]

//zoomkat 4/08/12
//email test code using DNS
//developed from code posted by various persons

#include <SPI.h>
#include <Ethernet.h>

#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
char serverName[] = "smtp.yourISP.net"; // your ISP's SMTP server
EthernetClient client;


void setup(){
  Serial.println("DNS and DHCP-based email test 4/08/12"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
  // print your local IP address:
  Serial.print("Arduino IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);

void loop()
  byte inChar;
  inChar = Serial.read();
  if(inChar == 'e')
    if(sendEmail()) Serial.println("Email sent"); //start sendEmail()
    else Serial.println("Email failed");

//////////////////////////////// email function
byte sendEmail()  //sendEmail() function that returns 1 or 0
  //start and check for email server connection
  if (client.connect(serverName, 25)) {
  else {
    Serial.println("connection failed");
    return 0; //send 0 (failed) back to sendEmail() function
  //wait for server "queing" response
  while(!client.available()) delay(1);

  client.println("HELO itismeletschat"); /*hello (statement after helo is needed but irrelevant)*/

  //wait for server "hello" response
  while(!client.available()) delay(1);

  client.println("MAIL From: me@athome.net"); // identify sender, this should be the same as the smtp server you are using*/

  //wait for server "sender ok" response
  while(!client.available()) delay(1);

  client.println("RCPT To: you@athome.net"); /* identify recipient */

  //wait for server "receipent ok" response
  while(!client.available()) delay(1);


  //wait for server to say "enter your message" response
  while(!client.available()) delay(1);

  //send email message to server
  client.println("To: you@athome.net"); /* identify recipient */
  client.println("Subject: You Have Arduino Mail!!"); /* insert subject */
  client.println("Please let me know it worked!!!"); /* insert body */
  client.println("."); /* end email */

  //wait for server "message accepted" response
  while(!client.available()) delay(1);

  client.println("QUIT"); /* terminate connection */
  //wait for server "goodby" response
  while(!client.available()) delay(1);

  //stop client connection
  return 1; //send 1 (success) back to sendEmail() function

Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.


Here is an example email sketch that evaluates and displays the responses of the email server so you know if it has actually been sent, and if not why it wasn't. It is an improved version of zoomkat's code.


Hi all,

it is possible to do the reverse way?? Receive an SNMP Trap, show it in Serial Monitor (just to check it) and depending on the information Trap fields change the digital inputs..?

Thanks in advance!

Go Up