Hackernoon logoRebuilding the Mission Impossible security system in Elixir on RaspberryPi by@ErlangSolutions

Rebuilding the Mission Impossible security system in Elixir on RaspberryPi

Erlang Solutions Hacker Noon profile picture

@ErlangSolutionsErlang Solutions

Information Technology and Services

by Ju Liu

Rebuilding the Mission Impossible security system in Elixir on RaspberryPi

Yes, you’ve read that right. In this tutorial we are going to rebuild the amazing security system featured in the 1996 all time classic Mission Impossible. We will use a Raspberry Pi, lots of sensors and we’ll write the code in Elixir.

Just a quick refresher for those who haven’t seen the movie. Ethan Hunt is a super spy trying to infiltrate the CIA headquarters in order to steal a valuable list of double-agents. Unfortunately, the list is safely stored in a highly secure bunker with the following security mechanisms:

  • Laser beams
  • Temperature sensors
  • Noise sensors
  • Ground vibration sensors


Before we start, let me give you the best advice I received when I started developing on a Raspberry Pi: get yourself a USB to TTL serial cable! You can find them on adafruit (link, tutorial) and these little devices will save you the trouble of having to connect an external monitor, a keyboard and a mouse in order to use your Raspberry. Just connect the cable, fire up screen and boom you’re in.

Now we need some sensors to build our security system, and I’ve found a set made by Sunfounder that has everything that we need and even more (link). I’m in no way affiliated with the company, but they posted all the C and Python code to control them on github so I think they’re pretty cool.

The last thing we need is Elixir! We can install it on our Raspberry Pi following this tutorial.

Let’s get started

We can now create the project using our beloved mix:

$ mix new intrusion_countermeasures

and add elixir_ale as a dependency in our mix.exs file:

defmodule IntrusionCountermeasures.Mixfile do use Mix.Project def project do [app: :intrusion_countermeasures, version: "0.1.0", elixir: "~> 1.4", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, deps: deps()] end def application do [extra_applications: [:logger], mod: {IntrusionCountermeasures, []}] end defp deps do [{:elixir_ale, "~> 0.5.6"}] end end

This library will provide us the abstractions for controlling the Raspberry GPIO pins and I2C bus. You can find out more about the library here. So let’s install and compile:

$ mix deps.get && mix compile

First things first: a laser!

Grab your laser emitter module and connect it to the breadboard in this way:

Now we can start writing the code for our security system:

defmodule IntrusionCountermeasures do use Application def start(_, _) do {:ok, laser} = Gpio.start_link(17, :output) pid = spawn(fn -> loop(laser) end) {:ok, pid} end def loop(laser) do :timer.sleep(200) turn_on(laser) :timer.sleep(200) turn_off(laser) loop(laser) end defp turn_on(pid) do Gpio.write(pid, 0) end defp turn_off(pid) do Gpio.write(pid, 1) end end

We connect the GPIO pin 17 using Gpio.start_link, specifying we’re using it as an output. Then we spawn a recursive loop function which repeatedly turns the laser on and off. We can run our app with iex -S mix and the laser will start blinking. How cool is that?

Also note that the default behaviour is to write 0 for turning something on and 1 for turning it off. To make the code easier to understand I just added the turn_on and turn_off helpers.

Here’s a picture of the setup on my desk:

Read more

Now that we have the laser blinking, go to the Erlang Solutions blog to learn how to add sensors for noise, temperature, and vibration detection.

Learn more about how Erlang Solutions can support you with Elixir Development or sign up to our mailing list to be the first to know about our future blog posts.

Originally published at www.erlang-solutions.com.


Join Hacker Noon

Create your free account to unlock your custom reading experience.