A wireless sensor network (WSN) refers to a group of sensors that monitor and record certain physical conditions. It typically consists of:
- One central receiver (for monitoring, storage, and controlling)
- Several wireless sensor nodes
The wireless sensor node is a battery or solar-powered circuit that senses physical quantities. This may include temperature, flow, pressure, soil moisture, gas, smoke detection, etc. It, then, transmits this value to a remote receiver, which includes:
1. A sensing element
2. A microcontroller unit or MCU (which may be optional in some cases)
3. A modulator and a transmitter (mostly RF)
4. A battery (which may be solar-powered)
Typically, several sensor nodes are spaced at regularly set distances to cover the geographical of interest. Each sensor sends the data it obtains to a receiver that’s in a central data-monitoring and storage system. The sensor nodes will transmit this data — also referred to as the sensor value —periodically.
The receiver receives the data from all of the nodes and it stores and displays it for monitoring and controlling purposes.
Here’s an example:
In the cold-storage sector, it’s necessary to maintain a set temperature in every corner of the storage area. To do so effectively, many small wireless temperature sensing nodes are installed in each corner. Each one will sense the surrounding temperature and transmit that sensor value to a central monitoring and controlling room at regular intervals. The controller will receive the readings and, then, will attempt to regulate the temperature so it remains the same in each corner.
For this project for sensor node, we’ve selected the gas sensor MQ2. It can sense different gasses (such as CO2, methane, LPG, propane, etc.) in the atmosphere and is used to detect a gas leak.
Such sensors are commonly used in:
- An LPG gas line. Placed at equal distances apart, these sensor nodes are designed to detect a gas leak, transmitting this data to a remote center for action.
- A chemical processing industry/plant. The sensor nodes are placed at different locations — for example, on gas chambers, tanks, boilers, and other relevant equipment —to detect leakage of hazardous gases. If gas is detected, they’ll immediately send an alarm signal to a central control room, which can then take the appropriate action to stop the leak.
The sensor node also consists of Arduino NANO as the MCU and a 433 MHz ASK RF transmitter module. Although there can be several sensor nodes, for this project we’ve only used two.
The receiver includes a 433 MHz ASK RF module and Arduino NANO MCU. Both sensor nodes transmit data of the sensed values for the gas. The receiver obtains the values from both sensors and sends it to a computer. The computer, then, displays these values and stores it for future use.
Now let’s build the system, starting with the block diagram below, followed by the circuit diagram and its working and operation. The software program is given last.
System block diagram
The complete system is divided into two distinct blocks:
1. The transmitter (also known as a sensor node
2. The receiver
There can be several sensor nodes placed in different spots, depending on the application, but there will typically only be one receiver that’s connected to the central data-storage system (the computer).
The sensor node consists of different sensors, a microcontroller, an RF transmitter, and a battery.
For this project, we’re using:
- An MQ2 gas sensor to detect gas and/or smoke in the surrounding atmosphere
- An Arduino NANO board as a microcontroller that will read the data from the gas sensor and transmit it using the RF transmitter
- An ASK-based RF transmitter module with a 433-MHz carrier frequency to modulate and transmit data to the receiver
- A 6-9V battery to provide a power supply for the sensor node
- One LED that will blink to indicate that the sensor node is active and properly transmitting data
The receiver consists of an RF receiver module and a microcontroller.
- An ASK-based RF receiver module with a 433-MHz carrier frequency to de-modulate and receive the data transmitted by the sensor node RF Tx module
- An Arduino NANO board as a microcontroller that gets the data from the RF receiver module and sends it to a computer that will store it for future use
- One LED that will blink to indicate the receiver is active and receiving data
Circuit diagram of the sensor node
There are only three major components in the circuit.
- The MQ2 sensor only has four pins for interfacing: Vcc, GND, A0, and D0. The Vcc pin is connected with Arduino’s 5V output and the GND is connected with common ground. The A0 is an analog output and it’s connected with the Arduino board’s A0 analog input. The D0 pin is a digital output (that is either 0 or 1) and is not used in this case.
- The 433-MHz RF Tx module has four interfacing pins: Vcc, GND, data_in, and an antenna. The Vcc pin is connected with the Arduino board’s 5V output and the GND is connected with the common ground. The data_in pin is connected with Arduino’s digital pin D11. The antenna is formed by winding 1mm @ 35cm of long, copper wire (single-core). It’s then connected with the antenna pin.
- An LED is connected to the digital pin D12 through a current-limiting resistor.
- A 9V battery is used to supply power to the Arduino board via Arduino’s Vin. This means the board will get working voltage and it will generate a 5V supply from the onboard 7805 voltage regulator chip, which is given to DHT11 and the RF Tx module.
Circuit diagram of the remote data receiver
There are also only three major components in the receiver circuit.
- The 433-MHz RF Rx module has four interfacing pins: Vcc, GND, data_our, and an antenna. The Vcc pin is connected with the Arduino board’s 5V output and the GND is connected with the common ground. The data_out pin is connected with Arduino’s digital pin D12. An antenna (that’s the same as the transmitter side) is connected with the antenna pin.
- An LED is connected to the digital pin D10 through the current-limiting resistor.
- A 5V DC buzzer is connected at digital pin D7 (as shown).
- The Arduino board and the RF Rx module receive a power supply from a laptop/desktop PC/central-storage system computer through a USB cable. The Arduino board also logs data and communicates with the computer using the same USB cable
Working and operation
The sensor node
It’s easy to think that the sensor simply periodically senses gas and transmits it. But it’s not that simple. As shown in the block diagram, there may be 2, 3, 5, 10, or N number of sensor nodes, which are all doing the same thing. This means that more than one node is likely to transmit data at the same time.
So, how does the receiver know the data received is from one particular node (say node 1 versus node 2 or 6, etc.?
To overcome these concerns, it’s necessary to plan. For example, all the sensor nodes can be synchronized in time so that two nodes never transmit data simultaneously. And if that happens, the receiver will only accept one sensor’s data at a time.
Additionally, the nodes must be assigned numbers (say from 1 to N). Then, they transmit their node number before transmitting data. This ensures the receiver knows what sensor node the data is coming from.
- The MQ2 gas sensor gives analog voltage output directly proportional to the level of gas in the surrounding atmosphere. The output voltage increases as the gas concentration increases. Arduino converts this analog voltage into a digital value (between 0 to 1023) and maps it between 0 – 99%. Finally, it converts this % value into ASCII characters.
- It forms a string (array of characters) of four characters:
node number + gas concentration
(2 characters) (2 characters)
- Next, it gives them to the RF Tx module through the D11 pin.
- The RF Tx module gets this string of 10 characters (called a packet), modulates it using the 433-MHz carrier, and transmits it using the antenna.
- Every time the packet is transmitted, the microcontroller blinks the LED to indicate that data is being transmitted.
- This cycle continuously repeats after a set time period (say, 3 or 10 seconds).
The remote data receiver
- The RF Rx module receives packets from every sensor node. It de-modulates them and sends them to the Arduino microcontroller.
- The microcontroller receives the packets and extracts the gas-level value (in %) and the node number.
- It serially sends this data to the computer through a USB:
Gas level: XXX %
- The microcontroller blinks the LED to indicate that data is being received.
- If the gas level in any node is more than the threshold level, then the buzzer will sound continuously to indicate a gas leak.
- This process repeats for each packet received from any node at any time. And since all of the nodes are synchronized in time, they will transmit data one after another.
- The receiver will obtain data from all of the nodes, one by one, and update the readings of each node after a set period of time.
The sensor node program
#define MQ2_pin A0
const int led_pin = 12;
const int transmit_pin = 11;
char node = “01”; // node number. change this node number for
char trnsmit_str;// different node
vw_setup(2000); // Bits per sec
gas_level=map(gas,0,1023,0,99); // map them in the range between 0 to 99%
Serial.println(“Node 1”); // serially print all values
Serial.print(“gas level: “); // for debugging
digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
itoa(gas_level,str1,10); // convert all 2 digit values into
strcpy(trnsmit_str,node); // one string
Serial.print(“transmitted string: “);
vw_send((uint8_t *)trnsmit_str, 4);
vw_wait_tx(); // Wait until the whole message is gone
The receiver program for two nodes
#define gas_threshold 80
#define siren 7
const int receive_pin = 12;
int led = 10,gas_level;
Serial.begin(9600); // setup serial communication
vw_setup(2000); // wireless data rate
vw_rx_start(); // Start the receiver PLL running
Serial.println(“Receiving sensor DATA from all nodes…..”);
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // when msg is received
if(buf==’1′) // check node number
Serial.println(“Node 1”); // print node number and
Serial.print(“gas level: “); // all sensor values
for (i = 2; i < 4; i++) Serial.print(buf[i]-48);
gas_level = (buf-48)*10 + (buf-48)*1;
Serial.print(“Gas Level: “);
for (i = 2; i < 4; i++) Serial.print(buf[i]-48);
gas_level = (buf-48)*10 + (buf-48)*1;