Introduction: LifeGuard 2.0

Picture of LifeGuard 2.0

Have you ever wanted to perform math operations, take sensor readings, monitor analog and digital inputs, and control analog and digital outputs with no previous electronics experience? If yes, this project is just for you! We will be using a microcontroller and MATLAB to create a device that can be used to monitor and enhance the EF Express SMART RAIL system. With a microcontroller, the possibilities for inputs and outputs (signal/information going into the board and a signal exiting the board) are endless. We will be using a flex sensor and potentiometer as our inputs. Their outputs will be a message via LCD screen and LED lights along with a buzzer, respectively. The enhancements we hope to implement into the SMART RAIL system are relative to improving system safety. Grab your laptop and microcontroller, and let us begin!

Step 1: Software and Materials

Picture of Software and Materials

Software needed:

1.) MATLAB

- You will need to download a local version of MATLAB on your computer. Go to mathworks.com and set up a MATHWORKS account, download files, and activate your license.

-You should download and install ALL available toolboxes for the newest release (R2016a or R2016b).

-Mac users: you must have OSX 10.9.5 or later to run R2015b, it is OK to run an earlier version of MATLAB.

2.) Arduino Hardware Support Package:

-Install the Arduino Hardware Support Package. Open MATLAB. On the MATLAB Home tab, in the Environment Menu, select Add-Ons --> Get Hardware Support Packages Select the "MATLAB Support Package for Arduino Hardware". You will need to login to your MATHWORKS account

-If your installation gets interrupted and you have successive failed attempts/errors when installing the hardware package - find and delete the folder Arduino download on your hard drive and start from the beginning.

Materials needed:

1.)Laptop or desktop computer

2.) SparkFun Arduino Board

3.) Flex Sensor

4.) Potentiometer

5.) LCD screen

6.)LED light

7.) SparkFun Inventor's Kit (Find online)

8.) USB cable and mini USB

9.) Jumper wires

10.) Piezo buzzer

Step 2: Connect to Your Arduino and Determine the COM Port

(Your COM port may change each time you plugin)
Connect the Arduino USB cable to your computer and the mini USB to your Arduino board. You may need to wait a few minutes for the drivers to download.

To determine the COM port:

On PC:

Method 1: In MATLAB use the command - fopen(serial('nada'))

-to determine your com port. You may get an error like this: Error using serial/fopen (line 72)
Open failed: Port: NADA is not available. Available ports: COM3. This error indicates that your port is 3.

-If Method 1 fails on your PC, open your Device Manager and expand the Ports (COM and LPT) list. Note the number on the USB Serial Port. e.g. 'USB Serial Port(COM*)' The port number is the * here.

-If no port is shown, close MATLAB and restart your computer. Open MATLAB and try fopen(serial('nada')) again.

-If this fails, you may need to download SparkFun's drivers from the file CDM_v2.12.00_WHQL_Certified.exe, open and run the CDM_v2.12.00_WHQL_Certified.exe file, and select Extract. (You may need to open the file from explorer, right click, and 'Run as Administrator').

-In the MATLAB command window create an Arduino object - a=arduino('comx','uno'); % x is your port number from above for PCs (no preceding zeros!)

On a Mac:

Method 1: From the MATLAB command line or in a Mac Terminal and type: 'ls /dev/tty.*' Note the port number listed for dev/tty.usbmodem* or dev/tty.usbserial*. The port number is the * here.

-If Method 1 fails on your MAC, you may need to

-Exit MATLAB

-Close the Arduino software and unplug the Arduino USB cable

-install Java 6 Runtime

-install USB driver kernel extension

-Restart your computer

-Reconnect Arduino USB cable

-Run from MATLAB command line or Mac Terminal: ls /dev/tty.*

-Note the port number listed for dev/tty.usbmodem* or dev/tty.usbserial*. The port number is the * here.

-In the MATLAB command window create an Arduino object - a=arduino('/dev/tty.usbserial*','uno'); % * is your port number from above for MACs, or '/dev/tty.usbmodem*'

Step 3: Matlab Code

Picture of Matlab Code

Inputs:

1.) Flex Sensor

2.) Potentiometer

Outputs:

1.) LCD screen with message that reads "Train Coming"

2.) LED light

3.) Piezo buzzer

In this step, we will be constructing the code that will analyze the inputs from the Arduino board and provide outputs based on the results of MATLAB's analysis. The following code will allow you to perform several functions: when the potentiometer is triggered, the piezo buzzer will emit alternating frequencies and the red LED will flash. When a train is not detected, the green LED will be illuminated. When the Flex Sensor is triggered, the greed LED will turn off, the red LED will illuminate, and the LCD will display a message that reads "Train Coming".

MATLAB Code:

%remery1,shornsb1,wmurrin

%Purpose: Train Warning

%IInput:potentiometer, flex sensor

%output:lcd, sound, light

%If board is not initialized or is having connection issues, execute the

%below commands in comments. They do not need to be execute every time

%clear all

%close all

%clc

%a=arduino('/dev/tty.usbserial-DN01DXOM','uno');

%lcd = addon(a,'ExampleLCD/LCDAddon',{'D7','D6','D5','D4','D3','D2'});

%Configure board once it is connected

configurePin(a, 'D8', 'pullup');%configure D8

configurePin(a, 'D9', 'PWM');%configure D9

time=50; %set time to 50

clearLCD(lcd) %initialize LCD

%Start Loop

while time>0

%Flex sensor voltage determines whether light is green, or if light

%is red and LCD displays "train coming"

flex_status = readVoltage(a, 'A0'); %read voltage of flex sensor

if flex_status>4 %if voltage is greater than 4, trigger loop

writeDigitalPin(a,'D12',0) %turn off green

writeDigitalPin(a,'D11',1) %turn on red

printLCD(lcd,'Train Coming') %display "train coming" on LCD

pause(5) %Wait 5 seconds

clearLCD(lcd) %Clear message from LCD

writeDigitalPin(a,'D11',0) %Turn off Red LED

else

end

pe_status = readVoltage(a, 'A2'); %Read potentiometer voltage

if pe_status>2 %if voltage is greater than 2, trigger loop

writeDigitalPin(a,'D13',1);%turn on red LED

playTone(a, 'D9', 400, .25);% Play 400Hz on Piezo buzzer, .25 sec

writeDigitalPin(a,'D13',0)%turn off red LED

pause(.25)%wait .25 seconds

writeDigitalPin(a,'D13',1) %Repeat above, with buzzer at 200Hz

playTone(a, 'D9',200,.25);

writeDigitalPin(a,'D13',0)

pause(.25)

writeDigitalPin(a,'D13',1);%Repeat above

playTone(a, 'D9', 400, .25);

writeDigitalPin(a,'D13',0)

pause(.25)

writeDigitalPin(a,'D13',1)

playTone(a, 'D9',200,.25);

writeDigitalPin(a,'D13',0)

pause(.25)

writeDigitalPin(a,'D13',1) %Repeat above

playTone(a, 'D9', 400, .25);

writeDigitalPin(a,'D13',0)

pause(.25)

writeDigitalPin(a,'D13',1)

playTone(a, 'D9',200,.25);

writeDigitalPin(a,'D13',0)

pause(.25)

writeDigitalPin(a,'D13',1) %Repeat above

playTone(a, 'D9', 400, .25);

writeDigitalPin(a,'D13',0)

pause(.25)

writeDigitalPin(a,'D13',1)

playTone(a, 'D9',200,.25);

writeDigitalPin(a,'D13',0)

pause(.25)

else

writeDigitalPin(a,'D12',1)%if voltage is less than 2, turn on green LED

writeDigitalPin(a,'D13',0)%turn of Red LED

end

end


Step 4: Wiring the Flex Sensor

Picture of Wiring the Flex Sensor

Materials needed:

1.) 1 Flex Sensor

2.) 1 10K Ohm Resistor

3.) 8 Jumper Wires

*Refer to pictures, respectively.

In this circuit, we will be measuring flex. A flex sensor uses carbon on a strip of plastic to act like a variable resistor, but instead of changing the resistance by turning a knob, you change by flexing the component. A voltage divider to detect change in resistance. In our case, will be using the flex sensor to detect a train passing to command a LCD screen (see picture) to read a message saying "Train Coming".

*In the pictures showing the instructions for wiring a Flex Sensor, only refer to the wires relative to wiring the Flex Sensor. Disregard the wiring for the Servo.

Wire pins as follows:

Step 1: On the Arduino board in the POWER section, plug 1 wire into input 5V and 1 wire into input GND (ground). Plug the other end of the 5V wire into a positive (+) input on the circuit board. Plug the other end of the GND wire into a negative (-) input on the circuit board.

Step 2: On the Arduino board in the ANALOG IN section, plug 1 in the A0 input. Plug the end of that wire into the j20 input on the circuit board.

Step 3: On the Arduino board in the DIGITAL I\O section, plug 1 wire into input 9. Plug the other end into input a3.

Step 4: On the circuit board, Plug 1 wire into a positive (+) input. Plug the other end into input h24.

Step 5: On the circuit board, Plug 1 wire into a negative (+) input. Plug the other end into input a2.

Step 6: On the circuit board, Plug 1 wire into a negative (-) input. Plug the other end into input b1.

Step 7: On the circuit board, Plug 1 wire into a negative (-) input. Plug the other end into input i19.

Step 8: On the circuit board, place the resistor in the i20 and i24 inputs.

*The last picture refers to real world applications.

Step 5: Connect Arduino to LCD

Picture of Connect Arduino to LCD

*Follow this link (https://ef.engr.utk.edu/ef230-2017-08/projects/ard...) and then refer to the steps I have provided below to connect a LCD to an Arduino:

Step 1: Open zip file

Step 2: open the ReadMe file and follow the instructions

Materials needed:

1.) 16x2 LCD similar to this device from SparkFun - https://www.sparkfun.com/products/9395

2.) Jumper wires

*Refer to pictures, respectively.

This step will show how to creat an LCD add-on library and display "Train Coming" on an LCD.

Wire pins as follows:

LCD Pin -> Arduino Pin

1 (VSS) -> Ground

2 (VDD) -> 5V

3 (V0) -> Mid pin on Flex Sensor

4 (RS) -> D7

5(R/W) -> Ground

6 (E) -> d6

11 (DB4) - D5 (PWM)

12 (DB5) -> D4

13 (DB6) -> D3 (PWM)

14 (DB7) -> D2

15 (LED+) -> 5 V

16 (LED-) -> Ground

Step 6: Connecting Soft Potentiometer

Picture of Connecting Soft Potentiometer

Materials needed:

1.) 1 LED

2.) 1 Soft Potentiometer

3.) Jumper Wires

4.) 3 330 Ohm Resistor

5.) 10K Ohm Resistor

*Refer to pictures, respectively.

In this circuit, we are going to use another kind of variable resistor, a soft potentiometer. This is a thin and flexible strip that can detect where pressure is being applied. By pressing down on various parts of the strip, you can vary the resistance from 100 to 10 K ohms. You can use this ability to track movement on the potentiometer or as a button. In this circuit, we will get the soft potentiometer up and running to control an RGB LED.

Step 1: On the Arduino board in the DIGITAL I\O section, plug 1 pin into input 10 and 1 pin into input 11. Respectively, plug the other end of those pins into input h6 and h7.

Step 2: On the circuit board, plug the LED into inputs a4, a5, a6, and a7.

Step 3: On the circuit board, place the 3 330 ohm resistors in inputs e4-g4, e6-g6, and e7-g7.

Step 4: On the circuit board, plug 1 pin into input e5. Plug the other end of that pin into a negative (-) input.

Step 5: On the circuit board, place the 10K ohm resistor into inputs i19-negative(-).

Step 6: On the circuit board, plug 1 pin into j18. Plug the other end of that pin into a positive (+) input.

Step 7: On the circuit board, plug 1 pin into input j20. Plug the other end of that pin into a negative (-) input.

Step 7: Test Your Enhancements on a Smart Rail System

Picture of Test Your Enhancements on a Smart Rail System

At this point, your MATLAB code should be functional and the Arduino board should be accurately connected along with all added components. Try it out on a certified Smart Rail System and see if your enhancements make the system safer.

Comments

About This Instructable

807views

16favorites

License:

More by wmurrin:LifeGuard 2.0How to Transform a Roomba Bot Into a LifeGuard
Add instructable to: