Stop in the Name of Science

Introduction: Stop in the Name of Science

Our goal was to develop something that would enhance the EF train system. We created a gate that would prevent cars from driving onto the track before a train passes, keeping them from being hit.

Step 1: Step 1: Wiring

First we had to figure out our circuitry. All of our schematics were derived from the booklet that came along with the provided raspberry pi, following the wiring for LED lights, motion detectors, and timers.

Step 2: Step 2: Construction

Next we 3-D printed and constructed the arms themselves. The "railway cross" and the housing for the LED lights were 3-D printed, and the arms, base and stem were made out of small pieces of wood. All of our pieces were taped or glued together, and then finally the arms was attached to a provided servo.

Step 3: Step 3: Coding

The following is the code for our project. We used our knowledge from EF 230, suggestions from the booklet, and code found the research in order to get the motion detector working, and then using that data to activate the gate.

function main()
clear all; close all; format compact; clc; display('Default delay for re-raising gates is set to 10 seconds.'); display('To change this, modify ''gate_delay'' variable.'); display('See details in annotation below.'); display('Note: To disable program and reset, press CTRL-C, manually'); display('reset gates, change variable, and start program again'); pause(5); gates_state = 0; % 0 for open; 1 for closed; % lights_state = 0; ALARM = 21; % input pin from PIR Motion Sensor

mypi = raspi('','pi','raspberry') s = servo(mypi,18,'MinPulseDuration',5e-4,'MaxPulseDuration',2.5e-3);

gate_delay = 10; % value in seconds; gives how many seconds that no motion % has been detected before raising the gates counter = 0;

while true % clc; % tic % used for timing loop cycle; goes with 'toc' below pin_state = readDigitalPin(mypi,ALARM); % 1 means no motion % 0 means motion % pin_state = 0; % used for testing loop cycle time pause(0.1);

if pin_state == 0 display('MOTION!!!'); display('LOWER GATES!!!'); writeDigitalPin(mypi,17,1) display('Started blinking!'); counter = 0; lower_gates(s,gates_state); gates_state = 1; pause(1); else counter = counter + 1; pause(1); end

if counter == double(int8(gate_delay./1.1343)) display('NO MOTION!!!'); display('RAISE GATES!!!'); writeDigitalPin(mypi,17,0); counter = 0; raise_gates(s,gates_state); gates_state = 0; pause(1) end % x = toc % used for timing loop cycle; used with 'tic' above % break % used for timing loop cycle with 'tic' and 'toc'

end end % main

function lower_gates(s,gates_state)

if gates_state == 0 for i = 20:0.5:90 writePosition(s,90-i) end gates_state = 1; end

end % lower_gates

function raise_gates(s,gates_state)

if gates_state == 1 for i = 20:0.5:90 writePosition(s,i) end gates_state = 0; end

end % raise_gates

% function flash_lights(lights_state) % % warning_lamps = 21; % % while true % writeDigitalPin(mypi,warning_lamps,1); % pause(0.5); % writeDigitalPin(mypi,warning_lamps,0); % pause(0.5); % end % % end % flash_lights

Step 4: Step 4: Put It Together

Finally, place the apparatus around the track so that there are gates on each side of the tracks in order to prevent cars on both sides from trying to cross in front of a train. Once everything is set up, run the train and lower the gates.

Be the First to Share


    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Big and Small Contest

      Big and Small Contest
    • For the Home Contest

      For the Home Contest


    DIY Hacks and How Tos

    Fun system. It makes me want to build some electronics for my kids' playsets