Introduction: Desert Railroad Temperature Detector & Passenger Counter

Purpose:

Temperature: This instructable will teach you how to set up and program an Arduino RedBoard (using MATLAB) to detect the temperature of a railroad. When an unsafe temperature for the passengers is reached, a warning message sounds, buzzers go off, and a warning sign lights up .

Passenger Counter: This portion will teach you how to use a button in order to count passengers and sound a warning when max capacity has been reached.

Features:

  • Uses Button to count up passengers entering train
  • Uses TMP36 (temperature sensor) to detect the temperature of the railroad
  • Uses an Red LED light to warn the train station
  • Uses buzzers to sound alarm
  • Sends an alert email with a plot of temperature vs time
  • Pop-up warning messages on MATLAB

Step 1: Materials and Supplies

  • 1 Laptop
  • MATLAB 2017
  • Download Arduino Toolbox
  • Sparkfun RedBoard
  • 1 Power Cable
  • Breadbord
  • 14 wires
  • 1 Piezo Buzzer
  • 1 Push Button
  • 2 10k ohm resistors
  • 1 TMP36 sensor
  • Red LED light
  • 3D printed sign (optional)

Step 2: Board Setup

Follow the setup above

Step 3: Writing the Code

While Loop: To ensure the code continues to test the temperature and sense the button status (pressed or unpressed), we place the code in the while loop for a specified time period.

Using TMP36: We determine the temperature by reading the voltage and converting it to degrees Fahrenheit, using conversion factors. Then, we use an if statement to play a tone and sound/send alerts if the temp is greater than or equal to the set max temperature

Using Button: With an if statement, we can test if the button was pressed using readDigitalPin. This command will return a Boolean (1 or 0). If the response is 0, then the button was pressed and the counter of passengers increases and displays a welcome message. Then, when the max capacity is reached, a warning message is sounded.

Step 4: Copy the Code

%Inputs: Pushing the button, temperature sensor

%Outputs: lights, buzzers, audio alert, emails, graphs

%Purpose: This product is designed to help ensure the safety and comfort of %passengers traveling by train through the desert.

%Usage: Detecting the number of the passengers using a push button, and %detecting the heat using a temperature sensor and graph it and sends both %passengers numbers and the temperature graph to the train station

configurePin(a, 'D2', 'pullup'); %in future releases use configurePin

time = 200;

e=0;

x=0

while time > 0

button_status = readDigitalPin(a, 'D2'); % equals zero when button is pushed, otherwise equals 1

voltage = readVoltage(a,'A0');%pin depends on where we place it

tempCelcius = (voltage*100)-50; %given in sensor manual

tempF(time) = (tempCelcius*1.8)+32 %known conversion formula

max = 120; %degrees F

writeDigitalPin(a,'D11',1);

rem=mod(e,2);

if tempF(time)>=max

writeDigitalPin(a,'D11',0);

writeDigitalPin(a, 'D9', 1);

playTone(a,'D9',2400,.5)

pause(.5)

writeDigitalPin(a,'D6',1)

playTone(a,'D6',1000,.5)

pause(.5)

writeDigitalPin(a, 'D9', 1);

playTone(a,'D9',2400,.5)

pause(.5)

writeDigitalPin(a,'D6',1)

playTone(a,'D6',1000,.5) %plays "siren"

z='Overheat.m4a'; %This puts the sound file into a variable

[data,freq]=audioread(z); %Loads data from sound file

o=audioplayer(data,freq); %Creates an object to control the playing of the audio file

o.play() %Plays audio file

o.playblocking() %Plays file and waits for it to finish

end

if button_status == 0 && rem==0

e=e+1

msgbox('Welcome Aboard!');

elseif button_status == 0 && rem==1

e=e+1

msgbox('Bienvenido a bordo!');

end

if e==5

writeDigitalPin(a,'D11',0);

if x==0

playTone(a, 'D6', 600, 1);

s='Warning_EF.m4a'; %This puts the sound file into a variable

[data,freq]=audioread(s); %Loads data from sound file

o=audioplayer(data,freq); %Creates an object to control the playing of the audio file

% o.play() %Plays audio file

o.playblocking() %Plays file and waits for it to finish

msgbox('Max Capacity')

x=x+1

end

elseif e>=6

playTone(a, 'D6', 2400, 0);

end

time = time - 1;

% pause(0.1);

% if e==5 && max(tempF)>=120

% time=0

% end

end

ee=num2str(e)

t=[1:200];

tempF2=fliplr(tempF);

plot(t,tempF2);

title('Time vs. Temperature')

ylabel('Temperature(F)')

xlabel('Time(s)')

saveas(gcf,'tempplot.jpg')

mail= 'sara.enani@gmail.com'

password='Srsora123#'

host='smtp.gmail.com'

setpref('Internet','SMTP_Server',host);

setpref('Internet','E_mail',mail);

setpref('Internet','SMTP_Username',mail);

setpref('Internet','SMTP_Password',password);

props = java.lang.System.getProperties;

props.setProperty('mail.smtp.auth','true');

props.setProperty('mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory');

props.setProperty('mail.smtp.socketFactory.port','465');

sendmail(mail,'Hello Train Station! There are this many passengers in the train',ee,'tempplot.jpg')

Step 5: Results