Sending an Email to Arduino

We have seen how to send the arduino serial content as email here, in this blog we will see how to send an email to arduino.Instead of simply sending  “hello world”  text, we will try to control the status of digital IO of the arduino.I will be using Node-RED to receive the email and send it to the Arduino.

Installing Required Components:

First you need to install Node-Red on your host (can be a windows system/Linux based system), then install johnny-five in the node-red directory (in case of windows it would be in your home directory .node-red)

Installing johnny five for node-red
Installing johnny five for node-red

 

npm install node-red-contrib-gpio
On arduino side, you just need to upload standardfirmata example

  • Open the Arduino IDE, select: File > Examples > Firmata > StandardFirmata

Node RED Flow:

The node-red flow looks some thing like this

node-Red_email_to_arduino

If you want to use Gmail, you need to get a password, follow this guide to get one .When Node-RED pulls email from Gmail, body contains additional information apart from what you sent, you may need to do additional processing depending on the content to extract the body.  Then Setup a input email node. 10 seconds refresh interval is too fast, 50 seconds should be a good value.

Node-red_input_email_node

you need to configure the johnny5 node as well, first create a new board

Johnny5-adding_new_Board

then need to register callback functions

EmailToArduinoJ5


node.log("Board is ready")

node.on("input",function(msg){
node.log("Input message payload"+msg.payload);
node.log("Input message topic "+msg.topic);
//filter emails based on subject
if(msg.topic=='toarduino'){
try{
var obj=JSON.parse(msg.payload);
var pin = new five.Pin(obj.digital[0]);
pin.write(obj.digital[1]);
console.log("Updated pin "+
obj.digital[0] +" to "+obj.digital[1]);
}catch (e) {
node.log("not a JSON body");
}}
});

 

The subject of the email should be toarduino and the body is a JSON string with pin number and status (1 for HIGH, 0 for LOW).

Sample email (makes the pin 13 LOW)

EmailToArduinoContent

 

 

Add a Comment

Your email address will not be published. Required fields are marked *