Wednesday 12 October 2011

CIRC-03: Spin Motor Spin

Purpose: 
The objective for this experiment is to create a simple repeating pattern involving motors. This pattern is turning the motor on for 2.5 seconds, and then off for 1 second.


Equipment:
1x Arduino Uno
1x Breadboard
1x Transistor
1x Diode
1x 10k Ohm Resistor
1x Toy Motor
9x Wires


Reference:
http://www.oomlout.com/a/products/ardx/circ-03


Program Detail:
In terms of hardware, 3 new pieces were introduced. The first of the 3 is a NPN transistor. The NPN means that that the emitter is grounded, and the collector receives the voltage. A transistor is used to amlify a small current into a bigger current, which is what we need to do to power the motor. This is because Arduino does not produce a strong enough of a current by itself. Another new piece of hardware which was introduced is a Diode, which is used to make sure that electricity flow in one direction. This is necessary in this project because we have voltage coming from two sources, and so there is a risk of a reverse charge. The diode ensures that this will not happen.

In terms for software no new concepts were introduced in the basic program. But it does talk about how Pin 9 has Pulse Width Modulation (PWM), and so it can behave like an analog. This means that we can use Pin 9 to control the speed of the motor. The method we use to do this is analogWrite(//pin number(9),//0-255);. The number that you input determines the outputted voltage, with 0 represents 0 volts, and 255 representing 5 voltage.

To put this together we connected the 5 volt and the ground to the (+) and (-) columns respectively. Then we sent the signal from pin 9 to the base of the transistor, but first it passes through a 10K ohm resistor. The emmiter of the diode is grounded via a wire from the emmiter to the (-) column. This connection is switched when the motor is moving, because if it isn't than the motor will remain grounded forever. A diode is placed between the transistor and the 5V, parallel to the motor. This is to prevent the electricity from remaining in the motor when the motor is meant to be off, as it restricts the electricity from traveling in a loop.

Results:
When we initially uploaded the code, the motor didn't spin. This was due to the motor wires not being inputted properly, so we pushed the wire in further. After that the motor ran as it was supposed too.


Time to Complete:
10 minutes to build, 10 minutes to code


Photo:




Tips:
Be careful with the diode, as there is only one correct way to place in on your circuit. You can ensure that you've placed it correctly by physically looking at the diode, as there is a dark black line marking the negative end.


Further Work: 
The pin we used to supply power to this motor is different from the other digital pins. This is because our pin has a feature called Pulse Width Modulation (PWM) which essentially allows it to behave as an analog pin. This feature can be used to make the motor accelerate and decelerate, rather than only being at maximum speed and off.

Program Modifications:
My program is very similar to the core program, with the only difference being that I change the on and off times, as I felt the whole pattern took too long. So I cut the total length of the pattern to a fifth, and in doing so the motor remains on for 0.5 seconds, and off for a mere 0.2 seconds.

I also removed all of the commented out methods, as they were not in use.


Program:


int motorPin = 9;                                        //Variable to represent Pin 9


void setup()
{
        pinMode (motorPin, OUTPUT);       // Sets Pin 9 to OUTPUT
}

void loop()
{
        motorOnThenOff();                     //Calls on the method
}

motorOnThenOff()
{
        int onTime = 500;                             //Represents the time the motor will be on (0.5 seconds)
        int offTime = 200;                             //Represents the time the motor will be off (0.2 seconds)

        digitalWrite(motorPin, HIGH);          //Sets PIN 9 to output 5 volts (Motor turns on)
        delay(onTime);                                 //Waits for 1/2 second

        digitalWrite(motorPin, LOW);          //Sets PIN 9 to ground (Motor turns off)
        delay(offTime);                                //Waits for 1/5 second
}


No comments:

Post a Comment