Introduction: How to Code "A Hiker's Scrapbook"
People tend to be nostalgic about hobbies that are important to them, such as hiking.
But how do you keep memory of a hike?
Pictures are an option, yes. This device would allow another option to be data archives from the trip. The person would have a graph plotting the time the hike took compared to the altitude they hiked. In addition, it would tell them the max, min, and average pressure they were exposed to throughout the length of the hike.
This uses Internet of Things Altitude and Pressure sensor to monitor and record data about the hike. MATLAB is then used to analyzed the data to output key pressure readings and a graph of time vs. altitude.
Step 1: Parts and Materials
Sparkfun ESP8266
Compatible altitude/pressure sensor
Wires
USB to micro-USB cable
ThingSpeak account
Arduino software
MATLAB software and ThingSpeak tool box
Step 2: Setting Up Software
Create an account
Create a "New Channel"
Label Field 1 as Altitude and Field 2 as Pressure
Save channel
Go to "Sharing" and select "Share channel view with everyone"
Paste code from [https://ef.engr.utk.edu/ef230-2017-08/projects/ard...] into Arduino
Change WiFi network "ssid" and password
Change "streamID" and "privateKey" to match API Keys on ThingSpeak
Step 3: Setting Up Hardware
Wire hardware according to the above picture
Plug USB into laptop and ESP8266
Step 4: Connecting to Your Device
Look for and flip the small, black switch on the ESP8266 to turn on
Click the right-facing arrow at the upper left corner of Arduino program to upload code (this may take a few minutes)
Now the sensor readings should be outputting data to the ThingSpeak website, which is represented graphically
Step 5: MATLAB Coding
Copy the following code for the function "microcontroller_project" into MATLAB
Alter the bold text to fit the specific ThingSpeak channel
(The "90" in bold refers to the minutes worth of data taken into account from the channel. Change this manually according to how long the channel has been running.)
Call the function by typing "microcontroller_project" into the Command Window
Code:
function [graph Pressures_Pa] = microcontroller_project ()
data = thingSpeakRead(364102,'Fields',[1,2],'NumMinutes',90,'OutputFormat','table');
readChannelID=364102;
readAPIKey='U9AJ9S68KVNYQKQV';
altitudefieldID=1;
pressurefieldID=2;
writeChannelID=364102;
writeAPIKey='6H8W3UNH6HMT1TCZ';
for i=1:max(size(data))
timestamp=data(i,1);
time_cell_array=table2cell(timestamp);
time_string_array=datestr(time_cell_array{1,1});
hour=str2num(time_string_array(13:14));
minute=str2num(time_string_array(16:17));
second=str2num(time_string_array(19:20));
time(i)=3600.*hour+60.*minute+second;
end
alt=data(:,2);
alt2=table2cell(alt);
altitude=transpose(cell2mat(alt2));
p=data(:,3);
pressure=cell2mat(table2cell(p));
plot(time,altitude)
title('Hiking Trail Data: Time vs. Altitude')
xlabel('Time (sec)')
ylabel('Altitude (ft)')
str=date; legend(str)
Pressures_Pa.max=max(pressure)
Pressures_Pa.min=min(pressure)
Pressures_Pa.avg=mean(pressure)
end
2 Comments
5 years ago
cool
5 years ago
That's a neat way to keep a record of your hikes :)