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!

Knock Lock Fun!

Locks always had a special place in my heart. I remember the amazement of playing with a lock and a key when I was in 4th grade. And then in 5th grade, I remember how we all got to have our own lockers, and hence we had to buy our own locks. My mom got me a silver one that was branded Yale for some weird reason, and that lock served me very well. It was only in 11th grade that I must have misplaced it somewhere. But you get the idea.

And so, now that I had to work on a knock-lock, of course I was really really excited. Basically, what happens is that you press a button to “lock” something and the servo motor turns its blades to lock something. To unlock the device, you have to tap the piezo three times successfully to be able to move the blade attached to the servo motor back to unlock the device. There are LEDs that tell you if your knock was successfully registered or not. In terms of code, it is very straightforward. After writing code that triggers the servo from the switch to lock the object, you just take in the input from the piezo, see if it reaches the threshold, and then once three knocks are made, then move the piezo. It was actually pretty fun!

Here’s a video of me playing with the Knock-Lock!

If you’re interested in the code, here’s the code too!


//This includes the servo motor we're going to use!
#include <Servo.h>
Servo myServo;

//Declaring the Variables(LEDs,Piezo,Switches,etc.)
const int piezo=A0;
const int switchPin=2;
const int yellowLed=3;
const int greenLed=4;
const int redLed=5;

int knockVal;
int switchVal;

const int quietKnock=10;
const int loudKnock=100;

boolean locked=false;
int numberOfKnocks=0;

void setup(){
  //Set the inputs and outputs
  myServo.attach(9);
  pinMode(yellowLed,OUTPUT);
  pinMode(greenLed,OUTPUT);
  pinMode(redLed,OUTPUT);
  pinMode(switchPin,INPUT);

  //Start Serial Communication
  Serial.begin(9600);

  //Prepare the Arduino for the Start State
  digitalWrite(greenLed,HIGH);
  myServo.write(0);
  Serial.println("The box is unlocked!");
}

void loop(){
  //What to do when Unlocked
  if(locked==false){
    switchVal=digitalRead(switchPin);
      if (switchVal==HIGH){
        locked=true;
        digitalWrite(greenLed,LOW);
        digitalWrite(redLed,HIGH);
        myServo.write(90);
        Serial.println("The box is locked!");
        delay(1000);
      }
  }

  //What to do when locked
  if(locked==true){
    knockVal=analogRead(piezo);

    if(numberOfKnocks<3 && knockVal>0){
      if(checkForKnock(knockVal)==true){
        numberOfKnocks++;
      }
      Serial.print(3-numberOfKnocks);
      Serial.println(" more knocks to go!");
    }
    if(numberOfKnocks==3){
      locked=false;
      myServo.write(0);
      delay(20);
      digitalWrite(greenLed,HIGH);
      digitalWrite(redLed,LOW);
      Serial.println("The box is unlocked!");
      numberOfKnocks=0;
    }
  }
}

//Code that checks the validity of a knock; Used to unlock the box
boolean checkForKnock(int value){
  if(value>quietKnock &&value<loudKnock){
    digitalWrite(yellowLed,HIGH);
    delay(50);
    digitalWrite(yellowLed,LOW);
    Serial.print("Valid knock of value ");
    Serial.println(value);
    return true;

  }else{
    Serial.print("Bad knock value ");
    Serial.println(value);
    return false;
  }
}

So there you go, this is the knock-lock! The modern more-futuristic version of that old rusty Yale lock I had back in 11th grade. Of course, it can’t replace the brotherhood I had with that lock, but yea, this new way of locking and unlocking this seems way cooler.

The Food Cue

Screen Shot 2014-10-09 at 5.03.55 PM

So one of the things that I always find myself confused in when I have meals in the dining hall is where exactly I should go to bus my trays. There were times that for lunch, trays were supposed to be bussed on the East side, and for dinner, it has to be bussed on the West side.

So, what I decided to come up with, was using pretty much the same code and technology as the Mood Cue, I created a food cure, where you are told where to bus your trays! It’s really cool!

Check the video below!

The Mood Cue

Ever wanted to tell people what your mood is electronically without having them bother you by knocking? Then the mood cue is here for you! You can easily turn a knob and tell people whether or not you want them to visit you! Isn’t this amazing?

How this project works is that using a servo motor a hand cues at something, points to something. The servo motor actually comes prepared with an entire library that can be used to control the motors in almost any way you want. The basics though are that, there is a pin that can move from 0 to 179 degrees, and that just pretty much lays the foundations for a very good way to signal things (think of like old-fashioned gas station pumps that have full/empty or just your car’s petrol gauge).

So, what I did was that using a knob, I could move the servo motor’s hands to whatever direction within 179 degrees I wanted to. And from that, I could tell people what my mood is currently.

See the video I made with the Mood Cue!

Also, check out the code that makes this thing work!


//Incldues the Servo Library
#include <Servo.h>

//Declares the Servo Motor (so I can just call this!)

Servo myServo;

//Variables
const int potPin=A0;
int potVal=0;
int angle=0;

//Begin Comms
void setup(){
myServo.attach(9);
Serial.begin(9600);

}

//The Magic
void loop(){
//Measures how much the knob is turned.
potVal=analogRead(potPin);
Serial.print("The Pot Value: ");
Serial.print(potVal);

//Translates that to the Servo motor!
angle=map(potVal,0,1023,0,179);
Serial.print(", angle: ");
Serial.println(angle);

myServo.write(angle);
delay(15);

}

So, that’s pretty much what I did! It’s a really cool thing to create! As I’ve mentioned in the video, some problems that I had with this project was that the potentiometer(knob) as well as the servo motor has a weird female head that even with the adapter doesn’t fit at all on the Arduino. I hope this can be sorted out because as you can see what I did in the video, I had to manually hold both apparatus down.

Other than that, it was a really cool project! And in fact, I had so much fun working on this that my extended project worked on using this technology to solve a problem here at NYUAD. Stay tuned for that!