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 Preparation Before we start, let me give you the best advice I received when I started developing on a Raspberry Pi: ! You can find them on adafruit ( , ) 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 and boom you’re in. get yourself a USB to TTL serial cable link tutorial screen 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 ( ). I’m in no way affiliated with the company, but they posted all the C and Python code to control them on so I think they’re pretty cool. link github 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 as a dependency in our file: elixir_ale mix.exs 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 . So let’s install and compile: here $ 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 , 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 and the laser will start blinking. How cool is that? Gpio.start_link iex -S mix Also note that the default behaviour is to write for turning something on and for turning it off. To make the code easier to understand I just added the and helpers. 0 1 turn_on turn_off Here’s a picture of the setup on my desk: Read more Now that we have the laser blinking, go to the to learn how to add sensors for noise, temperature, and vibration detection. Erlang Solutions blog 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 .