Untitled
% Seri port bağlantısını aç arduinoPort = serial('COM3', 'BaudRate', 9600); % Port numarasını kontrol edin fopen(arduinoPort); % Gerçek zamanlı veri okuma ve görselleştirme figure; while true if arduinoPort.BytesAvailable > 0 data = fscanf(arduinoPort, '%s'); disp(data); % Sıcaklık, nem ve ses verilerini ayrıştırın tokens = regexp(data, 'Temperature: ([\d\.]+) C, Humidity: ([\d\.]+) %, Sound Level: (\d+)', 'tokens'); if ~isempty(tokens) temperature = str2double(tokens{1}{1}); humidity = str2double(tokens{1}{2}); soundLevel = str2double(tokens{1}{3}); % Görselleştirme (örnek: sıcaklık grafiği) subplot(3, 1, 1); plot(temperature, 'r.-'); title('Temperature (°C)'); xlabel('Time'); ylabel('Temperature'); subplot(3, 1, 2); plot(humidity, 'b.-'); title('Humidity (%)'); xlabel('Time'); ylabel('Humidity'); subplot(3, 1, 3); plot(soundLevel, 'g.-'); title('Sound Level'); xlabel('Time'); ylabel('Sound Level'); drawnow; end end end % Seri portu kapat fclose(arduinoPort); delete(arduinoPort);
Leave a Comment