Exemplo de rede de sensores sem fio usando Arduino

Wireless sensor network example using Arduino

A Wireless Sensor Network (WSN) consists of the following:

  • A central receiver (for monitoring, storage and control)
  • Multiple wireless sensor nodes

The wireless sensor node is a battery- or solar-powered circuit that detects any physical quantity (such as temperature, pressure, flow, soil moisture, gas, smoke, etc.) and transmits its value to a remote receiver. This consists of

  1. A sensing element
  2. Microcontroller Unit (MCU) (may be optional in some cases)
  3. Modulator and transmitter (mainly RF)
  4. Battery (sometime powered by solar energy)

Many of these sensor nodes are placed at a regular distance over a large geographical area to cover the entire area. They all send their data to a receiver that is placed in the central monitoring and data storage system. All sensor nodes transmit data (sensor value) periodically. The receiver receives the data from all these nodes and it is stored and displayed for monitoring and control purposes.

Just take a look at an example.

  • It is necessary to maintain the set temperature in every corner of the entire cold storage area. Therefore, many small wireless temperature sensor nodes are installed in different corners. Together, they detect the ambient temperature and transmit the detected value to the central monitoring and control room. This way, the central controller will be able to get the temperature readings from every corner of the storage area and based on that, it will try to maintain the same temperature in every corner.

Here in this project for sensor node, I used MQ2 gas sensor to detect different gases (like CO2, methane, LPG, propane, etc.) in the atmosphere. The idea is to detect gas leaks at any point. For example:

  • In a very long LPG gas line, these sensor nodes are placed at a regular distance. Therefore, whenever and wherever there is an in-line leak, the sensor node detects it and transmits it to the remote center to take control measures immediately
  • In an industry/chemical processing plant, these sensor nodes are placed at different locations (like in gas chambers, tanks, boilers, etc.) to detect hazardous gas leaks. They detect gas leaks and immediately send an alarm signal to a central control room. The central control room takes the necessary measures and thus catastrophic effects can be avoided.

The sensor node also consists of Arduino NANO as MCU and 433MHz ASK RF transmitter module. There can be many such sensor nodes but I have used only 2 such nodes. The receiver includes a 433 MHz ASK RF receiver module and Arduino NANO MCU. Both sensor nodes transmit data of detected GAS values. The receiver receives values ​​from both sensors and transmits them to the computer. The computer displays these values ​​and stores them for future use.

So, let's build the system, starting first with the block diagram, followed by a circuit diagram, its functioning and operation. The software program is provided in the latest

System block diagram

The complete system is divided into two distinct blocks

  1. Transmitter (also called sensor node)
  2. Receiver

There can be any number of sensor nodes situated at different locations, but there will be only one receiver connected to a central data storage system (computer).

The sensor node consists of four things: (1) different sensors, (2) microcontroller, (3) RF transmitter, and (4) battery. Here in our case

  • The sensor is an MQ2 gas sensor used to detect gas/smoke in the surrounding atmosphere
  • The Arduino nano board is used as a microcontroller that will read the data from the gas sensor and transmit it using an RF transmitter
  • An ASK-based RF transmitter module with a carrier frequency of 433 MHz is used to modulate and transmit the data to the receiver
  • 6V – 9V battery is used to provide power to complete the sensor node
  • An LED is also provided that will flash to indicate that the sensor node is active and transmitting data

The receiver consists of just two things: (1) RF receiver module and (2) microcontroller.

Here in our case

  • An ASK-based RF receiver module with a carrier frequency of 433 MHz is used to demodulate and receive data transmitted by the RF Tx module of the sensor node
  • The Arduino NANO board is used as a microcontroller that takes the data from the RF receiver module and delivers it to a computer that will store it for future use.
  • An LED is also provided here and will flash to indicate that the receiver is active and receiving data

Sensor node circuit diagram

sensor node circuit diagram As shown in the figure, there are only 3 main components in the circuit

  • The MQ2 sensor has only 4 pins for interface. (1) Vcc (2) Gnd (3) A0 and (4) D0. Pin D0 is a digital output (0 or 1) and is not used. A0 is an analog output and is connected to the Arduino analog input A0. The Vcc pin is connected to the 5V output of the Arduino board and Gnd is connected to the common ground
  • The 433 MHz RF Tx module has 4 interface pins. (1) Vcc (2) Gnd (3) data_in and (4) antenna. The Vcc pin is connected to the 5V output of the Arduino board and Gnd is connected to the common ground. The Data_in pin is connected to the D11 digital pin of the Arduino board. an antenna is formed by winding a 1 mm to 35 cm long copper wire (single core) which is connected to a pin on the antenna
  • An LED is connected to digital pin D12 through a current limiting resistor
  • A 9V battery is used to power the Arduino board. The Vin pin of the Arduino board is connected to the battery. Thus, the board will obtain working voltage and generate 5V power from the integrated 7805 voltage regulator chip, and this is supplied to the DHT11 and RF Tx module

Remote Data Receiver Circuit Diagram

As shown in the figure, there are only three main components in this receiver circuit

  • The 433 MHz RF Rx module has 4 interface pins. (1) Vcc (2) Gnd (3) data_out and (4) antenna. The Vcc pin is connected to the 5V output of the Arduino board and Gnd is connected to the common ground. The Data_out pin is connected to the D12 digital pin of the Arduino board. an antenna (same as the transmitter side) is connected to the antenna pin
  • An LED is connected to digital pin D10 through a current limiting resistor
  • A 5V DC buzzer is connected to digital pin D7 as shown
  • Arduino board and RF Rx module get power from laptop/desktop PC/computer with central storage system via USB cable. The Arduino board also records data and communicates with the computer using the same USB cable

Work and operation

Sensor node
If I want to say the operation of the sensor node in a single line, I will say: “it will periodically detect gases and transmit them”. But it's not that simple. There can be 2, 3, 5, 10 or N number of sensor nodes, as we saw in the block diagram. They are all doing the same thing. More than one node can transmit data at the same time. Another question is: “how would the receiver know that the data received is from a specific node (say, node 1, node 2, etc.)?”

To overcome these problems, special measures must be taken. All sensor nodes will be synchronized in time so that no two nodes transmit simultaneously. Either way, if this happens, the receiver will accept any sensor data. Furthermore, all nodes are assigned numbers (say from 1 to N) and before transmitting data, they transmit the node number. Therefore, the receiver would know that this data is from sensor node X.

  • The MQ2 gas sensor provides analog voltage output directly proportional to the gas level in the surrounding atmosphere. This means that its output voltage increases as the gas concentration increases. The 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 (character array) of 4 characters like

node number + gas concentration

(2 characters) (2 characters)

  • And then pass to RF Tx module via pin D11
  • RF Tx module takes this 10 character string (we can call it packet ), modulates it using 433 MHz carrier and transmits it using antenna
  • Whenever a packet is transmitted, the microcontroller blinks the LED to indicate that the data is transmitted
  • This cycle repeats continuously after the set period of time (say 3, 5 or 10 seconds)

Remote Data Receiver

  • The RF Rx module receives packets from each node. It demodulates and delivers this package to the Arduino microcontroller
  • The microcontroller gets the packet and extracts the gas level value (in%) along with the node number
  • It sends this data serially to the computer via USB as

Node x

Gas Level: XXX%

  • The microcontroller blinks the LED to indicate that data has been received
  • If the gas level at any node is higher than the threshold level, the buzzer will sound continuously to indicate gas leakage problem
  • This process repeats for every packet received from any node at any time. because all nodes are synchronized in time, they all transmit data one after another
  • So the receiver will get data from all nodes one by one and update the readings of any node after the set period of time
 Sensor node program:
 #include <VirtualWire.h>
 #define MQ2_pin A0

 const int led_pin = 12;
 const int transmit_pin = 11;
 char str1(2);
 char node(3) = "01"; // node number. change this node number for
 char trnsmit_str(4);// different node
 void setup
 {
 vw_set_tx_pin(transmit_pin);
 vw_set_ptt_inverted(true);
 vw_setup(2000); // Bits per sec
 Serial.begin(9600);
 pinMode(led_pin, OUTPUT);
 }
 void loop
 {
 int gas,gas_level;
 gas=analogRead(MQ2_pin);
 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 
Serial.print(gas_level);
 Serial.println(" %");
 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
 strcat(trnsmit_str,str1);
 Serial.print("transmitted string: ");
 Serial.println(trnsmit_str);
 vw_send((uint8_t *)trnsmit_str, 4);
 vw_wait_tx ; // Wait until the entire message is gone
 digitalWrite(led_pin, LOW);
 delay(5000);
 }

 Sensor node program: Receiver program for 2 nodes:
 #include <VirtualWire.h>
 #define gas_threshold 80
 #define siren 7
 const int receive_pin = 12;
 int led = 10,gas_level;
 void setup
 {
 Serial.begin(9600); // setup serial communication
 vw_set_rx_pin(receive_pin);
 vw_set_ptt_inverted(true);
 vw_setup(2000); // wireless data rate
 vw_rx_start ; // Start the receiver PLL running
 pinMode(led,OUTPUT);
 pinMode(siren,OUTPUT);
 digitalWrite(led,LOW); 
digitalWrite(siren,LOW);
 delay(1000);
 Serial.println("Receiving sensor DATA from all nodes.....");
 }
 void loop
 {
 uint8_t buf(VW_MAX_MESSAGE_LEN);
 uint8_t buflen = VW_MAX_MESSAGE_LEN;
 int i;
 if (vw_get_message(buf, &buflen)) // when msg is received
 {
 digitalWrite(led,HIGH);
 if(buf(1)=='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);
 Serial.println(" %");
 gas_level = (buf(2)-48)*10 + (buf(3)-48)*1;
 if(gas_level>gas_threshold) digitalWrite(siren,HIGH);
 else digitalWrite(siren,LOW);
 }
 else if(buf(1)=='2')
 {
 Serial.println("Node 2");
 Serial.print("Gas Level: ");
 for (i = 2; i < 4; i++) Serial.print(buf(i)-48);
 Serial.println(" %"); 
gas_level = (buf(2)-48)*10 + (buf(3)-48)*1;
 if(gas_level>gas_threshold) digitalWrite(siren,HIGH);
 else digitalWrite(siren,LOW);
 }
 }
 }

{

(tagsToTranslate)Arduino

Conteúdo Relacionado

ESP32-CAM is a compact camera module that combines the...
A network of sensors is embedded in every vehicle,...
The motor controller is one of the most important...
A evolução dos padrões USB foi fundamental para moldar...
A SCHURTER anuncia um aprimoramento para sua conhecida série...
A Sealevel Systems anuncia o lançamento da Interface Serial...
A STMicroelectronics introduziu Diodos retificadores Schottky de trincheira de...
Determinar uma localização precisa é necessário em várias indústrias...
O novo VIPerGaN50 da STMicroelectronics simplifica a construção de...
A Samsung Electronics, fornecedora de tecnologia de memória avançada,...
O mercado embarcado tem uma necessidade de soluções de...
You have probably come across the term ' drag...
You probably have a support insulator if you've noticed...
You've probably seen stand an insulator sit on power...
You've probably seen shackle insulators enthroned on electricity poles,...
You have probably experienced situations where controlling a circuit...
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.