Medición de PM2.5 y análisis en tiempo real en MATLAB

Medición de PM2.5 con un sensor GP2Y1014 y un STM32, y representación de los datos en tiempo real en MATLAB a través de UART (con circuito y código).

Dispositivos y software utilizados:

#GP2Y10141325 #stm32f103ze #matlab #resistencia-150-ohmios #condensador-220uF #keil uVision5

Código fuente

Código de MATLAB:

clear;
clc;
clf;
delete(instrfindall);  %delete instrfind (required)
ob=serial('COM5');%set up the UART interface
set(ob,'BaudRate',115200);
set(ob,'BytesAvailableFcnCount',1);
set(ob,'BytesAvailableFcnMode','byte');
set(ob,'TimeOut',0.1);%set the timeout
fopen(ob);%open COM5
pm=fread(ob);%read the data
PM0=hex2dec(pm);
t=0:18;
PM=zeros(1,19);
while(1) 
  pm=fread(ob);
  PM0=hex2dec(pm);
  size(PM0)
  if (length(PM0)==69||length(PM0)==66||length(PM0)==72||length(PM0)==57||length(PM0)==63)
    for i=1:19
      PM(i)=PM0(3*i-2)*100+PM0(3*i-1)*10+PM0(3*i);
    end
  else
    for i=1:19
      PM(i)=PM0(2*i-1)*10+PM0(2*i);
    end
  end
  plot(t,PM);
  axis([0 18 0 696]);
  ylabel('PM2.5(g/cm^{3})');
  pause(0.1);%required
end
Gráfica de PM2.5 en tiempo real en MATLAB
Foto del montaje de medición de PM2.5
Medición de PM2.5 en curso