Introduction: [Arduino Etheret Project] Hey You!! Get Away From My Home!!!

About: I am SoC engineer of Korea. I developed several comunication SoCs. Now I'm very interesting in IoT with ethernet. and Open Hardware platform.

[Prologue]

Oneday.

It was a extremely exhausted day because of hard working.

Anyway I back to home after work lately.

As soon as I entered my home I could feel that there is a something wrong in my home.

There was no evidence. It was a just my feeling.

.....

After I felt that first time, sometimes I could feel "exist of trespasser"

Finally I bet that there is a "trespasser" in my home.

I had to someting. I considered for a while.

I ran to small room and found out my tool box.

There are electrical parts which I used before include Arduino and Ethernet shield.

I started to make something alram to trespasser and me.

=============================================================

Of cource above story is fiction.

Let's make a someting can be alram to trespasser like as main charactor of fiction.

What we will make is :

  1. Check every 1sec what body there is or not with ultrasonic sensor
  2. If there is a body, turn on the TV to make trespasser frighten with IRLED
  3. Send twitter message to me for alram & send a google email using Temboo with Ethernet Shield

Step 1: What We Need for This Project

The main requirement parts I had for this project were the following :

  1. Arduino Uno

  2. Arduino Ethernet Shield

  3. Ultrasonic sensor for measure distance

  4. IRLED

  5. Prototyping PCB for making "ultrasonic & IRLED" shield

  6. And several pin headers and registers.

Step 2: Circuit of This Project (Fritzing)

Circuit of this project is very simple.

  1. Arduino ethernet shield is stack on Arduino uno.
  2. Ultrasonic sensor connect to pin #7 of Arduino uno.
  3. IRLED connect to pin #3 of Arduino uno with 100ohm register.

Step 3: Complete Making Hardware of This Project

A. Let's make a "ultrasonic & IRLED shield"

  1. Preparing electric parts for making shield (ultrasonic sensor, IRLED, pin header, 100 ohm, color cable)
  2. Soldering

B. Stack "ultrasonic & IRLED shield" on Arduino ethernet shield

C. Now... Complete hardware is prepared.

Step 4: Preparing Software of This Project (Flowchart)

  1. Setup : Initialize (Ethernet setting, Twitter account setting, TEMBOO & GOOGLE account setting, IRLED & Ultrasonic sensor pin setting)
  2. Check distance by ultrasonic sensor.
  3. Compare measured distance with initial distance.
  4. If measured distance is not initial distance we can assume that there is a trespasser.
  5. Turn on TV for alram and frighten tresspasser by IRLED
  6. Send twitter message to my account
  7. Send google email to me and/or my family.

Now... we prepared how can we write Arduino sketch by this flowchart now.

But we have 3 items to check first.

  1. How to control IRLED to turn on the TV
  2. How to send twitter message from Arduino
  3. How to send google email from Arduino through TEMBOO

Step 5: How to Control IRLED to Turn on the TV

Before we use a IRLED we have to install Infrared remote library to remote control TV.

What I used IR remote library is below :

http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html

And below is examples/IRsendDemo sketch provides a simple example of how to send codes to control TV and so on.

/*
* IRremote: IRsendDemo - demonstrates sending IR codes with IRsend
* An IR LED must be connected to Arduino PWM pin 3.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
#include <IRremote.h>
IRsend irsend;
void setup()
{
Serial.begin(9600);
}
void loop() {
if (Serial.read() != -1) {
for (int i = 0; i < 3; i++) {
irsend.sendSony(0xa90, 12); // Sony TV power code
delay(40);
}
}
}
Do you know how to install new library can be use in Sketch?
Just unzip file and copy to your arduino installed directory (ex : ../arduino-1.0.5-r2/libaries/)
Then you can use this library like as already installed other libraries.

Step 6: How to Send Twitter Message From Arduino

To send twitter message we have to get a token to from Twitter and install Tweet library for Arduino.

Follow below 3 step :

  1. Make a/more twitter account to receive a tweet message from Arduino.
  2. Get a token to post a message using OAuth
  3. Download attatched twitter library and install like as IRLED library to your Arduino installed directory
  4. Run below sample sketch to tweet.
#if defined(ARDUINO) && ARDUINO > 18   // Arduino 0019 or later
#include <SPI.h>
#endif
#include <Ethernet.h>
//#include <EhternetDns.h> Only needed in Arduino 0022 or earlier
#include <Twitter.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 177 };
Twitter twitter("<<< your token here >>>");
char msg[] = "Hello, World! I'm Arduino!";
void setup()
{
delay(1000);
Ethernet.begin(mac, ip);
Serial.begin(9600);

Serial.println("connecting ...");
if (twitter.post(msg)) {
int status = twitter.wait();
if (status == 200) {
Serial.println("OK.");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
} else {
Serial.println("connection failed.");
}
}
void loop()
{
}

Step 7: How to Send Google Email From Arduino Through TEMBOO

To send google email from arduino through TEMBOO we have to do something first.

[Need Google Account]

  1. Make google account. [Make Google account]
  2. Need a google App-specific password that generated after 2-Step Verfication. [Google App-specific password setting]

[How to use TEMBOO]

  1. Download attatched TEMBOO library and install like as IRLED/Twitter library to your Arduino installed directory
  2. Make TEMBOO accout first [TEMBOO accout]
  3. There are many APIs already prepared by TEMBOO. We will use "send google email" API in this project, so we have to go [Google > Gmail > SendEmail]
  4. [Important] And you have to select "IoT Mode [ON]" which is located in top/right with yellow charactor.
  5. And test send email with fillout pink box and click Run. (See Picture)
  6. We can see the Arduino sketch source code for send gmail from TEMBOO as below
  7. Now we can use TEMBOO for send gmail

[Sketch source code]

/* Setup shield-specific #include statements */
#include <SPI.h> #include <Dhcp.h> #include <Dns.h> #include <Ethernet.h> #include <EthernetClient.h> #include <Temboo.h> #include "TembooAccount.h" // Contains Temboo account information

byte ethernetMACAddress[] = ETHERNET_SHIELD_MAC; EthernetClient client; int numRuns = 1; // Execution count, so this doesn't run forever int maxRuns = 10; // Maximum number of times the Choreo should be executed

void setup() { Serial.begin(9600); // For debugging, wait until the serial console is connected. delay(4000); while(!Serial); Serial.print("DHCP:"); if (Ethernet.begin(ethernetMACAddress) == 0) { Serial.println("FAIL"); while(true); } Serial.println("OK"); delay(5000); Serial.println("Setup complete.\n"); } void loop() { if (numRuns <= maxRuns) { Serial.println("Running SendEmail - Run #" + String(numRuns++)); TembooChoreo SendEmailChoreo(client); // Invoke the Temboo client SendEmailChoreo.begin(); // Set Temboo account credentials SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT); SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); SendEmailChoreo.setAppKey(TEMBOO_APP_KEY); // Set Choreo inputs String MessageBodyValue = "Message what you want to send"; SendEmailChoreo.addInput("MessageBody", MessageBodyValue); String SubjectValue = "subject of email"; SendEmailChoreo.addInput("Subject", SubjectValue); String PasswordValue = "generated_password"; SendEmailChoreo.addInput("Password", PasswordValue); String UsernameValue = "youraccount"; SendEmailChoreo.addInput("Username", UsernameValue); String ToAddressValue = "destination_address@abcdef.com"; SendEmailChoreo.addInput("ToAddress", ToAddressValue); // Identify the Choreo to run SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail"); // Run the Choreo; when results are available, print them to serial SendEmailChoreo.run(); while(SendEmailChoreo.available()) { char c = SendEmailChoreo.read(); Serial.print(c); } SendEmailChoreo.close(); } Serial.println("\nWaiting...\n"); delay(30000); // wait 30 seconds between SendEmail calls }

["TembooAccount.h", Header file]

/*
IMPORTANT NOTE about TembooAccount.h TembooAccount.h contains your Temboo account information and must be included alongside your sketch. To do so, make a new tab in Arduino, call it TembooAccount.h, and copy this content into it. */ #define TEMBOO_ACCOUNT "your_temboo_account" // Your Temboo account name #define TEMBOO_APP_KEY_NAME "myFirstApp" // Your Temboo app key name #define TEMBOO_APP_KEY "1eb4e************************39a61" // Your Temboo app key #define ETHERNET_SHIELD_MAC {} /* The same TembooAccount.h file settings can be used for all Temboo SDK sketches. Keeping your account information in a separate file means you can share the main .ino file without worrying that you forgot to delete your credentials. */

Step 8: Complete Arduino Sketch Source Code for This Project

We have to mix and edit below source codes which is represented from step 5 to step 7.

  • IR remote library
  • Twitter library
  • TEMBOO library for send gmail

Now we can complete source code with flowchart and libraries.

Refer attatched file which is completed Arduino sketch source code.

Step 9: RUN Arduino to Know Existance of Trespasser

[Epilogue]

I made a Arduino system with ethernet shield, irled, ultrasonic sensor.

I checked time... It was 7 o'clock morning.

It is time to go to work. I hurried.

I set this system in front of TV because there is a roughter and I plugged ethernet cable to ethernet shield.

I leaved home.

I thought that "Arduino will make me if there is a trespasser from now" with smile as working.

=============================================================

Hi... all...

I'm Leo

Thank you for your reading entry level my article.

As soon as ... I will upload demo video more and show you how does it working.

I want to publish this project quicly before complete because I want to get "more any ideas and advices".

And

English is not my mother language. (I'm Korean)

So maybe there are many mistake in grammer, expression and word in this article.

I need your collect what I written english in this article.

Thank you.

First Time Author Challenge

Participated in the
First Time Author Challenge