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!