Verwendete Bauteile und Software:
#GP2Y10141325 #stm32f103ze #matlab #150-Ohm-Widerstand #220uF-Kondensator #keil uVision5
MATLAB-Code:
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





