“A Comprehensive Review of IoT-Based Carbon Dioxide Monitoring
Systems”
NAME = Siddu
USN = ENG23RA0018
ROLL NO = 18
Dept. of AI & Robotics, Dayananda Sagar University
[email protected]
matlab code
% File: co2_monitor_thingspeak.m
% ThingSpeak Configuration
writeAPIKey = 'EVM65B75T8QRTUZI'; % Replace with your ThingSpeak write API key
readChannelID = 2974704; % Replace with your ThingSpeak channel ID
readAPIKey = 'MC3WWPGBSIJSSP0X'; % Replace with your ThingSpeak read API key (optional
for public channels)
fieldNum = 1; % Field number for CO₂ data
% Setup
thingSpeakURL = 'https://api.thingspeak.com/update';
numDataPoints = 20; % Number of points to simulate
pauseTime = 15; % Seconds between uploads (ThingSpeak min is 15 seconds)
% Simulate and Upload CO2 Data
disp('Starting CO₂ data upload simulation...');
for i = 1:numDataPoints
% Simulate CO2 data (ppm)
co2ppm = 400 + 200 * rand(); % e.g., random between 400-600 ppm
disp(['Uploading CO₂ data point ', num2str(i), ': ', num2str(co2ppm), ' ppm']);
% Send data to ThingSpeak
response = webwrite(thingSpeakURL, ...
'api_key', writeAPIKey, ...
['field', num2str(fieldNum)], co2ppm);
% Wait before next upload
pause(pauseTime);
end
disp('Data upload completed.');
%% Retrieve and Plot CO₂ Data from ThingSpeak
% Optional analysis section
data = thingSpeakRead(readChannelID, ...
'Fields', fieldNum, ...
'NumPoints', numDataPoints, ...
'ReadKey', readAPIKey);