Friday, December 9, 2011

CIRC-04 Assignment 2

Purpose
     The purpose of this assignment is to apply the connection between the potentiometer & servo to control a robot. 


Equipment 
If the robot is being connected to Arduino Uno, the following parts are needed besides the robot:

  • Arduino Uno
  • 6 x Potentiometers
  • Breadboard
  • 26(approx) x Wires
Assembly

     Assembling this circuit doesn't follow the usual principle as it uses external equipment. However attaching the arduino related pieces can take up to 12 minutes. 

Program Details

     The following program uses the same functions as the prior assignment to control a robot with six potentiometers associated with six servos at the various turning points on the robot. Below is a diagram of the robot in initial position.

The following program accompanies this assignment:


Resources

http://schools.tdsb.on.ca/danforthcti/arduino/ArduinoGuide.html


*Results and Tips are omitted as the practical application wasn't completed. 

CIRC-04 Assignment 1

Purpose
     The purpose of this assignment is to learn to control the outputs Servos and LEDs using the primary input, potentiometer. 

Equipment
  • 1 x Servo & Servo Arm
  • 1 x 3 Pin Header
  • 1 x Potentiometer
  • 3 x LEDs
  • 3 x 330 Ohm Resistors
  • 11 x Wires
  • 1 x Arduino Uno
  • 1 x Breadboard & Reference Sheet
Assembly

     This circuit is simply a modification of CIRC4. The servo is attached in the same way, using a pin header and the three wires (power, grounding, data). The potentiometer follows the same principle, using 3 wires. Besides the servo and the potentiometer, there are 3 additional loads, LEDs, that are attached as usual. Assembling this circuit takes from 5-7 minutes. See the images below.



Program Details

     This assignment utilized the concept of a 'library' to control the servo and make the code easier. A library typically has a specific set of functions which can be called within the program. Simply introduce the library at the top of your program before using it. In the following code, the LED codes are straightforward, used in previous blogs, the only different functions are those associated with the servo library. For instance, the function 'Servo ____' introduces the servo, with a name. In void setup(), the function '_____.attach(pin#)' forms the connection between the servo and digital pin. Note that the servo doesn't need to be declared input/output. The function 'map( , , ,)' is used to scale the values to be utilized by the servo. Finally, the function '_______.write(position variable)', turns the servo to the appropriate position. See the code below, which works to turn the servo as instructed by the potentiometer. The 3 LEDs are used to indicate the direction of the servo when it is at it's initial position, 90 degrees, and at it's max position (180). 

Results

     The program worked well after a few modifications. As always, strict timing has to be considered. Another consideration is the initial position, which should be carefully and manually set before the program is uploaded. Otherwise, it was another excellent exercise as it was a slight challenge integrating two outputs under the influence of one form of input. 

Tips include: 

  • connect the servo to the circuit last because it can be easily detached and lost
  • avoid clutter and section off the circuit (LEDs, potentiometer, servo), there are a lot of wires
  • follow the current path to make sure the appropriate wires and resistors are present and connected accordingly
  • secure the servo connection with fingers if necessary
  • remember the scale starts at 0 degrees
  • also remember to call the library at the very start of the program

Resources

Spark Fun Inventor's Starter Guide
http://schools.tdsb.on.ca/danforthcti/arduino/ArduinoGuide.html

Tuesday, December 6, 2011

CIRC3-Assignment 4

Purpose
      The purpose of this lab is to learn to control a motor's speed using button input signals. 


Equipment

  • 1 x DC Motor
  • 1 x Diode
  • 1 x Transistor
  • 2 x Pushbuttons
  • 4 x LEDs
  • 3 x 10k Ohm Resistor
  • 4 x 330 Ohm Resistor
  • 14 x Wires
Assembly

     The following lab consisted of two circuits, the second one being a modification of the first one. The first circuit simply consists of a motor & its associated parts, and two pushbuttons. Exclude the LEDs and its associated resistors, wires, etc. Used for Part One, the pushbuttons are used to accelerate and decelerate the motor. Building the first circuit can take 3-5 minutes, however the most important step is taking a minute to check afterwards. Certain parts such as the diode is important for the safety of the parts. For instance the diode protects the motor from power surges and therefore must be connected properly. This also applies to the resistors used in all circuits (especially 10K). See the image of the assembled circuit to the right.



     
      The second circuit simple adds the four LEDs and its associated parts. This takes an additional 2 minutes, however if the primary circuit is not available, the whole circuit can take around 7 minutes to assemble. The additional LEDs play an important role representing the speeds in parts 2&3, so make sure they are connected accurately, and correspond to the program code. This circuit also only utilizes the first button. Simply ignore the other one. Nothing happens if it's pressed. See the image of the circuit to the left.




Program Details

     This assignment consists of 3 parts, each a slightly advanced modification of the other. Most functions were discussed in the previous blog, the only new concepts surround the inclusion of the motor. The motor's speed functions off an analog command. The range is 0-255, where 0 is off, and 255 is the maximum speed.  Commanding the motor to function at a certain speed follows this format: 'analogWrite(motorpin, speed), where the speed is a number from 0-255. In part 1, the 'for loop' is used to accelerate and decelerate the motor as the loop counts from 0 up to 255, then later from 255 down to 0. Each part's objective and code is explained below (comments). 

Part 1: Use the two buttons in the first circuit to accelerate (button 1) and decelerate (button 2) the speed of the motor.
Part 2: Use the first button to tell the circuit how fast the motor should be spinning. The number of times the button is pressed corresponds to how fast, and which LED is turned on. This can be 25% (one press, 1st LED), 50% (two presses, 2nd LED), 75% (three presses, 3rd LED), or 100% (four presses, fourth LED) of full speed. 

Part 3: Using the same circuit and speed values in Part 2, tell the motor what speed to function in. In addition, make the motor reduce to 25% of its speed every 0.5 seconds until it is turned off. As it reduces speed, the corresponding LED should be on as well. 


*The three parts serve as modifications, refer to CIRC03 for additional modifications.

Results

     There were certain minor errors that were often overlooked, but soon after correcting these, everything worked as it was supposed to. Again, there is strict timing as to when the buttons are pushed and when the buttons' states are read. To make this more user friendly, there were certain delays placed after reading the buttons' state. It was also hard to see the motor accelerating, it easier to feel it. To enhance the outcome, attach something light weight to the top of the motor, such as a small piece of paper. If possible, secure the detachable shaft from the mini servo on to the motor. Besides this, it was interesting to connect the two outputs, with one input. 

Tips include:

  • separate various parts of the circuit to avoid clutter (For instance, keep the LEDs bottom right, pushbuttons bottom left, and motor top left)
  • make sure the pins that the various inputs and outputs are connected to match the code, or else the data will not be conveyed
  • connect important pieces CORRECTLY, for safety issues (Eg, diode as explained earlier)
  • as always take the time to check over

Resources

Spark Fun Inventor's Starter Guide
http://schools.tdsb.on.ca/danforthcti/arduino/ArduinoGuide.html