Rick and Morty Portal Gun (Arduino and 3D Printer Project)

12K6033

Intro: Rick and Morty Portal Gun (Arduino and 3D Printer Project)

Welcome to my first big 3D print project!

Sneak Peak of end result!

This Instructables will explain all the steps you will need to flow to build yourself a working portal gun like Ricks! for roughly £35!

Hope you enjoy & lets begin!

STEP 1: Project Proposal

As a massive Rick and Morty fan I really want a Portal Gun of my own, having looked about the current existing projects I thought I could add some extra features!

Key Goals

Have a Working (Visually anyway, still a ways of a real portal gun) Ricks Portal Gun this will include,

  1. Working 4 Digit Seven Segment Display in Red
  2. The display must be able to cycle through infinite dimensions and the key ones from the show!
  3. Must be able to fire the portal gun causing front panel to light up indicating portal generation!
  4. Portal Tube must be lit
  5. Needs a self destruct button hidden in the handle!
  6. Some way of charging the gun without disabling the device
  7. Must look like the portal gun!

I've planned out a simple system flow diagram for how I think the device should work

STEP 2: BOM

Lets discuss the the electronics and materials required for this project, to achieve the proposed system flow diagram the following components will be required.

The estimated cost of this projects components would be £35.17 to buy all the parts out right,

The cost of all the components used in one of these projects would be approximately £24.77

*Note that this does not include the cost of the 3D printer material used!

BOM

Arduino Nano V3 - £3.60

4 Bits TM1637 Digital Tube LED Display Module - £0.99

Rotary Encoder Module KY-040 - £1.56

Momentary Tactile Push Button - £1.25

PCB Slide Switch DPDT On-Off-On - £8.14 **** (This part is not only option any Vertical Slide On - Off Switch could be used)

TP4056 Lithium Battery Charging Module - £2.40

180Ω & 1kΩ Resistors (Just buy a set of resistors) - £5.66

Green 10mm Diffused LEDs - £1.69

3.7V 1600mAh Lipo Li-polymer Rechargeable Battery - £7.50

M3 8mm Countersunk Screws - £1.39

3D Parts

If you don't want to paint your parts you will want to get some White & Black PLA to print all the required model parts.

For this project I used,

Flashforge® PLA 3D Printing Filament 1.75mm 1KG White - £17.00

AMZ3D 1.75mm Black PLA 3D Printer Filament - 1kg Spool - £16.99

of course the other option is to print the parts in any materials you currently have and then post process the parts

STEP 3: 3D Printed Parts

The 3D print models can all be found on Thingiverse here - https://www.thingiverse.com/thing:2935246

To design this model I used Fusion 360, I tried to find as many screen shots of the gun from the show as possible and tried to recreate the gun with consideration for all of the electronics.

The parts have all been designed with a 0.4mm tolerance to compensate for any 3D print inaccuracies (This is based on my experience with my printer)

Note* You may still want to file back some of the joins e.g the LED cutouts.

The parts are named with the colour they need to be printed in,

  • 'B_' = Black Part
  • 'W_' = White Part

The only 2 parts that require supports are the

  1. W_HiddenDoor_v4.stl
  2. W_Handle2 SinglePartSecretDoor.stl

All other parts do not require supports or rafts.

For the portal gun tube I have used a Bubble Sword toy which had a diameter of roughly 27mm this is what the current 3D model has been designed for. If you have issues finding a similar part I can modify the .stl if you let me know what you need it changed to!

STEP 4: Electronics

Now time to put together the circuit diagram!

I've used Fritzing to plan the circuit diagram which is a really awesome free bit of software for these types of project.

The setup shown in the attached image will allow for the Arduino to control the TM1637 Display and update it when the user inputs on either the Rotary Encoder Module or the Momentary Tactile Push Button.

The battery is connected through the TP4056 which allows for Micro USB charging, this then connects to the MT3608 which stets up the 3v7 to 5v for the Arduino Nano Vin. The Latching slide switch is connected through this 5v connection to use as an On/Off switch. While in this configuration the battery can still be charged while the device is powered down.

The 2 LEDs for the tube are always powered up & the 3 LEDs for the front panel are connected to a Do pin of the Arduino so they can be triggered when the Rotary Encoder is pressed.

STEP 5: Code

The code for this project was pretty simple,

For this code to work you will need the attached library 'TM1637-1.1.0.zip'

This is far from an optimal code but it seems to work for me!

(Code shown below but it would be better to download the .ino rather than copy and paste)

#include "SevenSegmentTM1637.h" </p><p>const int clkPin= 6; //the clk attach to pin 2<br />const int dtPin= 5; //the dt pin attach to pin 3<br />const int swPin= 4 ;//the sw pin attach to pin 4<br />const int LEDPin= 12;<br />const int selfDest= 10;<br /> <br />const byte PIN_CLK = 8; // define CLK pin (any digital pin)<br />const byte PIN_DIO = 7; // define DIO pin (any digital pin)</p><p>int encoderVal = 0;<br />int oldState = 0;<br /> <br />SevenSegmentTM1637 display(PIN_CLK, PIN_DIO);</p><p>void setup() <br />{<br /> display.begin(); // init the display<br /> display.setBacklight(20); // set the brightness of the display to 20 %<br /> Serial.begin(9600);<br /> display.clear();<br /> display.print("HOLA");<br /> <br /> pinMode(clkPin, INPUT);<br /> pinMode(dtPin, INPUT);<br /> pinMode(swPin, INPUT);<br /> pinMode(selfDest, INPUT);<br /> pinMode(LEDPin, OUTPUT);<br /> digitalWrite(swPin, HIGH);<br /> digitalWrite(LEDPin, LOW);<br /> <br /> delay(1000); <br /> <br /> display.clear();<br /> display.print("C137");</p><p>}</p><p>void loop() <br />{<br /> int change = getEncoderTurn();;<br /> encoderVal = encoderVal + change;<br /> bool buttonPress = 0;<br /> bool sdPress = 0;<br /> <br /> <br /> if(digitalRead(swPin) == LOW)//if button pull down<br /> {<br /> encoderVal = 0;<br /> buttonPress = 1;<br /> Serial.println("Switch Pin");<br /> Serial.println(swPin);<br /> }</p><p> if(digitalRead(selfDest) == HIGH)//if button pull down<br /> {<br /> encoderVal = 0;<br /> sdPress = 1;<br /> Serial.println("Self Destruct Pin");<br /> Serial.println(selfDest);<br /> }</p><p> if (buttonPress == 1)<br /> {<br /> display.clear();<br /> display.print("FIRE");<br /> digitalWrite(LEDPin, HIGH);<br /> delay(1000);<br /> digitalWrite(LEDPin, LOW);<br /> buttonPress = 0;<br /> display.clear();<br /> display.print("C137");<br /> }</p><p> if (sdPress == 1)<br /> {<br /> digitalWrite(LEDPin, HIGH);<br /> display.clear();<br /> display.print(" S");<br /> delay(150);</p><p> display.print(" SE");<br /> delay(150);</p><p> display.print(" SEL");<br /> delay(150);</p><p> display.print("SELF");<br /> delay(150);</p><p> display.print("ELF ");<br /> delay(150);</p><p> display.print("LF D");<br /> delay(150);</p><p> display.print("F DE");<br /> delay(150);</p><p> display.print(" DES");<br /> delay(150);</p><p> display.print("DESR");<br /> delay(150);</p><p> display.print("ESRU");<br /> delay(150);</p><p> display.print("SRUC");<br /> delay(150);</p><p> display.print("RUCT");<br /> delay(450);</p><p> display.clear();<br /> delay(100);</p><p> display.print("....");<br /> delay(200);</p><p> display.print("...3");<br /> delay(200);</p><p> display.print("..3.");<br /> delay(200);<br /> <br /> display.print(".3..");<br /> delay(200);</p><p> display.print("3...");<br /> delay(200);</p><p> display.print("....");<br /> delay(200);</p><p> display.print("...2");<br /> delay(200);</p><p> display.print("..2.");<br /> delay(200);<br /> <br /> display.print(".2..");<br /> delay(200);</p><p> display.print("2...");<br /> delay(200);</p><p> display.print("....");<br /> delay(200);</p><p> display.print("...1");<br /> delay(200);</p><p> display.print("..1.");<br /> delay(200);<br /> <br /> display.print(".1..");<br /> delay(200);</p><p> display.print("1...");<br /> delay(600);</p><p> display.print(" X X");<br /> delay(350);</p><p> display.print("X X ");<br /> delay(350);</p><p> display.print(" X X");<br /> delay(350);</p><p> display.print("X X ");<br /> delay(350);<br /> <br /> <br /> delay(1000);<br /> digitalWrite(LEDPin, LOW);<br /> sdPress = 0;<br /> display.clear();<br /> delay(1000);<br /> display.print("C137");<br /> }</p><p> if (encoderVal == 0 && (change == 1 || change == -1))<br /> {<br /> D1();<br /> }</p><p> if (encoderVal == 1 && (change == 1 || change == -1))<br /> {<br /> D2();<br /> }</p><p> if (encoderVal == -1 && (change == 1 || change == -1))<br /> {<br /> D3();<br /> }</p><p> if (encoderVal == 2 && (change == 1 || change == -1))<br /> {<br /> D4();<br /> }<br /> if (encoderVal == -2 && (change == 1 || change == -1))<br /> {<br /> D5();<br /> }<br /> if (encoderVal == 3 && (change == 1 || change == -1))<br /> {<br /> D6();<br /> }<br /> if (encoderVal == -3 && (change == 1 || change == -1))<br /> {<br /> D7();<br /> }<br /> if (encoderVal == 4 && (change == 1 || change == -1))<br /> {<br /> D8();<br /> }<br /> if (encoderVal == -4 && (change == 1 || change == -1))<br /> {<br /> D9();<br /> }<br /> if ((encoderVal >= 5 || encoderVal <= -5) && (change == 1 || change == -1))<br /> {<br /> DPos();<br /> }<br />}</p><p> </p><p>int getEncoderTurn(void)<br />{<br /> static int oldA = HIGH; //set the oldA as HIGH<br /> static int oldB = HIGH; //set the oldB as HIGH<br /> int result = 0;<br /> int newA = digitalRead(clkPin);//read the value of clkPin to newA<br /> int newB = digitalRead(dtPin);//read the value of dtPin to newB<br /> if (newA != oldA || newB != oldB) //if the value of clkPin or the dtPin has changed<br /> {<br /> // something has changed<br /> if (oldA == HIGH && newA == LOW)<br /> {<br /> result = (oldB * 2 - 1);<br /> }<br /> }<br />oldA = newA;<br />oldB = newB;<br />return result;<br />}</p><p>void D1()<br />{<br /> display.clear();<br /> display.print("C137");<br /> oldState = 11;<br />}</p><p>void D2()<br />{<br /> display.clear();<br /> display.print("C500");<br /> oldState = 12;<br />}</p><p>void D3()<br />{<br /> display.clear();<br /> display.print("J19");<br /> oldState = 13;<br />}</p><p>void D4()<br />{<br /> display.clear();<br /> display.print("C239");<br /> oldState = 16;<br />}</p><p>void D5()<br />{<br /> display.clear();<br /> display.print("C132");<br /> oldState = 17;<br />}</p><p>void D6()<br />{<br /> display.clear();<br /> display.print("C499");<br /> oldState = 18;<br />}</p><p>void D7()<br />{<br /> display.clear();<br /> display.print("C726");<br /> oldState = 19;<br />}</p><p>void D8()<br />{<br /> display.clear();<br /> display.print("J19A");<br /> oldState = 20;<br />}</p><p>void D9()<br />{<br /> display.clear();<br /> display.print("35-C");<br /> oldState = 21;<br />}</p><p>void DPos()<br />{<br /> char rndChar[4];<br /> int tempN = random(10, 999);<br /> int tempC = random(1, 26);<br /> int rndC = 0;<br /> <br /> rndC = tempC + 97;<br /> sprintf(rndChar, "%c%d", rndC, tempN);<br /> Serial.println(rndChar);</p><p> display.clear();<br /> display.print(rndChar);<br /> oldState = 22;<br /> <br />}</p><p>

STEP 6: Assembly

Once I assembled and tested the electronics it was time to put together the entire gun!

I used a small pin to hold the secret hinge door, a header / small bit of wire / paper clip should work as well.

Once assembled its time to test it out!

Final Test

STEP 7: Conclusion

I'm really happy with how this project came out and hope you guys enjoyed,

If you get around to making your own please send me photos, I would love to see how it worked out for everyone!

If you have any questions or issues please comment and I will try to help as best I can

Future Work

  1. I plan to add audio to the device soon using a ISD1820 chip and a small speaker, this will play the audio bite and I may also find a self destruct noise
  2. Maybe an Evil Rick Portal Gun Variant?!

24 Comments

Does this thing actually spur out portals and take you to other universes

Greetings from Los Alamos, New Mexico, USA. I made 2 of these as a demo for our makerspace! The first one was completely constructed, but the second one was deconstructed and had parts everywhere. I added a couple of UV leds under the green tube, and made a plasma ball with some hot glue! The glue lights up pretty good with the UV bulbs.

Thanks Jack, for this projcet!!! This was the first thing I soldered in my life, I might have never learned with out this project!

What ever you do with this portal gun, stay out of the Citadel.

-J

dont suppose you can upload a clear instructions on how to wire it up if your using an arduino nano.

Hi Jonathan, Awesome job and great idea with the UV lights they look great, I've ordered some to try out myself and some UV Reactive Green PLA samples for the plasma ball in the tube! Thanks for sharing your build and I'm glad you enjoyed it!

Jack

hi im having trouble getting the unit to light up ive tried following your wire diagram but having trouble as i cant see the letters ect on the arduino and it seems the positive and neg wires are back to front on the batt charg unit in the pics , ive bought the exact parts you have listed and i have rewired twice and still no luck.
Hey i really like this idea but the problem is i dont have a 3D printer but i am planning to buy it. do you think i could make this out of cardboard en popsticle sticks?
Hey Kyan, don't see why not! Be sure to upload photos if you manage it :)
I got the programming figured out.. lots of issues there to start... now the diagram for the Arduino board has lines goes to holes that are counted for... some of the lines are just jumbled around and connect to several different things maybe? Can you clear up how to wire everything? Perhaps using the NAMES ON THE BOARD example GND for ground (which on the v3 nano there are two of btw) or D3/D4/D5, those are some of the names of the pin locations on the board itself. If you just say pin 3... well there isnt a pin 3 labeled on the board. There is D3 AND A3 on this board. I mean great work overall, really love the design and thought that went into this but the follow-through for "Instructables" is failing.
I give up. None of the wires on the diagram are accurate enough to understand. Pro Tip, MS Paint is not the way to set up your wiring display. Wasted $100 on this. Decent print but horrible design notes. Crazy part is, I rewired Apache Attack Helicopters in the Army for 6 years... that's how bad this example provided is.
Hi, not totally sure what
your issue is, if you could detail your circuit setup and HW config maybe we
can debug the issue.

Can you confirm you are using the same display module (TM1637)?

The Pin map is poor but I did not spend much time on that as
its redundant after you look at the pin definitions in the code I provided.

Below I've detailed the
display pins, once these are connected you just need to provide the TM1637 with
PWR & GND. The diagram is redundant again as there are many different
variants of this display module with different ordered pin outs. If the pins
below are not appropriate for you setup, you can just redefine them.

const byte PIN_CLK
= 8; // define CLK pin (any digital pin) ** Pin D8

const byte PIN_DIO
= 7; // define DIO pin (any digital pin) ** Pin D7

I'm not sure what level of electronic knowledge you have but
if you are capable of reading a part DS & solder I would assume you could
resolve this issue quite easily (Especially if you have worked on military
grade systems...)

I would recommend validating
that the display works using the examples in the provided library before
attempting the full system code.

Unless you provide more detailed explanations for the issues
you are having I cannot help further.

Also the software used to make the circuit diagram is called Fritzing( http://fritzing.org/download/). This is a common bit of software used on this site due to its focus on hobbiest electronics and the facts it free. I could have used LTSpice or Altium to model this but that would have been a tad over kill :)

I went with a different board, got the program uploaded to the Trinket Pro. Guessed at how to alter the code, you're much better at it than I am. Changed the pins code around to match the Trinket, rotary encoder when rotated just fires and turns on the lights. Working on the code again to find out why when I turn the knob (to change the led) it just says FIRE over and over again like the SW button is being pushed. Once I have everything figured out and running would you mind if I added images of how I wired everything to the Pro Trinket?

NEVERMIND! Its cause I'm stupid. Didn't have the + hooked up on the encoder! Gonna put it all together now and finally get some screws in on this bad boy. Took 2 weeks but hey... worth

I got a 7 segment display which has 8 pins. How do I wire that to the arduino?

Hi, is it a 4 bit 7 segment display? you will need to follow another guide of how to configure it like this one to get there working https://create.arduino.cc/projecthub/SAnwandter1/programming-4-digit-7-segment-led-display-2d33f8

The issue with doing this is that my code will not work, you would need to rewrite the display sections.

I would advice either buying a cheap TM1637 IC and find a guide on setting that up or the better option would be to buy a TM1637 4 bit 7 segment display module like I used otherwise the wiring can get messy!


The TM1637 is ac IC that handles the 4 digit 7 segment display connctions, so that TM1637 chip connects to the 8 pins on the display itself. The chip drives the LEDs in the display based on simple I2C commands it recieves from the Arduino.

This means that the Arduino only need to use 2 pins Rx and Tx instead of the 8 pins that the LCD Display needs. Also now that we are just sending standard I2C signals it makes it much easier to programme everything.

Using modules like this is always easier especially when using a small microcontroller like an Arduino Nano, as it has very limited I/O.

Wonder if a persistance of vision display could be used to create a portal effect infront of it...

Hey, that is a possible solution I think although I don't know how bright this method would be. I'm quite interested in how the Funko Toy Ricks Portal Gun does it (seen here https://youtu.be/9eXw0bzWeRw?t=123). I think its just a High power LED behind a lens with the portal image on it which would be nice and simple. I'd be tempted to buy one to see how they did it if they were on sale.

Will this work even if I am not a rick ?

Can confirm that yes it does work if you are not Rick!

Unfortunately the real portals only work for Rick :)

More Comments