Zoetrope: Carnivorous Plant Clip

Wasn’t that cool?

So, I wanted to build my own Zoetrope too! To be able to do that, I wired up my Arduino with a motor, and from there, placed buttons to spin the zoetrope one way, then the other way. There was also a potentiometer to control the speed of the Zoetrope. In order to manage the motor, this time, I used an H-bridge instead of transistor, as it pretty much performs the same duties as the transistor.

This project is very similar to the Motorized Spin-y Spin-y project I had a few weeks back, so you may wanna take a look at that here. So, without further ado, here is the video of my Zoetrope!

Here’s the code!

const int controlPin1 = 2;
const int controlPin2 = 3;
const int enablePin = 9;
const int directionSwitchPin = 4;
const int onOffSwitchStateSwitchPin = 5;
const int potPin = A0;

int onOffSwitchState = 0;
int previousOnOffSwitchState = 0;
int directionSwitchState = 0;
int previousDirectionSwitchState = 0;

int motorEnabled = 0;
int motorSpeed = 0;
int motorDirection = 1; 

void setup(){
  pinMode(directionSwitchPin, INPUT);
  pinMode(onOffSwitchStateSwitchPin, INPUT);
  pinMode(controlPin1, OUTPUT);
  pinMode(controlPin2, OUTPUT);
  pinMode(enablePin, OUTPUT);

  digitalWrite(enablePin, LOW);
}

void loop(){
  onOffSwitchState = digitalRead(onOffSwitchStateSwitchPin);
  delay(1);

  directionSwitchState = digitalRead(directionSwitchPin);

  motorSpeed = analogRead(potPin)/4; 

  if(onOffSwitchState != previousOnOffSwitchState){
    if(onOffSwitchState == HIGH){
      motorEnabled = !motorEnabled;
    }
  }

  if (directionSwitchState != previousDirectionSwitchState) {
    if (directionSwitchState == HIGH) {
      motorDirection = !motorDirection;
    }
  }  

  if (motorDirection == 1) {
    digitalWrite(controlPin1, HIGH);
    digitalWrite(controlPin2, LOW);
  }
  else {
    digitalWrite(controlPin1, LOW);
    digitalWrite(controlPin2, HIGH);
  }  

  if (motorEnabled == 1) {
    analogWrite(enablePin, motorSpeed);
  }
  else {
    analogWrite(enablePin, 0);
  }
  previousDirectionSwitchState = directionSwitchState;
  previousOnOffSwitchState = onOffSwitchState;
}

I hope you liked it! Yes, I’m now off to final project working mode!

Motorized Spin-y-Spin-y

Who doesn’t like colorful things than spin, huh? (Especially if you don’t have to spin it yourself?) So, that’s why I came up with this motorized spin-y spin-y! It’s actually the first time I used the motor, and to say the least, it was really fun (and quite dangerous too)!

So wiring up a motor is quite dangerous because the motor is voltage hungry, and so if you don’t get the wiring right, there might be a chance that you actually damage your motor and the Arduino board. But if you’re careful, it’s pretty easy and straightforward. In order to plug in the motor, you need to make sure the circuit is safe, to do that we employ two cool new parts: a transistor and a diode.

What a transistor does is, it’s a three pinned device wherein once power is passed through it connects the ground to the component ensuring the high voltage is managed correctly. A diode was also used. What it primarily does is that since it is polarized (it is meant to run only one way), it only allows the electricity to run one way and not back, which prevents damage to the motor.

The other parts of the wiring process was quite simple. All I did was to connect the motor to the transistor with a diode also connected in the circuit. And then a switch was made to control the spinning. The code was also one of the most straightforward codes around. Just power up the motor when I press the button pretty much sums up what the software does.

So watch me demonstrate this with the help of Pedro!

If you’re interested in the code, here it is: plain and simple!


//Declare Variables
const int switchPin = 2;
const int motorPin =  8;

int switchState = 0;

void setup() {
  pinMode(motorPin, OUTPUT);
  pinMode(switchPin, INPUT);
}

void loop(){
  switchState = digitalRead(switchPin);

  //If I press the button, start the spinning!
  if (switchState == HIGH) {
    digitalWrite(motorPin, HIGH);
  }
  else {
    digitalWrite(motorPin, LOW);
  }
}

So that’s the motorized spin-y spin-y. It’s really really fun to play with! I really recommend it! Oh and if you’re wondering how I came up with the pinwheel itself, it’s just a CD wrapped with a colorful piece of paper. Your Arduino comes with this cross that you can use to attach to the CD. I’m now going to try experimenting with different colors!