Arduino Basics: Animation
Showing posts with label Animation. Show all posts
Showing posts with label Animation. Show all posts

9 November 2018

Digital Rain Cloud

 
 

Description

This is a very simple project that turns a Rainbow Cube Kit from Seeedstudio, into a digital rain cloud. It features a relaxing rain animation which is ruined by a not-so-relaxing yet somewhat realistic lightning effect. The animation has a very random pattern, and is quite satisfying to watch. The strategically placed cotton wool on the top of the cube makes all the difference to the project, and is sure to impress all of your friends. Luckily, I have done all of the hard work for you. You will find the full source code for the animation sequence below. You just have to provide the Rainbow Cube Kit and the cotton wool. Have fun !!

 
 

24 April 2016

Arduino Stroboscope Animation





UPDATE: Magzor has just started a Kickstarter campaign. Please check it out to get a good package deal on many of their components. Many of which were used in this tutorial.
 
This tutorial will show you how to build your own Stroboscopic Animator using Magzor's Mechanotronic Design Portal as a starting point. Magzor Corporation is a business in California that is trying really hard to simplify robotic design. They want to enable users with little to no engineering experience to design and manufacture a custom robot by themselves in a matter of hours.
What is a stroboscope? A stroboscope is an instrument that uses a strobe light to make a moving object look stationary… We will use this feature to create an interesting 4 picture animation on a rotating disk.

 

 
Have a look at the video below to see the project in action, and the MDP process walk-through:


 

Video




 
 

Parts Required:





 

Magzor Schematic Diagram

Click to zoom ...

 
Further build instructions can be obtained by selecting the components in the Mechanotronics Design Portal within the Magzor website. Generating the build, and then selecting "Setup Instructions" tab at the top of the page. See video above to see this process in action.
 
 

Arduino Sketch


Make sure to copy and paste the following code into your Arduino IDE. It doesn't seem to work directly from the browser. You also need to install the Arduino Magzor I2C library ( http://magzor.com/downloads/ )



 

Putting it together


 
Arduino MEGA


 
Magzor I2C board


 
MIC Boards


 
MIC Boards Assembled


 
Sensors, Modules and Shields - all put together


 
Motor with Bracket and Wire


 
Picture lined up with magnet on disk


 

Stroboscopic Animation



 


 


The Arduino MEGA microcontroller listens for the hall effect sensor to be triggered by the south facing side of the magnet on the underside of the rotating disk. As the magnet moves over the hall effect sensor, the sensor is triggered and the Arduino instructs the LED to blink for a fraction of a second. By manipulating the delay after the trigger time, we can get the LED to blink when one of the four images on the rotating disk is towards the front position. And if we get the timing right, we can make a simple animation.
 
If you watch the video above, you will see that the image bounces around a little bit. The duration of each frame is determined by the speed of the rotating disk (or motor), and the number of LED flashes per frame. Any changes in rotation speed will affect the position of the picture when the LED blinks. My rotating disk is not completely semetrical or centred correctly, and therefore a bit jumpy… but you get the idea. Bold images with high contrast seem to work best… Precision is key for this type of project. And if you can get the disk to rotate at a constant speed, you could probably do away with the hall effect sensors and magnets… however, in my case, these were essential in getting the project to work as intended.
 
This project is a lot of fun. You can really get creative by making your own pictures or 3 dimensional models (for a stop motion effect). Try different colours. It really is quite cool.



Concluding Comments


I would like to thank Magzor for supplying the components used in this tutorial, and letting me try out their MDP process. I really like the concept, the one stop shop which looks after you from beginning to end. Providing everything I needed to get the project off the ground. The point of this exercise was to go through the entire process of selecting the parts, build the project, and get it up and running. And I have done that in no time at all.
 
There is only one library to download and install, and the good thing is that you don't have to go hunting for it. The latest "correct" working version of the library is easy to find, right there on the Magzor website… Speaking of the Magzor website, please make sure to take a quick look around. It is quite impressive.
 
  UPDATE: Magzor has just started a Kickstarter campaign. Please check it out to get a good package deal on many of their components. Many of which were used in this tutorial.





If you like this page, please do me a favour and show your appreciation :

 
Visit my ArduinoBasics Google + page.
Follow me on Twitter by looking for ScottC @ArduinoBasics.
I can also be found on Pinterest and Instagram.
Have a look at my videos on my YouTube channel.


 
 
             

This project would not have been possible without the collaborative effort from Magzor Corporation.
Please visit their site and check out the MDP.



However, if you do not have a google profile...
Feel free to share this page with your friends in any way you see fit.

3 June 2012

Jumper: Arduino controlled animation

In this project, I have connected an Arduino to my computer and used a photoresistor to control an animation on the screen. Other sensors could have been used, but I chose a photoresistor because it feels like magic!!

The photoresistor responds to changes in ambient light as my hand moves up and down. The Arduino sends the reading to a Processing sketch on the computer via a Serial command (through the USB cable). The processing sketch interprets the signal from the Arduino and selects the appropriate picture to display.

I took a series of screenshots from the following YouTube video: http://www.youtube.com/watch?v=h6nE8m74kDg  And after borrowing a bit of code from these sites (1,2), the project was born.
This idea is not new, nor my own. There are many people who have done this project before, but I thought to blog about how I have done it, just for fun.

The Project Movie




Components Required


  • Arduino Uno (and associated software), and USB cable
  • Photoresistor or Photocell
  • 10K resistor
  • Wires to put it all together
  • Processing IDE from http://processing.org
  • Computer/laptop


The Arduino Sketch






The Arduino Code:

You can download the Arduino IDE from this site.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Jumper: Using an Arduino to animate:
   Written by ScottC on 02/06/2012 */

int photoRPin = 0; 
int minLight;
int maxLight;
int lightLevel;
int adjustedLightLevel;
int oldLightLevel;

void setup() {
  Serial.begin(9600);
  
  //Setup the starting light level limits
  lightLevel=analogRead(photoRPin);
  minLight=lightLevel-10;
  maxLight=lightLevel;
  oldLightLevel=lightLevel;
}

void loop(){
   lightLevel=analogRead(photoRPin);
   delay(10);
  
  //auto-adjust the minimum and maximum limits in real time   
   if(minLight>lightLevel){
     minLight=lightLevel;
   }
   if(maxLight<lightLevel){
     maxLight=lightLevel;
   }
   
   //Map the light level to produce a result between 1 and 28.
   adjustedLightLevel = map(lightLevel, (minLight+20), (maxLight-20), 1, 28); 
   adjustedLightLevel = constrain (adjustedLightLevel, 1,28);
   
   /*Only send a new value to the Serial Port if the 
     adjustedLightLevel value changes.*/
   if(oldLightLevel==adjustedLightLevel){
     //do nothing if the old value and the new value are the same.
   }else{
     //Update the oldLightLevel value for the next round
     oldLightLevel=adjustedLightLevel;
     
     /*Send the adjusted Light level result 
       to Serial port (processing)*/
     Serial.println(adjustedLightLevel);
   } 
}

The code above was formatted using this site.



The Processing Code:

You can download the Processing IDE from this site.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* Jumper: Using an Arduino to animate
   Written by ScottC on 02/06/2012

Source code derived from : 
  http://processing.org/learning/topics/sequential.html
  http://processing.org/discourse/beta/num_1267080062.html

Pictures captured from:
  http://www.youtube.com/watch?v=h6nE8m74kDg      
  
======================================================= */

import processing.serial.*;
Serial myPort;
String sensorReading="";

// Create the array that will hold the images
PImage[] movieImage = new PImage[29];

/* The frame variable is  used to control which 
   image is displayed */
int frame = 1;



/* Setup the size of the window. Initialise serial communication with Arduino
   and pre-load the images to be displayed later on. This is done only once.
   I am using COM6 on my computer, you may need replace this value with your
   active COM port being used by the Arduino.*/

void setup(){
  size(700,600);
  
  myPort = new Serial(this, "COM6", 9600);
  myPort.bufferUntil('\n');
  
  for(int i=0;i<28;i++){
    movieImage[i] = loadImage("Jumper" + (i+1) + ".jpg");
  }
}




// The draw function controls the animation sequence.

void draw(){
  
  //this draws the relevant image to the window  
  image(movieImage[frame-1],0,0,width,height);
}

void serialEvent (Serial myPort){
 sensorReading = myPort.readStringUntil('\n');
  if(sensorReading != null){
    sensorReading=trim(sensorReading);
    if (sensorReading.length()<2){
      frame = integerFromChar(sensorReading.charAt(0));
    }else{
      frame = integerFromChar(sensorReading.charAt(0))*10;
      frame += integerFromChar(sensorReading.charAt(1));
    }
  }
}



/* This function used to convert the character received from the
   serial port (Arduino), and converts it to a number */
   
int integerFromChar(char myChar) {
  if (myChar < '0' || myChar > '9') {
    return -1;
  }else{
  return myChar - '0';
  }
}

The code above was formatted using this site.


The pictures 

Captured from this YouTube Video: http://www.youtube.com/watch?v=h6nE8m74kDg