Clear Filters
Clear Filters

How to extract only specific data from whole bunch of string that is coming from Arduino ?

5 views (last 30 days)
I am using 2 pairs of Arduino, Xbee, DHT11 sensor, and an MQ2 sensor that will transmit data to the third Arduino, Xbee connected to the computer with Matlab. Matlab GUI was created to display data from two Xbee's. The transmitted data consists of source address and data of Xbee1 and Xbee2 along with some other data like the checksum. Using Matlab I want to read incoming data(Data continuously coming from both 2 pairs of Arduino, Xbee) and extract the data I want(source address and values of DHT11,MQ2) from whole data. How to achieve this?

Answers (2)

Robert Adam
Robert Adam on 3 Apr 2018
Could you tell me please what is the code you used on the both transmitters? I mean the code on the Arduino board which are connected to the sensors?...I really need your answer..
  1 Comment
Karthik Muthineni
Karthik Muthineni on 4 Apr 2018
Hello Robert Adam, I have integrated dht11 and mq2 sensors with Arduino and plotted the live data from these sensors in Matlab. Here is my Arduino code that I have used
#include dht.h
SoftwareSerial sensor(2,3);
#define dataPin A1
#define mq2Pin A2
dht DHT;
void setup(){
Serial.begin(9600);
sensor.begin(9600);
}
void loop(){
int readData=DHT.read22(dataPin);
float t=DHT.temperature;
float h=DHT.humidity;
float s=analogRead(mq2Pin);
Serial.print(t);
Serial.print(h);
Serial.println(s);
delay(1000);
}

Sign in to comment.


Srinidhi B R 16MMT0007
Srinidhi B R 16MMT0007 on 26 Feb 2018
Hello karthik,
if you are sending the data in a specified format then its really easy to log it in MATLAB.
the follwing image shows how i am sending a array data in serial port . the variable SensorData is a 1x3 array which holds acceleration values from a ADXL345 sensor. after sending each value with a single space between them we need to send a new line feed ( Serial.println();) which will be defined as terminator in MATLAB.
now in MATLAB we need to program such that it detects the data in the specified sent format. here is the image of a part of the code in MATLAB
s is a Serial port object. sscanf command scans a length of data for the specified format and stores it in the store variable. if you use it in the loop correctly you will be able to log easily.
as you mentioned two arduino i believe you will have to create two serial object ports correspondingly and scan the particular port

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!