Battery-less switches: The next big thing in IoT ?

Internet of Things, or IoT as it is popularly known, needs no special introduction as it has been making rounds for quite a few years. As I am writing this, I know there are probably million other researchers in thousands of laboratories around the globe, sweating it out to come up with something new in this field. IoT relies on good quality sensor data at the right time in the right format, which is why energy harvesting wireless sensors are of special interest.

Imagine, being able to control your air-conditioner or television through a remote which doesn’t need a battery; yeah, you read that right. This is one of the many applications that energy harvesting switches can offer.

IoT

EnOcean, a Siemens spin-off, is a leading batteryless switch manufacturer with open APIs available for researchers to  play around and hook it up with other IoT devices. It uses a piezoelectric generator,  and the mere mechanical pressure generated by pushing the switch generates just enough electricity to transmit a unique switch code. Range of the switch comes in at around 120 meters which should give end-users plenty of flexibility. Two way communication is possible with EnOcean and the datarate comes around 125 kbps (For more info and comparison of EnOcean with other IoT technologies, refer to my paper here)

enocean

Refer to enocean website here for details on motion energy harvesting.

Today, energy harvesting wireless technology is very well established for providing M2M (Machine to Machine) solutions in the building automation sector, bridging the control of light, HVAC and other fields of building technology to smart home, smart metering and energy management systems. This is the starting point to actuate further applications that lead to the Internet of Things in the long term.

For hobbyists, hooking up a EnOcean switch to your home automation network is not a Herculean task. There are open source automation applications like OpenHab available which can do the task seamlessly.

References:
1. https://www.enocean.com/en/newsitem/energy-harvesting-wireless-and-iot/
2. https://www.enocean-alliance.org/en/enocean-technology-and-the-internet-of-things/
3. http://www.electronicsweekly.com/uncategorised/sensors-powered-by-energy-harvesting-key-to-iot-success-2015-08/
4. https://en.wikipedia.org/wiki/EnOcean

MG811 CO2 Sensor with Arduino

The MG-811 sensor is highly sensitive to CO2 and moderately sensitive to alcohol and CO. It could be used in air quality control, ferment process, in-door air monitoring application. The output voltage of the module falls as the concentration of the CO2 increases.

It is available as a breakout board like this from dfrobot or you may opt for the sensor only option, in which case you might need an external amplifying and conditioning circuit.

MG811

It has an onboard heater which needs a separate 6V supply , but if you are getting the breakout board this can also be eliminated as the circuit itself takes care of heater supply voltage.

Connecting to arduino and getting the data is a fairly simple process. What I suggest would be to write a simple program like the one below to get the output values in terms of mV first against some known PPM values. You might want to get a high precision NDIR monitor or PPM monitor for this.

int sensorValue = analogRead(A5);
float voltage= (sensorValue * (5.0 / 1023.0))*1000;

Note down all the output voltage values against the known PPM values (ranging from around 300 ppm to 1000 ppm maybe) and plot a graph in excel. Add a trend-line and use curve fitting tool to get a logarithmic formula, something like the one shown below. You cannot always depend on the formula you get from web because the amplification factor of your particular breakout board might be different and it is always better to work reverse and get the formula by using a standard CO2 monitor.

1

 

Since the output voltage is directly proportional to this logarithmic function, you may use this formula in your code to convert the values to PPM.

float refy = (voltage-264.76)/-17.644;
float ppm = pow(2.71828,refy) * 10000;

Note: This piece of information is supposed to be used for demonstration only. More sophisticated calibrations are required for industrial applications.

Reading data from multiple TelosB motes and pushing to MySQL Database

So, before starting the tutorial, I assume that you have installed TinyOS on your machine (whether it be Linux or Windows or MacOS). If not, follow this link. They have a really good step by step tutorial on how to do this.

1326546992_mote3

So, what I have is a set of TelosB motes (8 to be exact). 7 of them  placed in different parts of our laboratory, monitoring the climate data and the 8th one being used as a base station (a gateway, rather) connected to the central server machine. This Wireless Sensor Network, made of TelosB motes will be sending the climate (light, temperature, humidity) data to the base station in real-time and the base station in-turn pushes it to the MySQL database. There is provison to attach additional sensors to the TelosB motes. In my case, I have added  an additional microphone breakout board (ADMP401) to the TelosB motes which will send amplitude of sound (in dB) in addition to the climate data.

My database looks like this. The devices are identified by their device ids and corresponding data (whether temperature, light, humidity or whatever) being identified by a task number.

DB

The data can be represented in a meaningful way, by means of a real time dynamic chart using Java, JDBC and JSP/HTML5. This is beyond the scope of this tutorial and therefore I am not going into the details.

 So, how did i do this? Here it goes.

Steps

Note: All the programming was done in Linux platform, and using the Eclipse IDE. (Kepler Version)

1. Start by programming one of your motes with the BaseStation app which is already coming with the TinyOS package. Open the terminal/Cygwin and navigate to BaseStation folder. Type motelist to ensure that the mote is attached to the machine. If it displays “No Devices Found”, unplug and plug the mote again.

cd BaseStation
cd src
make telosb
make telosb install,1

This will compile and install the application onto the mote. Note that the id assigned to the device can be anything (1 in my case). It is just used to identify a particular device.

2. Now that the gateway is ready to receive messages, we should program the other motes with nesC code that will transmit the data to the base station mote. The oscilloscope application present inside the package can be edited for this purpose.

Edit OscilloscopeC.nc file which can read and transmit 5 different data sets. Initialise reading variables for all the 5 sensors.

oscilloscope_t local;
oscilloscope_t localL;
oscilloscope_t localH;
oscilloscope_t localP;
oscilloscope_t localM;

uint8_t reading;
uint8_t readingL;
uint8_t readingH;
uint8_t readingP;
uint8_t readingM;

interface AMSend as AM1;interface AMSend as AM2;
interface AMSend as AM3;interface AMSend as AM4;
interface AMSend as AM5;

Similarly add 5 Receive, Timer and Read interfaces.

Example functions are given below. (Complete code is not given. Spend some time on the already available Oscilloscope app and the functions listed here, and you will get the hang of it 🙂 )
Replicate the fired(), readDone(), sendDone() and receive() functions for all the 5 sensors.

event void T1.fired() {

local.id=81;
if ((reading == NREADINGS) )
{
if (!sendBusy && sizeof local <= call AM1.maxPayloadLength())
{
memcpy(call AM1.getPayload(&sendBuf, sizeof(local)), &local, sizeof local);
if (call AM1.send(AM_BROADCAST_ADDR, &sendBuf, sizeof local) == SUCCESS)
sendBusy = TRUE;
}
if (!sendBusy)
report_problem();

reading = 0;
/* Part 2 of cheap “time sync”: increment our count if we didn’t
jump ahead. */
if (!suppressCountChange)
local.count++;
suppressCountChange = FALSE;
}
if (call Read.read() != SUCCESS)
report_problem();
}

event void Read.readDone(error_t result, uint16_t data) {

if (result != SUCCESS)
{
data = 0xffff;
report_problem();
}
if (reading < NREADINGS)
local.readings[reading++] = data;

call T2.startOneShot(localL.interval);
}

event message_t* R1.receive(message_t* msg, void* payload, uint8_t len) {
oscilloscope_t *omsg = payload;
report_received();

if (omsg->version > local.version)
{
local.version = omsg->version;
local.interval = omsg->interval;

startTimer();
}

if (omsg->count > local.count)
{
local.count = omsg->count;
suppressCountChange = TRUE;
}

return msg;
}

3. Edit the already available OscilloscopeAppC file to map the different sensors

OscilloscopeC.AM1 -> AMSenderC;
.
.
OscilloscopeC.AM5 -> AMSenderC;

OscilloscopeC.R1 -> AMReceiverC;
.
.
OscilloscopeC.R5 -> AMReceiverC;

OscilloscopeC.T1 -> TimerMilliC;
.
.
OscilloscopeC.T5 ->TimerMilliC;
OscilloscopeC.ReadL -> PhotoSensor;
.
.
OscilloscopeC.ReadM -> Microphone;

4. Next, you need to add the database configuration details in Oscilloscope.java file

static String userid=”…”, password=”…”;
static String url = “jdbc:mysql://…….”;
static Connection con = null;
static Statement stmt = null;
con = DriverManager.getConnection(url, userid, password);
Inside the public synchronized void messageReceived(int dest_addr,
Message msg) function,  write the syntax for pushing the data to the MySQL database. For example, in my case it looked something like this:

statement.executeUpdate(“insert into solar_data ” + “values  (‘”+((omsg.get_id())%10)+”‘,'”+firstDigit(omsg.get_id())+”‘,'”+reading+”‘,'”+currentTime+”‘)”);

Repeat this for all parameters (Light, Temp, Humidity etc) by filtering them using if else blocks.

The delay interval can also be included.

And that’s it. Connect your base station TelosB to usb port. Ensure that it is detected by typing “motelist” in the terminal. Go to the java folder, make and run the app. Your motes should automatically be detected and shown in the Oscilloscope application. Basic graphs will be generated here and the data will be pushed to the MySQL database too.

Voila! You may choose to make responsive graphs using the generated data in HTML5, AngularJS etc.

Have fun exploring. Until next time.

 

Remote /Cloud Air Conditioner Control using Arduino, Bluetooth and J2EE

So, we have this very old air conditioner in our lab with a wired thermostat, which basically works alright but doesn’t have a remote control. The air conditioner is so old that the spare parts of this system are not even available in the market right now. As part of making everything “futuristic”, we decided to do little tweaking to enable wireless cum cloud control for this thingy.

The initial step was to check how the system works. The thermostat is DC powered and have its own proprietary protocol for sending commands and signals to the machine. Examining the terminals of the ON/OFF switch with a multimeter revealed that shorting the terminals for a few seconds would send the ON/OFF signal to the system. And I guess, this is how most of the thermostats, irrespective of the brand, do the job.

Now that we know how to turn ON/OFF the system, time to gather the hardware. Do reverse engineering, what needs to be at the end of the system is a Relay, which can do the “shorting”. And what can power the relay? A 5V signal. And where should it come from? From an output pin of Arduino. And what should trigger the signal? A command from PC/Mobile/Tablet. And how should the command be transmitted. Via Bluetooth/Zigbee/Wi-Fi. Here we use Bluetooth, because the hardware is comparatively cheap, and it can be easily integrated with Arduino. So here it goes, the complete hardware and software list for making this system.

1. Arduino (Can be any. Here I use Uno)
2. Bluetooth Adapter for Arduino HC-05 or HC-06
3. 5V Relay
4. Wires and Jumpers
5. Breadboard/ Soldering Board
6. Arduino Programming Software
7. Eclipse IDE where we run the Dynamic Java Application for web interface.
8. Serial Terminal for Windows, For Example TeraTerm
9. Bluetooth Serial Terminal Software for Android (Optional)
10. And obviously the thermostat connected to AC and a little bit of patience 😉

Start by wiring the HC-06 to the Arduino. Connect the TX pin of HC-06 to the RX pin of Arduino. Connect the RX pin of HC-06 to the TX pin of Arduino through a voltage divider. Connect Vcc(5V) and GND pins of HC-06 to respective terminals (Refer figure).

Take the output from any of the Arduino digital pins. In my case, I used pin number 10 (Of Arduino Uno). This output is connected to one of the the energizing coil terminals of the relay. And the other pin is connected to the GND. The outputs of the relay are connected across the ON/OFF terminals of thermostat.

IMAG0577_1

Time to program the Arduino. Set the pin 10 as output and make it LOW and HIGH with a delay of 1 second. Why because the shorting has to persist for a second for the thermostat to turn ON. Do the same thing for turn OFF process as well. During programming, make sure you disconnect the HC-06 from Arduino.

char VAL;
int AC = 10;
void setup() {
Serial.begin(9600);
pinMode(AC, OUTPUT);
}
void loop() {
Serial.println(“AC CONTROL \n”);
Serial.println(“Press 1 to turn ON or 0 to turn OFF”);
while (!Serial.available());
VAL = Serial.read();
if(VAL == ‘0’ ) {
digitalWrite(AC, LOW);
}
if( VAL == ‘1’ ) {
digitalWrite(AC, HIGH);
delay(1000);
}
delay(50);
}Now that the entire hardware setup is ready, we should check if this really works. Pair your laptop or PC with the HC-06 (Obviously, your machine should have Bluetooth. Use a Bluetooth adapter, if it is not available inbuilt). The password should most likely be “1234”. Open a serial terminal, for eg TeraTerm. Connect to the respective COM port. Type “1” to see if the relay is working. You can also use Bluetooth Serial Terminal for Android to check.

To enable local control using a web application, we should make a dynamic Java application and run it on a local server. Import RxSerial and RxParallel libraries for Java. Open the respective COM port, set the Baud Rate to send the commands. For the front-end, use JSP-JSF or HTML-5 to create a simple web page. Note that for cloud control, the program should be written in such a way that the web app should send a signal to the local machine which is connected to the HC-06 via Bluetooth. This signal should trigger opening the COM port on our local machine.

Export this application as a WAR file and upload to cloud server. The cloud server should support JSP-JSF /HTML and should also have an application server like Apache Tomcat. Do note that the local web application and the server should be running the same version of the Web Server; Tomcat or JBOSS or whatever. Otherwise, there might be problems launching the application from Web.

IMAG0579_1

You could also make an Android application to do the control from mobile or tablet. Bluetooth Terminal Apps are available though, as I already mentioned.

That’s it. Restart your application server after deploying the web application. And voila!! You can control your AC from web. Further modifications like temperature control, auto scheduling ON/OFF can be done easily. But yeah, once you are done with the basic stuff, you can always build on top of it. 🙂

Ciao!

Rahul Ashok

Dissecting the LBW theory

The other day, I was talking to an avid cricket enthusiast about the ongoing T20 world cup. We ended up discussing about a controversial LBW decision. After the heated discussion, I realized the fact that I know “nothing” about MCC’s Law 36( The LBW Law) and updating my knowledge on  the same would be good. 😀

Sachin was victim of some really bad decisions, when India toured Srilanka in 2009. See the video.

If you take a survey among the billions of people in our cricket-frenzy nation, I’m certain that more than 50% of the people won’t be having an idea about how LBW really works. Most people would say that the batsman can be given out if the ball would have gone on to hit the stumps, had it not been obstructed by the pads. Is that the real definition? Not really; There are many other factors to be taken into consideration before giving the decision.

So What is LBW? Here it goes.

Ball pitches outside the leg-stump:

If the ball pitches outside the leg-stump, the batsman can’t be given out, even if the ball goes on to hit the stumps.

See the picture below

Pitches outside leg

Impact outside the off-stump:

If the ball strikes batsman’s pad outside the line of off-stump, he can’t be given out, even if the ball goes on to hit the stumps.

But, this law holds invalid, if the batsman deliberately ducks/offers no shot to the delivery. In that case, he is OUT. See the pics below.

Impact outside offOffers no shot

 

 Plumb in front:

You might have heard the commentators saying this more often than not. Obviously  it means the ball has struck in line and on to the pads in front of the wicket. The batsman is OUT in this case. See the picture below.

Struck in line

Miscellaneous factors:

      • The batsman cannot be given out if the bowler bowls a no-ball.
      • The batsman cannot be given out if the ball hits the bat/glove, before hitting the pads.
      • Most umpires give the benefit of doubt to the batsmen, if they find the ball hitting the pads somewhere near/above the knee roll. Some clever batsmen lean forward, so as to make the distance between the impact and the stumps more. In those cases also, they might get away. Again, it’s up to the discretion of the umpire.
LBW- Leg Before Wicket does not necessarily mean that the batsmen can obstruct the ball with any other part of their body. See this video. Sachin misjudged the bounce of the delivery and ducked. The ball went onto hit his shoulder. He was adjudged OUT.

Earlier we saw how Sachin became victim of a series of really bad decisions. But, we can’t really blame the umpires. Can we? Because, they are under tremendous pressure, each time the fielding team appeals.

See this video. Billy Bowden takes a hell lot of time to take the decision. No wonder they are wearing those big hats. Those are the so called “Thinking Caps“, i guess… 🙂

http://youtu.be/aWaBcTCAh3M

Now that you know the rules, try to guess the umpire’s decision next time you see the bowler appealing. Cheers!! 🙂

 

–Rahul Ashok
admin@rahulashok.com 

Reference and Image courtesy: BBC Sport-Cricket

 

 

 

I write crap when I am bored