Introduction: Arduino Animation

In this instructable I will show you how you can make a real life animation with Arduino and little perspex plates. The idea is that if you illuminate the plates from beneath you can see the engraving light up. If you loop the lights under the plates, you will see an animation. Much like a zoetrope. Only this one doesn't spin and the plates are placed directly behind each other. When you get closer to the animation, because of the ultrasonic sensor, the animation will play faster. When you are further away it will play slower.

This is what you need:

  • Arduino UNO
  • Power cable for the arduino
  • Breadboard
  • HC-SR04 Ultrasonic sensor
  • LED 5mm (any colour you want) X32
  • Resistor 220Ω X8
  • Jumper wire X15
  • Perspex / plexiglass plates (5 cm x 7 cm) X8
  • Dremel engraver (Or some way to engrave the plates)
  • Laptop to run arduino software
  • Cardboard, wood etc (to build the casing)

Step 1: Step 1: Arduino Setup

What you want to do first is connect the breadboard to your arduino. This is done by connecting the 5V pin on your arduino with a jumperwire to the + side on your breadboard and connecting ground (GND) with a jumperwire to the - side of your breadboard.

Next step is adding the LEDs, you want to place 4 LEDS in serie, this make sure you have enough light intensity to illuminate your plates. You need to do this 8 times.

  • You want to connect the longer pins of your LED, which is de +, with a jumper wire to the output pins of the arduino (11-4).
  • You need to connect the shorter pin of the LED, which is the -, with a res to the - side of the arduino.

You need to do those steps 8 times because there are 8 frames you want to illuminate. See the Scheme.

Next you want to connect the ultrasonic sensor:

  • Connect the GND pin of the sensor to the - side of the breadboard.
  • Connect the VCC pin of the sensor to the + side of the breadboard.
  • Connect the Trig pin of the sensor to the 13th output pin of the arduino.
  • Connect the Echo pin of the sensor to the 12th output pin of the arduino.

Step 2: Code

This is the code, the comments will explain what the different lines of code mean and what they do.

* trigger pin of the sonic sensor. */ const int trigPin = 13;

/* * echo pin of the sonic sensor. */ const int echoPin = 12;

/* * pins of all leds in the loop. */ const int leds[] = {4, 5, 6, 7, 8, 9, 10, 11};

/* * This variable stores the size of the leds array. It is stored in a separate variable since * the (byte) size of the leds array must always be divided by the (byte) size of an integer. * THis is because sizeof(variable) returns the amount of BYTES in memory, not the amount of * variables in the array. * Ergo: this variable is here for code cleanliness. */ const int ledAmount = sizeof(leds) / sizeof(int);

/* * This variable stores the current index of the current pin in the leds array. */ int currentPin = 0;

/* * */ void setup() { pinMode(trigPin, OUTPUT); // Sets the trigPin as output. pinMode(echoPin, INPUT); // Sets the echoPin as input. for (int c = 0; c < ledAmount; c += 1) { // c counts from 0 to ledAmount (the amount of leds). pinMode(leds[c], OUTPUT); } }

/* * Sets up the loop, makes sure it gets repeated. */ void loop() { long distance = measureDistance(); // Sets the variable distance equal to measureDistance. if (distance < 200) { // The statement is true for a distance smaller than 200 cm. digitalWrite(leds[currentPin], HIGH); // Sets the voltage of the current pin to high, the LED is on. delay(distance * 10); // Time between on and off is the distance that the sensor measures x 10. digitalWrite(leds[currentPin], LOW); // Sets the voltage of the current pin to low, the LED is off. currentPin += 1; // currentPin counts from 0 up. if (currentPin >= ledAmount) { // If currentPin amount is more than the amount of leds present it sets currentPin = 0; // the currenPin back to 0. } } else { // If the distance is bigger than 200 cm. for (int c = 0; c < ledAmount; c++) { // c counts from 0 to ledAmount (the amount of leds). c++ is the same as c+=1 digitalWrite(leds[c], LOW); // Sets the voltage of the LEDs to low, the LEDs are off. } } }

long measureDistance() { // Sets the variable measureDistance. long duration, distance; // Sets the variables duration and distance within measureDistance. digitalWrite(trigPin, LOW); // Erases the TrigPin. delayMicroseconds(2); digitalWrite(trigPin, HIGH); // Sets TrigPin on a high voltage. delayMicroseconds(10); digitalWrite(trigPin, LOW); // Sets TrigPin on a low voltage. duration = pulseIn(echoPin, HIGH); distance = (duration / 2) / 29.1; return distance; // Returns distance. }

Step 3: Animation

You need to make an 8 frame animation, which is endless, meaning you can loop it without it having an end.

I choose to make an 8 frame walking animation.

Step 4: Plates / Frames

You will need 8 plates or frames that are:

  • 5 cm wide
  • 7 cm long
  • See through
  • 3 mm thick
  • Have polished sides
  • Made of plexiglass, perspex or another type of plastic

Next you have to engrave the animation that you have made in the plates. You can do this with a dremel engraver. You can also let someone else do it, like a company for example, however engraving it with the hand gives a better effect than engraving it with a laser. This is because laser engraving is very undeep, the illuminating effect will be a lot less.

Step 5: Casing

You can make the casing from any material that you like. I choose to make it with cardboard because this was in my case the easiest way.

In the picture you can see the sketches. You need to make slids/holes for the plates to go in, so they need to be a little bit less than 5cm long and a little bit less than 3mm wide. Because of making it a little bit less than exactly 5cm and 3mm you have to push the plates in, and they won't directly fall through it. You need to measure how much space there is in between you leds, and this is the space that goes between the slids/holes. The slids/holes go on top of the leds, so that they can directly illuminate the bottom of the plates.

First Time Author Contest 2018

Participated in the
First Time Author Contest 2018