Electric Imp is a technology company that provides connectivity for the Internet of Things. They offer perhaps the simplest way to enable any physical object to be connected to the Internet thanks to their “Imp” module, a powerful piece of hardware containing WiFi and a processor.

The imp002 is a solder-down module form-factor. It works in conjunction with the imp service to allow easy connection of any device to the internet. There are two versions of imp002; The imp002-s uses the built-in antenna and the imp002-c uses an external antenna.

In this guide you’ll learn how to read an analog input from your Electric Imp and send its value to Ubidots.

More about the imp002 Breakaout

Requirements

Setup

1.- The best way to become familiar with the Imp is to follow their Blinkup guide, which helps you link your device to your Electric Imp account: Blinkup Tutorial the most important thing to know is that the Electric Imp IDE is divided in three main windows: agent code, device code, and the log.

  • Agent code window: This code is run in the Imp cloud, not in your device. It allows you to do heavy processing, HTTP requests, store small amounts of data, etc.
  • Device code window: As the name suggests, this code WILL be run in your device. Here’s where you typically manage input/ouput pins that connect the Imp to the real world.
  • Log window: Very useful to understand what’s going on, both in the Agent and in the Device code.

2.- Hardware Setup:

  • Connect one end of the photocell to “PIN9” of your Imp002 breakout, and the other end to “3V3”.
  • Connect one end of the 1k resistor to “PIN9” of your Imp002 breakout, and the other end to “GND”.

Send one value to Ubidots

After going through the Blinkup tutorial and setting up your Ubidots account, you can now program the Imp to send data to Ubidots by following these steps:

1.- In the Electric Imp IDE, you should see an empty workspace with one “Unassigned Device” in the left side. This means your Imp has been detected but is not yet assigned to any project:

2.- Click on “Create New Model” and assign your device to this model:

3.- Copy and paste these Agent and Device blocks of code:

NOTE:  Please note that you should replace your TOKEN with the one from your Ubidots account.

Agent Code

#require "Ubidots.agent.lib.nut:1.0.0"

Ubidots <- Ubidots.Client("9DriKmYujOJZ2x637376xbFtaSLvq0");

local VAR_LABEL  =  "humidity";

//Ubidots.setDeviceLabel("Electric-imp");

device.on("saveValue", function(value) {
    Ubidots.sendToVariable(VAR_LABEL, value);
    server.log("Sending data to Ubidots");
    server.log(value);
});

Device Code

sensor <- hardware.pin9;
sensor.configure(ANALOG_IN);

function mainLoop() {
    imp.wakeup(1.0, mainLoop);
    local value = hardware.pin9.read();
    agent.send("saveValue", value);
}

mainLoop();

Here’s how it would look like after putting your code:

Did this answer your question?