Wednesday, 4 November 2015

Setup Wireless Sensor Node: Setup Sensor Node Part 2

It is hard to write a template of code that can be use for every sensor, since some sensor using digital input, analog input as well as You can check my source code here at codebender

This is an ongoing project and this list will keep growing but as for now I only done writing code for interfacing WSN with:
  1. DHT22 --- Temperature and Humidity Sensor
  2. BH1750FVI --- Light Intensity Sensor
Algorithm that I use are following the discussion at part 1. 


Tuesday, 3 November 2015

Setup Wireless Sensor Node: Setup Sensor Node Part 1

Basically every sensors that can interface with Arduino can be used as a wireless sensor node with the addition of serial Bluetooth connectivity (HC-05). To push sensor reading to the gateway we need to understand:
  1. Operation that is done by the gateway to collect data. 
  2. Type of data that those sensors produce.
  3. Numbers of sensors that is connected to the single Arduino's Board.
  4. Packet protocol that are used to transmitting sensor reading to the gateway.

Heartbeat method: Operation done by gateway to collect data

What can I share with you here is the best practice that I usually use known as Heartbeat method. You can read more at here and here, which are to my understanding are a method that enable base/leader/master/sink node to know the availability of the other node in its local network cluster by sending a "pulse" signal at a regular interval of time. If a heartbeat signal from targeted node isn't received for a time, the machine that should have sent the heartbeat is assumed to have failed. 


By using this method I modify the "pulse" signal to be a command signal. Commanding the targeted node to send sensor reading as well as monitoring the life of that node. The targeted node will reply back the sensor reading and if it doesn't reply back that node are consider as dead. This is like a master/slave method where, Gateway will become a master and sensor nodes as a slave. This method also allowing the whole system from sensor nodes to the cloud database to be in sync which each others. 



Don't worry, this heartbeat process are monitored by SensorGate apps what important is you know some of the basic algorithm.



String of Character: Type of Data that those Sensors Produce
Always use string of character to represent reading for each sensors, no matter if its float, int, char, double, or Boolean, change it to string of character. If you are using an Arduino, usually for each of the sensor you are using, it will come with the tutorial on how to interface with it and a source code to get that sensor reading. But many of those source code doesn't change the reading to string of character, which is your job to find a method to change your reading value to String of Character. I will show this at the next post. 


Number of Sensors: As long as their is a pin to Interface
As long as their is enough pin to interface with those sensors it can be used. You just need to build the sequence to listen to each of those sensor and change it's reading to a String of Character for that sensor. 


Packet Protocol
Packet protocol that I use for this system are: 

        var1,var2,...,varN:VALUES:'values1','values2',...'valuesN'

For example:

        Temp,Humidity,LightIntensity,Motion:VALUES:'34','20','10','1'

This string packet are made based on SQL format, the idea is to provide a flexible method to store and push data to the Fusion Table database. 

On the second part I will show you the template for Arduino Script for wireless sensor node. 

Monday, 2 November 2015

Setup Wireless Sensor Node: Setup Bluetooth Connectivity

You can follow this TechBitar Guy method or you can read more here.

Step 1: Component and Wiring


Parts:
Wiring:
  • HC-05 GND --- Arduino GND Pin
  • HC-05 VCC (5V) --- Arduino 5V
  • HC-05 TX --- Arduino Pin 10 (soft RX)
  • HC-05 RX --- Arduino Pin 11 (soft TX)
  • HC-05 Key (PIN 34) --- Arduino Pin 9

Step 2: Component and Wiring
This Arduino program (HC_05.ino) does two things. It takes the AT commands you enter from the Arduino IDE Serial Monitor and sends those commands to the HC-05. The program then reads the output of the HC_05 and displays it on the Arduino IDE Serial Monitor. You can also use a terminal emulator such as Tera Term instead of the Arduino Serial Monitor. 

The Arduino communicates with the HC-05 using the SoftwareSerial ports while the Arduino communicates with the user via Serial Monitor.


#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10,11); // (RX,TX)

void setup() {
     pinMode(9,OUTPUT);   //this pin will pull the HC-05 pin Key high and switch module to AT mode
     digitalWrite(9,HIGH);
     Serial.begin(9600);
     Serial.println("Enter AT commands:");
     BTSerial.begin(38400);   //HC-05 default baud rate for Bluetooth in AT command
}

void loop(){
     //Continuously reading from HC-05 and send to Arduino Serial Monitor
     if(BTSerial.available())
            Serial.write(BTSerial.read());

     //Continuously reading from Arduino Serial Monitor and send to HC-05
     if(Serial.available())
            BTSerial.write(Serial.read());
}


Step 3: Switch the HC-05 Into Command Mode
For the HC-05 module to switch to AT command mode, the HC-05 Key pin needs to pulled HIGH but in a certain order of events explained below. 

  1. Wire the HC-05 and Arduino Uno per instructions.
  2. BEFORE YOU CONNECT THE ARDUINO TO THE USB remove the VCC(power) wire from HC-05. All other wires are still connected.
  3. Now connect your Arduino Uno with the USB cable extended from your PC.
  4. Make sure the HC-05 module is NOT PAIRED with any other Bluetooth device. 
  5. Re-connect the Arduino Uno 5V wire to the HC-05's VCC (5V power) pin. 
  6. The HC-05 LED will blink on and off at about 2 second intervals. Now its ready to accept ATCommands to change configuration and settings.
  7. To test if everything is wired correctly, open the Serial Monitor from the Aduino IDE and type "AT" (remove the "" just AT) and click SEND. You should see an "OK"
  8. If you don't see an "OK" check your wiring.

Step 4: Example HC-05 AT Commands
You can send AT Commands to the HC-05 from the Arduino IDE Serial Monitor while the Arduino is running the attached Arduino program. 


You cab find a full set of AT commands from the attached HC-05 reference PDF file, or you can test some of the popular AT commands.


(remove double quotes from AT command)

  • To return HC-05 to mfg. default setting: 'AT+ORGL"
  • To get version of your HC-05 enter: "AT+VERSION?"
  • To change device name from the default HC-05 to let's say BLUENODE enter: "AT+NAME=BLUENODE"
  • To change default security code from 1234 to 2232 enter "AT+PSWD=2232"
  • To change HC-05 baud rate from default 38400 to 115200, 1 stop bit, 0 parity enter: "AT+UART=115200,1,0"

Setup Wireless Sensor Node

Wireless sensor node is a kind of sensor that can transmit its sensing data, alphanumeric or multimedia and transmit it to the base station via wireless connection. There can be many kind of wireless connectivity with their own protocol. Some use for Local Area Network like Wi-Fi, others for Personal Area Network like Bluetooth and ZigBee. 

This SensorGate apps are function by receiving sensor data from your sensor node with Bluetooth connectivity and transmit it to your fusion table you just selected. 

To do that you need to setup your own sensor node by:
1. Configure Bluetooth connectivity, 
2. Get sensor reading from sensor, and
3. Send its reading to the phone by following the packet protocol.