In factories and industries it is common to deal with the use of harmful and poisonous gases. There are situations in which the concentration and volume of this type of gases need to be monitored in a device. Since these gases can be harmful to humans, it is not safe to employ humans for such tasks. Thus, robots can be used to monitor different parameters related to the use of such gases in a gas-filled device or chamber. In this tutorial, a wireless robot is designed that can move inside a chamber or well and detect the gas concentration level there.
X-bee modules are used to connect the robot wirelessly with a remote control. X-bee is a Zigbee module from Digi International. Zig-Bee is a standard wireless communications technology that transfers data in ISM radio bands. Operates on 2.4 GHz worldwide and on other ISM frequencies in selected countries. The communications protocol is commonly used to create personal area networks for applications such as home automation, wireless office networks, and sensor-based data networks. Zig-Bee modules are commonly used to connect low-power embedded devices that need to operate in a small area with low data rates. A Zig-Bee module operating in the 2.4 GHz band has a data rate of 250 Kbps. With X-bee used for wireless connectivity, the robot can be moved 30 to 100 meters away from the remote control.
The remote control has a keyboard that allows you to control the robot's movement and send instructions to perform concentration level measurements. There is also an LCD display on the remote control that allows you to monitor the measurements taken. The robot is a surface-moving robot with a caster and a two-wheeled body. The robot is equipped with MQ-135 and MQ-7 gas sensors to monitor the presence and concentration of gases. The MQ-7 is used to measure the concentration of carbon monoxide in the air, while the MQ-135 is used to monitor the concentration of combustible gases. The robot is driven on two wheels with a L293D motor driver IC used to control the DC motors with connected gears. The X-bee module is used to connect the robot to the remote control.
Fig. 1: Keyboard-controlled wireless Arduino robot prototype based on X-bee for gas monitoring
Required components:
Fig. 2: List of components required for X-bee based wireless keyboard controlled Arduino robot for gas monitoring
Block Diagram:
The robot remote control circuit can be represented by the following block diagram –
Fig. 3: Remote control block diagram for X-bee based wireless keyboard controlled gas monitoring Arduino robot
The control circuit of the robot (mounted on it) can be represented by the following block diagram –
4: Block diagram of control circuit for wireless Arduino keyboard controlled gas monitoring robot based on X-bee
Circuit Connections –
There are two circuits used in the project – one is the remote control circuit and the other is the control circuit mounted on the robot. The remote circuit is built using Arduino Mega, 4X3 keyboard, 16X2 character LCD and X-bee module. The control circuit of the robot mounted on its body is composed of Arduino UNO, MQ-135 sensor, MQ-7 sensor, X-bee module, L293D motor driver IC and DC geared motors.
The remote circuit has the following circuit connections –
5: Picture of remote control for wireless Arduino keyboard controlled gas monitoring robot based on X-bee
Arduino Mega – Arduino Mega is one of the microcontroller boards available on the Arduino platform. This controller board has Atmega 1280 as sitting MCU and has 128 Kb flash memory, 4 Kb EEPROM, 8 Kb SRAM, integrated UART, SPI and I2C interfaces. The board has 56 GPIO pins, of which 15 pins can be used for 8-bit PWM output. There are 16 analog input pins available on the board as well. This is a larger controller board available in Arduino and is generally used when the number of sensors or components required to interface is large. In the remote circuit, 15 pins of the board are utilized, where 6 pins are used to interface the character LCD, 7 pins are used to interface the keyboard, and Rx and Tx pins are used to connect with the X-bee module.
4X3 Keyboard – A 4X3 keyboard is used in the project. The keyboard has 12 buttons arranged in 4 rows and 3 columns. This is a numeric keypad that is used to control the movement of the robot and send instructions to measure the gas concentration. The rows and columns of the keyboard interface with the Arduino in the following scheme –
Fig. 6: Table listing the circuit connections between the Arduino Mega and the keyboard
This matrix keyboard operates by steering between a single row and column at the press of a button. Any one of the rows or columns is transformed into digital output, while the remaining others (rows or columns) are transformed into digital input. Suppose rows are defined as digital output and columns as digital input. Now, the controller cycles through the lines generated in the digital output, setting them to HIGH or LOW one after the other and simultaneously checks the reception of the same logic in the columns. So, at a time, a single row is set to HIGH or LOW while other rows are set inversely and upon pressing a key the same logic is received in a single column. This unique combination of row and column allows you to identify the key pressed.
16X2 Character LCD – The 16X2 LCD display is used to monitor the sensor values sent by the wireless robot. It interfaces with the Arduino MEGA by connecting its data pins D4 to D5 with the controller's pins 6 to 3, respectively. The LCD's RS and E pins are connected to the controller's pins 13 and 12, respectively. The RW pin of the LCD module is connected to ground. The character LCD circuit connections with the Arduino board are summarized in the following table –
Fig. 7: Table listing circuit connections between Arduino Uno and Character LCD
X-bee module – X-Bee is a Zigbee module from Digi international. Zigbee is a wireless communication module that uses the IEEE 802.15.4 standard. 802.15.4 is an IEEE standard for low-power radio frequency applications. It is used in many products for wireless communication functionality. It can be used as a transmitter and receiver. It uses serial communication to send and receive data. It has two series, series 1 and series 2. Series 1 is comparatively easy to use and is recommended for beginners. In this project, the X-bee Series 1 module is used. The Zigbee Series 1 module cannot work in a mesh network. This means that it cannot talk to more than one Zigbee at the same time. Learn more about Zigbee Technology.
X-bee series 1 is a 20-pin module with the following pin configuration –
Fig. 8: Table listing the Xbee Module pin configuration
The module can be connected to a controller board using UART. The module can be connected to Arduino by connecting its DOUT (UART Data Out) or TX pin with RX pin of Arduino and DIN (UART Data In) or RX pin with TX pin of Arduino. The module's VCC and Ground pins must be connected to common VCC and ground. The X-Bee module used in the remote circuit is configured to function as both an RF data transmitter and a receiver. The remote control needs to transmit control commands while needing to receive data from the robot's sensor.
Power supply – All remote circuit components require a 5V DC supply. The Arduino board is powered by 5V via a USB cable. The other components draw power from the 5V Vout pin on the Arduino board.
The control circuit mounted on the robot is assembled from the following components –
Fig. 9: Image of control circuit for X-bee based wireless keyboard controlled gas monitoring Arduino robot
Arduino UNO – Arduino UNO is one of the most popular prototyping boards. It is often used in robotic applications because it is small and packed with advanced features. The board comes with an integrated Arduino bootloader. It is an Atmega 328 based controller board that has 14 GPIO pins, 6 PWM pins, 6 analog inputs and integrated UART, SPI and TWI interfaces. In this control circuit, 8 pins on the board are used. There are 4 pins used to connect with the motor driver IC input pins. The two pins RX and TX on the board are used to interface the X-bee module and establish serial communication via USART. Analog input pins A0 and A1 are used to interface MQ-7 and MQ-135 sensors. Learn more about the Arduino UNO here.
MQ-7 Gas Sensor – MQ-7 is a carbon monoxide sensor used to measure the concentration of CO gas in the air between the range of 20 PPM to 2000 PPM. The sensor uses SnO2 as a sensitive material that has low conductivity in clean air, but has high conductivity when the concentration of carbon monoxide is higher in the air. The sensor is used as industrial CO gas alarm and portable CO gas detector.
Fig. 10: Graph showing the sensitivity curve of the MQ-7 CO sensor
From the sensor sensitivity curve, it can be seen that the sensor resistance decreases as the target gas concentration increases in PPM, while for clean air its resistance remains constant. In the graph, Rs is the resistance in the target gas and Ro is the resistance in clean air. The graph is shown for the gases CO, CH4 and H2.
Fig. 11: Graph showing the analog voltage output curve of the MQ-7 CO sensor
It can be seen that as the target gas concentration increases, the voltage output also increases. The graph above was obtained for a load resistance of 4.7 KΩ. The sensor has four terminals – Ground, VCC, Digital Output and Analog Output. The sensor's VCC and Ground terminals are connected to common VCC and Ground. The sensor's analog output pin is connected to the Arduino pin A0. The analog output voltage of the sensor can be assumed to be directly proportional to the CO gas concentration in PPM under standard conditions. The analog voltage is detected by the sensor and converted to a digital value in the range 0 to 1023 by the controller's integrated ADC channel. The digitized value is therefore equal to the gas concentration in PPM.
MQ-135 Sensor – MQ-135 is another gas sensor used to measure the concentration of combustible gases. It has lower conductivity in clean air, while its conductivity increases with the presence of combustible gases in the air. The sensor is highly sensitive to gases such as ammonia, sulfide and benzene vapor. The sensor can detect the concentration of combustible gases in the range of 100 PPM to 1000 PPM.
Fig. 12: Graph showing the MQ-135 Sensor Sensitivity Curve
From the sensor sensitivity curve, it can be seen that the sensor resistance decreases as the target gas concentration increases in PPM, while for clean air its resistance remains constant. In the graph, Rs is the resistance in the target gas and Ro is the resistance in clean air. The graph is shown for Carbon Dioxide, Carbon Monoxide and Ammonia. The sensitivity of this sensor can be adjusted and calibrated to detect a specific concentration level of a target gas. The sensor has four terminals – Ground, VCC, Digital Output and Analog Output. The sensor's VCC and Ground terminals are connected to common VCC and Ground. The sensor's analog output pin is connected to the Arduino pin A1. The analog output voltage of the sensor can be assumed to be directly proportional to the CO2 gas concentration in PPM under standard conditions. The analog voltage is detected by the sensor and converted to a digital value in the range 0 to 1023 by the controller's integrated ADC channel. The digitized value is therefore equal to the gas concentration in PPM.
X-Bee Module – The X-Bee module used in the robot control circuit is also configured to function as both a receiver and transmitter of RF data. The module interfaces with the Arduino by connecting its DOUT (UART Data Out) or TX pin with the Arduino's RX pin and DIN (UART Data In) or RX pin with the Arduino's TX pin. The module's VCC and Ground pins are connected to VCC common and ground.
L293D Motor Driver IC – The L293D is a dual H-bridge motor driver integrated circuit (IC). Motor drivers act as current amplifiers in that they receive a low current control signal and supply a higher current signal. This higher current signal is used to drive the motors. It has 16 pins with the following pin configuration:

Fig. 13: Table listing the L293D motor driver IC pin configuration
There are two DC motors used to make the robotic car. DC motors interface between pins 3 and 6 and pins 14 and 11 of the motor driver IC.
IC L293D controls DC motors according to the following truth tables:
Fig. 14: Truth table of L293D motor driver IC
Pins 4, 5, 13 and 12 of the L293D are grounded while pins 1, 16 and 9 are connected to 5 VDC and pin 8 is connected to 12 VDC. Pins 15, 2, 7 and 10 of the motor driver IC are connected to pins 5, 2, 3 and 4 of the Arduino board. The DC motor connected to the right wheel is connected to pins 11 and 14, while the motor connected to the left wheel is connected to pins 3 and 6 of the motor driver IC. The IC enable pins (pins 1 and 9) are physically connected to the 5 VDC source.
Geared DC Motors – In this robot, 12V DC geared motors are attached to the wheels. Geared DC motors are available with a wide range of RPM and Torque, which allows a robot to move based on the control signal it receives from the motor driver IC.
Power Source – The Arduino UNO, X-Bee module, gas sensors, and motor driver IC logic power pins require 5V DC, while the driver IC power pin requires 12V DC. A 12V battery is used to power the robot. The battery power is regulated to 5V and 12V using 7805 and 7812 ICs. Pin 1 of both voltage regulator ICs is connected to the battery anode and pin 2 of both ICs is connected to ground. The respective voltage outputs are taken from pin 3 of the respective voltage regulator ICs. An LED along with a 10K Ω pull-up resistor is also connected between the common ground and the output pin to get a visual cue of power continuity. Despite using a 12V battery, the 7812 is used to provide a regulated and stable power supply to the motor driver IC.
How the circuit works –
As the battery is attached to the robot, it prepares to receive commands from the remote control. The remote control is powered by connecting it to a USB connection or a regulated 5V supply from a battery. As the remote control is turned on, some initial messages flash on it indicating the application of the project. From the remote control, commands can be transmitted by pressing keys on the keyboard. The following keys are assigned to the respective tasks in the project –
Fig. 15: Table listing remote key assignments for the Robot
When the user presses a key, a string command is passed from the remote control to the robot's control circuit using the X-bee interface. The following string characters are passed through the remote circuit to the robot's receiving circuit on pressing the respective keys –
Fig. 16: Table listing command sequences for remote control of the robot
The command strings are read by the Arduino board from the receiver circuit with the help of another X-bee module. On receiving a command, the Arduino board compares it with the above-mentioned command strings and changes the digital logic on the pins connected to the input pins of the motor driver IC to perform the desired operation. The robot is moved forward, backward, left or right by implementing the following input logic on the motor driver pins –
Fig. 17: Logic table of L293D motor driver IC for Arduino robot
The input pins of the motor driver IC are connected to the Arduino pins and by changing the digital logic on the Arduino pins, the respective logic is implemented on the input pins of the motor driver IC.
Thus, the user can navigate the robot to the location where it should measure gas levels. Once the robot reaches this point, the user needs to press key 1 or 3 to pass the CO or CO2 concentration measurement command respectively. When the command to measure gas concentration from the MQ-7 or MQ-135 sensor is received, the Arduino board detects the voltage at pin A0 or A1 respectively. The voltage is converted into a digital readout using the onboard ADC channel and sent as a string back to the remote circuit. The remote circuit receives the measured gas level as serial data from the X-bee module. The Arduino remote circuit sketch converts this string into an integer value and displays it on the LCD display.
Fig. 18: Image of X-bee based keyboard controlled wireless Arduino robot for gas monitoring
To activate the wireless connection between the robot and the remote circuit, it is important to configure the X-Bee modules on both sides. The CoolTerm terminal application is used to configure the X-Bee modules. To make PC communicate directly with Xbee, even Arduino board can be used by removing the controller IC or a simple sketch can be uploaded to Arduino boards which makes Xbee enabled to communicate with computer directly and not with the Arduino board. Firstly, the circuit connections between the X-Bee module and the Arduino must be made as mentioned above.
Now follow the following steps –
Open the CoolTerm app and navigate to connection -> options -> serial port and select the COM port. Set the baud rate and go to the Terminal option and select the Local Echo checkbox to display the entered commands and click OK to save the changes.
Fig. 19: Screenshot of the CoolTerm application
Fig. 20: Screenshot of connection options in the Coolterm app
To configure X-Bee, the following AT commands must be used.
First make X-Bee enter command mode by typing +++ in the terminal, when OK, follow with the other AT commands
Firstly, XBEE radios only operate at a certain baud rate, which is the number of bits per second that the X-Bee can send. A brand new X-Bee has a default baud rate of 9600 bps, which is quite slow. The baud rate can be changed by changing the ATBD register. Both X-Bee modules must have the same baud rate to communicate with each other. The available baud rates (and corresponding ATBD value) are as follows –

Fig. 21: Table listing ATBD commands for different baud rates
Therefore, to set the baud rate to 9600, the following command must be passed –
ATBD3
The next important parameter is the Personal Area Network ID. This is a number shared between each XBEE on a network. Here, there are only 2 X-Bee modules, but there can be many X-Bee modules in a network (for which X-Bee Series 2 modules must be used). X-Bee modules on different networks do not “see” each other. The default PAN is 3332, so avoid using this number. The PAN ID is stored in the ATID record. The registry can be changed by passing the following command –
ATID1001
Once both X-Bee modules are on the same network, they must each be assigned an address number indicated by the ATMY record. The destination address can also be set, which is the address number to communicate with and is indicated by the ATDL register (for low destination, there is no need to use the high bytes if the address numbers are less than 16 bits of lenght). An example configuration of two X-Bee modules that will communicate directly with each other at 38.4 kbps can be done by passing the following commands –
ATMY10
ATDL11
Therefore, both the X-Bee modules are configured by passing the following AT commands –
XBEE1:
ATID1001
ATMY10
ATDL11
ATBD3
XBEE2:
ATID1001
ATMY11
ATDL10
ATBD3
One important thing to note is that the changes you make are stored in temporary memory. if the X-Bee modules are turned off, the settings will be lost. Send ATWR to write changes to non-volatile memory so they are not lost during shutdown.
Fig. 22: CoolTerm app screenshot showing AT commands passed to the Xbee module
Once the X-Bee modules are configured, the Arduino sketch for the remote circuit and receiver circuit can be uploaded to the respective controller board.
Check the Arduino sketch of both side controllers to know how the Arduino boards manage the entire operation in coordination and provide software intelligence for both the remote circuit and the robot control circuit.
Programming guide –
Remote Control Program: The target board for this program is the Arduino MEGA. The Arduino code for the remote control first imports LiquidCrystal.h to handle the LCD display and Keypad.h to handle keyboard input. Variables to indicate the number of rows and columns in the matrix keyboard are defined and an LCD-type object is instantiated. Matrix keyboard keys are represented as a multidimensional array and a keyboard object is instantiated. The setup function is called in which the baud rate for serial communication with the X-bee module is set to 9600 and the LCD is initialized into 16X2 character LCD mode using the start method on the LCD object. Some initial messages flash on the LCD display indicating the project application.
Fig. 23: Screenshot of initialization in Arduino code for Xbee-based Arduino gas monitoring robot
The loop function is called in which the keystroke is detected using the useKey method of the Keypad object. The pressed key is stored in a variable and compared with the keys mentioned in the table above using if statements. For each key pressed, a single character string is passed to the X-bee module for transmission using the println function. The functions write the string character to the serial buffer from which it is transmitted via the X-bee module.
Fig. 24: Screenshot of loop function in Arduino code for Xbee based gas monitoring Arduino robot
In the loop function, pressing key 1 or 3 sends the command to measure the concentration of CO or CO2 gas respectively. The string command used for CO gas measurement is 'C' while the string command used for CO2 gas measurement is 'A'. The gas concentration is received as a string value from the X-bee module which is converted to an integer value using the atoi function and is displayed on the LCD screen.
Fig. 25: Screenshot of loop function in Arduino code for Xbee based gas monitoring Arduino robot
This completes the Arduino sketch in the remote circuit. Please check the full outline in the code section.
Robot Control Circuit Program: – The target board for this sketch is the Arduino UNO. The Arduino code first defines variables that represent the connections of the Arduino pins to the input pins of the motor driver IC. A variable is declared to store the sensor value and a variable is declared to store the message containing the sensor reading. Functions for moving the robot in different directions are declared. This is followed by the setup function which must be executed once when the robot is turned on. In the setup function, the baud rate for serial communication with the X-bee module is set to 9600 and the pins connected to the motor driver IC are configured as digital output using the pinMode function.
Fig. 26: Screenshot of initialization in Arduino code on the robot side
The loop function is called and continuously checks the received serial data. If serial data is available, the data is read using the serial.read function and stored in a variable. Then the stored data is checked with the mentioned conditions. Then, with respect to the conditions, the respective functions are called to move the robot or measure the gas concentration from the MQ-7 or MQ-135 sensors.
Fig. 27: Screenshot of the loop function in the Arduino code on the robot side
When the command is received to measure the gas concentration, the values are measured using the analogRead function and the measured value is sent to the remote circuit in the form of a string via the X-bee module. When the command to move the robot is received, the digital logic on the input pins of the motor driver IC is changed to move the robot in the respective direction.
This completes the Arduino sketch for the robot control circuit. Check out the full outline in the code section.
Project source code
###
//Program to
#include
#include
const byte ROWS = 4; //four rows
const byte COLS = 3; //four columns
LiquidCrystal LCD(13, 12, 6, 5, 4, 3);
char hexaKeys(ROWS)(COLS) = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins(ROWS) = {41, 43, 45, 47}; //connect to the row pinouts of the keypad
byte colPins(COLS) = {49, 51, 53}; //connect to the column pinouts of the keypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); //initialize an instance of class NewKeypad
void setup
{
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Engineers Garage");
lcd.setCursor(0,1);
lcd.print(" ");
delay(3000);
lcd.setCursor(0,0);
lcd.print("INDSL MONITORING");
lcd.setCursor(0,1);
lcd.print(" WIRELESS ROBOT");
delay(3000);
}
void loop
{
char customKey = customKeypad.getKey;
if(customKey == '2')
{
Serial.println("F");
lcd.clear;
lcd.setCursor(0, 0);
lcd.print("<--Direction-->");
lcd.setCursor(0, 1);
lcd.print("FORWARD");
}
if(customKey == '8')
{
Serial.println("B");
lcd.clear;
lcd.setCursor(0, 0);
lcd.print("<--Direction-->");
lcd.setCursor(0, 1);
lcd.print("BACKWARD");
}
if(customKey == '4')
{
Serial.print("L");
lcd.clear;
lcd.setCursor(0, 0);
lcd.print("<--Direction-->");
lcd.setCursor(0, 1);
lcd.print("LEFT");
}
if(customKey == '6')
{
Serial.println("R");
lcd.clear;
lcd.setCursor(0, 0);
lcd.print("<--Direction-->");
lcd.setCursor(0, 1);
lcd.print("RIGHT");
}
if(customKey == '5')
{
Serial.println("S");
lcd.clear;
lcd.setCursor(0, 0);
lcd.print("<--Direction-->");
lcd.setCursor(0, 1);
lcd.print(" STOP");
}
if(customKey == '1')
{
Serial.println("C");
lcd.clear;
lcd.setCursor(0, 0);
lcd.print("CarbonMonoxide");
lcd.setCursor(0, 1);
lcd.print("Reading");
delay(500);
char buffer = {' ',' ',' ',' ',' '};
while (!Serial.available );
//when serial is available read the data till newline and store to buffer
Serial.readBytesUntil('n', buffer, 10);
//converting the character to integer
int incomingValue = atoi(buffer);
// Serial.println(incomingValue);
lcd.clear;
lcd.setCursor(0, 0);
lcd.print("Measured value");
lcd.setCursor(0, 1);
lcd.print(incomingValue);
}
if(customKey == '3')
{
Serial.println("A");
lcd.clear;
lcd.setCursor(0, 0);
lcd.print("AirQuality");
lcd.setCursor(0, 1);
lcd.print("Reading");
delay(500);
char buffer = {' ', ' ', ' '};
while(!Serial.available );
Serial.readBytesUntil('n', buffer, 10);
int incomingValue = atoi(buffer);
lcd.clear;
lcd.setCursor(0, 0);
lcd.print("Measured value");
lcd.setCursor(0, 1);
lcd.print(incomingValue);
}
}
###
Circuit diagrams
| Circuit Diagram-Remote Control-Xbee-Gas Monitoring-Arduino-Robot |
 |
| Circuit Diagram-Xbee-Gas Monitoring-Arduino-Robot |
 |
Project video