Monday, October 10, 2011

A Single Servo (CIRC-04)

Purpose
     To control a servo, which rotates by changing angles.

Equipment
  • 1 x 3 Pin Header
  • 1 x Mini Servo
  • 5 x Wire
  • 1 x Breadboard Sheet
  • 1 x Breadboard
  • 1 x Arduino Uno
Program Details
     
     Assembling the following circuit is not the most intimidating task. The wires are simply plugged as instructed. The 3 pin header helps to hold the servo connection in place. Complete assembly of the circuit takes about 4-8 minutes. See the assembled circuit below.




The images of above show the assembled and functional circuit.


The vocabulary used to program the servo is to some degree new, but easy. The key is to understand what controls the servo, that is position, ranging from 0 to 180 degrees. Accordingly, the program leads the servo to rotate a degree every 15 ms until it reaches 180 degrees, then rotate back to 0 degrees in the same manner. The variable 'pos' is assigned to do this. It is astonishing that a function as simple as this can be applied in something as big as an airport. 


Results


     First the connector between the servo and the 3 pin header was lose, so the servo did not pin. However after securing this connection, the servo rotated as programmed. 


Tips


     Simply make sure the connection between the pin header and servo is secure before uploading the program. Also make sure the values assigned to the variable 'pos' is within the limit (0-180).


Next Steps & Associated Program


     A slightly more complicated approach to controlling the servo would be changing the pulse directly, versus making the servo an object controlled by position. While the servo is on, it turns, for the allotted time, then it turns off, and repeats this function. See the code below.



 int servoPin = 7; //the servo is connected to pin 7, note the assembly should match this too

 void setup()
 {
   pinMode(servoPin,OUTPUT); //initialize the pin, set up purposes
 }

 void loop()//the following segment is repeated
 {
   int pulseTime=2100; //amount of time the servo will be on
   digitalWrite (servoPin, HIGH);//turn the servo on, it turns
   delayMicroseconds(pulseTime);//leave it turned on for this long
   digitalWrite (servoPin, LOW);//turn the servo off
   delay (25);//wait 25ms before repeating the segment
 }

Simply referred to the Sparkfun Inventor's Guide.

Spin Motor Spin (CIRC-03)

Purpose
The purpose of this circuit experiment is to integrate the usage of transistors and motors.

Equipment
  • 1 x Transistor P2N2222AG
  • 1 x Diode
  • 1 x 10k Ohm Resistor
  • 1 x Toy Motor
  • 7 x Wires
  • 1 x Arduino Uno
  • 1 x Breadboard
  • 1 x Breadboard Sheet
Program Details

     With the new pieces, combination of small and big ones, it is a bit of a hassle connecting them as they overlap, but it isn't hard. Again, just as the resistors are specific to the direction in which they are connected, the diode, transistor and motor is as well. This was our first problem, both our diode and transistor was wired wrong. After rewiring and programming, it worked. See the image below.

Assembled and functional motor.

     Assembly takes around 5-10 minutes. The coding corresponds directly to what happens in the circuit. The main loop consists of three segments: turning the motor on and off, setting the motor to a specific speed while on, then bringing the speed down to a specific level and turning it off, and finally, accelerating and decelerating the motor. The programming within these categories are basic, using variables such as 'delaytime' and 'onspeed' for the different numerical values in the program. To turn the motor on and off, use HIGH and LOW. For the acceleration and deceleration, the speed limits are stated then the program counts up or down, using the same format as that used for repeating a code. Note that in the 'void loop()' two segments are commented out. This means they don't run.

Results

     As mentioned earlier after rewiring certain components, and uploading the provided code, the motor worked perfectly. First we didn't realized that the motor was programmed to function in three different ways, we only noticed that it'd pause or stop working sometimes. However after analyzing the code, we understood perfectly. If you hold your finger to the motor, as shown below, you can feel the motor work.




Hold your finger to the motor to feel it work.



     Tips

     To make sure you understand whats going on with the motor, analyze the program before uploading it. This time with the assembly, attach the smaller parts, in the right direction, then attach the wires overhead. This will make it easier and faster to work on the small breadboard. Also, right after attaching a part, check to make sure it is attached in the correct direction instead of checking amidst all the other parts. 


Next Steps & Associated Program Modifications


     There are small modifications that can be made to the already existing program to make it do more than it does. This is because two segments of code with different functions are already commented out. By getting rid of the slashes, the 'void loop()' will run those segments as well. One can also change the numerical values of the variables. See the program sequence with two segments now. The code in orange is essentially not needed for this program (not copied and pasted).



int motorPin=9;


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


void loop() //the program runs the following segment repeatedly no matter what
{
  motorOnThenoff(); //this turns the motor on for a certain time, then off
  motorOnThenoffwithSpeed(); //turns the motor on with a particular speed, then off
  //motorAcceleration(); this segment will not run for the program
}


void motorOnThenoff()
{
  int onTime=2500; //how long the motor will be on for
  int offTime=1000; //how long the motor will be off for
  digitalwrite (motorPin, HIGH); //turns the motor on
  delay(onTime); //function above is active for the duration of 2500ms
  digitalwrite(motorPin, LOW); //turns the motof off
  delay(offtime); //function above is active for the duration of 1000ms
}


void motorOnThenoffwithSpeed()
{
  int onSpeed=2000; //what speed the motor will be when it is on
  int onTime=2500;//how long it will stay on
  int offSpeed=50;//what speed signals that the motor is off
  int offTime=1000;//how long it will be off
  analogWrite (motorPin, onSpeed);//turns the motor on to the set speed
  delay(ontime);//keeps the motor on for 2500ms
  analogWrite(motorPin,offSpeed);//turns the motor off
  delay(offtime);//keeps the motor off for 1000ms
}


void motorAcceleration();
{
  int delaytime=50;
  for (int i=0; i<256; i++);
  {
    analogWrite(motorPin,i);
    delay(delaytime);
  }
  for (int i=255; i>=0; i--);
  {
    analogWrite(motorPin, i);
    delay (delayTime);
  }
}  



Reference


The Sparkfun Inventor's Guide



Tuesday, October 4, 2011

8 Blinking LEDs (CIRC-02)

Purpose:
The purpose of this experiment is to turn multiple LEDs on and off in a sequence.


Equipment:

  • 8 x 330 Ohm Resistor
  • 8 x Yellow LED
  • 10 x Wire
  • 1 x Breadboard
  • 1 x Arduino Uno
  • 1 x Breadboard reference sheet
Program Details:

      This circuit uses techniques similar to the first circuit, but with added LEDS (8 in total). Again, assembly is straightforward, but not easy. As the amount of LEDs increases, so does the resistors, and again, keeping them in place was quite a task. See 'Tips' for advice on this part of the assembly. Assembly takes around 3-8 minutes.The image below displays the assembled circuit.

Assembled and functional circuit 2.

     The programming for this circuit uses the same basics from the first circuit, (delaytime, HIGH, LOW, etc.), but with a few new concepts such as, utilizing an array, programming the number of repeats, and using the 'oneAfterAnotherNoLoop'. The array is used in the very beginning during the setup. In this case, it simply stores all possible values for the ledpin, which the program can access. Next, the number of repetitions is set using the variable i in the function: for(int i = 0; i < 8; i++){}.After setting i to the minimum, the limit (maximum) is stated using the less than sign, and is essentially the number of repetitions. By adding 'i++' afterwards, the program is allowed to increase the value of i till it reaches the maximum. Another way to be concise in this program is using the oneAfterAnotherNoLoop, which as its name suggests, performs everything in the loop one after another repeatedly. The loop in this circuit turns each LED on consecutively, with a pause identified by the variable 'delaytime', then turns all LEDs off in the same fashion.  

Results

     After uploading the program to the circuit, a minor error surfaced. Certain LEDs did not turn on at all, while the other LEDs followed the uploaded program. First we checked the program to see if the coding for the specific dysfunctional pins were the problem, however after checking everything, the source of error turned out to be the assembly of the resistors. Here we learnt that we have to wire the resistor specifically as shown in the breadboard sheet, so that the right side of the resistor was plugged into the right component in the breadboard. After rewiring the resistors, the circuit worked fine.

The final circuit.

Tips

     With the assembly of the circuit, the only thing to keep in mind is the fragility of the resistors. Assemble the resistors last, with patience, so you get it right the first time and also stays in place. In addition to the assembly, remember to keep the programming clean. Use comments so that you can refer back to what each component of the program is if something goes wrong. If you know it well, you don't have to. 

Next Steps & Associated Program Modifications


     There are many ways to go from here. You can add more pins, or play with the the pattern in which the LEDS are turned on and off. For instance, an arduino related forum, link here,  discussed manipulating the circuit to flash each LED in ascending/descending order. The following snip-it of new program (descending flashing lights) is from the website:


void descend()
{
  int descending[] = {9,8,7,6,5,4,3,2};
  
  for (int i = 0; i < PIN_COUNT; i++)
  {
    digitalWrite(descending[i], HIGH);
    delay(100);
    digitalWrite(descending[i], LOW);
  }
}



This coding can be integrated into the program for circuit two by simply adding this code after introducing the pins and setup. See below. New coding slightly modified, integration and comments original.


int ledPins[] = {2,3,4,5,6,7,8,9}; //this introduces the connected LEDs 
//that we'll be working with


void setup() //the coding below in setup turns all the LEDs on
{
  for (int i = 0; i < PIN_COUNT; i++)
  {
    pinMode(ledPins[i], OUTPUT);
  }
}



//now add the new codes!


void descend()  //loop for the descending pattern (repeats)
{
  int descending[] = {9,8,7,6,5,4,3,2}; //the order of the LEDs that will be used
//Note that this sequence is different from the regular one

    for (int i = 0; i < PIN_COUNT; i++) //the pattern will work up till the last 
//pin. From pin 2-9. However it starts off at nothing, 0.

  {    digitalWrite(descending[i], LOW); //the program originally said HIGH, but 
//since all the LEDs are already on, they will turn off first. 

    delay(100);  //wait a tenth of a second
    digitalWrite(descending[i], HIGH); //turn the LEDs off
  }
}







Finito!!


References

  1. http://forums.adafruit.com/viewtopic.php?f=21&t=17865
  2. http://docs.google.com/viewer?a=v&q=cache:oxirS_yKWpUJ:www.sparkfun.com/tutorial/AIK/ARDX-EG-SPAR-WEB.pdf+arduno+sparkfun+starter+kit+circ-01&hl=en&gl=ca&pid=bl&srcid=ADGEEShenZ1X6WUWJcmrXmkYtGjoNz6DylD1jf6bB0E9RT7CWJOitbc2DHxsFePHchtLV3h8TXOOjgqHR7i2hU07hfYY_j9QeHqE8q5dSw3xJbhtDK7njPAydUExPLnGZFfOq4ySJasd&sig=AHIEtbS9g6laYWNOfpgAqcqz8QvV9YxUVg&pli=1


Sunday, October 2, 2011

A Blinking LED (CIRC-01)

Purpose:
The purpose of this experiment is to create a blinking effect by repeatedly turning the LED on and off.

Equipment:
  • 1 x Yellow LED
  • 1 x 330 Ohm Resistor
  • 3 x Wires
  • 1 x Breadboard
  • 1 x Arduino Uno
  • 1 x Breadboard reference sheet
Program Details:

     Since this had been the first time building this circuit, programming with C and moreover performing an arduino project, there were many new concepts. The first segment of the project, assembly, was not hard to follow as there were a minimal number of pieces and a sheet to follow up with to make the appropriate connections on the breadboard. The task was simply placing the ends of the wires or pins, in the correct hole. See the image below of the assembled circuit.

Ariel shot of the assembled circuit.
  However, this job did uncover just how delicate the wires of a resistor are. Trying to push a single resisitor into the 2 appropriate holes took a great amount of time as it kept bending. Furthermore, the pair of us learnt how to read a resistor. The first coloured band corresponded to the first digit, the second coloured band corresponded to the second digit, and the third coloured band corresponded to the number of trailing zeros. A reference table was provided in the kit, and is available on this online version.

     The programming code was directly available on the program, however we also developed an understanding for the program that was uploaded to the circuit with the aid of the comments. First the basic operation was analyzed. The 'void setup' runs once just as the power is turned on, to setup the necessary componenets for the rest of the program. Then the LED light is turned on for one second, then off for another, on for a second, then off, and so forth. Then we looked at the functions of the individual lines. The line in the 'setup' component identified the LED pin. The loop in the rest of the program turned the light by sending a 'HIGH' voltage, 'delayed' it for 1000ms then turned it of by returning it to a ground state ('LOW'). Again the pin is delayed by 1000ms so that this becomes a constant pattern.

On the whole, it takes around 4-6 minutes to build, and 5-10 minutes to program, depending on one's level of experience.

Results

     Since this is one of the simplest and most straightforward circuits in the book, we had no problems getting the LED to blink. We simply built it, made sure every part was secure, then connected and uploaded the program. It seemed like at fist it was blinking at a fast pace, but after the setup, we noted the one second delay. It was blinking perfectly until we unplugged the program. See the images below of the circuit with the LED turned on.


The LED is turned on after being programmed.
      However to ensure that the circuit functions, the most important step is to make sure that everything, most importantly the delicate resistor is completely inserted into the breadboard.

Tips

     The only hassle with this circuit would be the resistor. Treat it with extra care, and try not to bend it unecessarily. Do not apply pressure to the very top of the resistor, instead force the resistor in using the long wire on either side. In order to avoid reinserting the resistors later in the assembly, assemble the wires first, then the LED then the resistor. Working from large pieces first, to smaller ones.

Next Steps & Associated Program Modifications

     A simple next step would be changing the delay time by n, and accordingly changing the coding for the amount of time to, n x 1000. However a more advanced effect, only slightly complicated would be changing the brightness using analog components. First, the wiring has to be changed to a pin that allows analog function, such as nine. Then the coding needs to be changed. Instead of the ledpin=13, make it ledpin=9. Finally inside the loop, instead of digitalwrite (ledpin, HIGH) or LOW, type analogwrite (ledpin, b), where b is any number between 0 and 255. When b is assigned 0, the LED is off, 255 the LED is on, inbetween creates a different brightness. The time delay inbetween is optional.

int ledPin = 9; //This introduces the lead pin, which is now connected to 9
//because it has analog capabilities.

// The setup() segment below runs once when the power is turned on
 void setup()
{
// The line below makes ledpin 9 an output

pinMode(ledPin, OUTPUT);
}

// the loop() segment is repeated as long as the Arduino has power
void loop()
{
analogw
rite(ledPin, 255);
//Now the LED is on
delay(1000);
// wait for a second
analogwrite (ledPin, 5);
//the LED has a diffrent brightness
analogwrite (ledPin, 6);
//the LED is slightly brighter
analogwrite (ledPin, 7);
//the LED is even brighter
analogwrite (ledPin, 0);
//the LED is turned off

}


 
The link in references gives the information above. However the modified programming is not copied and pasted from this site!!


References

  1. http://docs.google.com/viewer?a=v&q=cache:oxirS_yKWpUJ:www.sparkfun.com/tutorial/AIK/ARDX-EG-SPAR-WEB.pdf+arduno+sparkfun+starter+kit+circ-01&hl=en&gl=ca&pid=bl&srcid=ADGEEShenZ1X6WUWJcmrXmkYtGjoNz6DylD1jf6bB0E9RT7CWJOitbc2DHxsFePHchtLV3h8TXOOjgqHR7i2hU07hfYY_j9QeHqE8q5dSw3xJbhtDK7njPAydUExPLnGZFfOq4ySJasd&sig=AHIEtbS9g6laYWNOfpgAqcqz8QvV9YxUVg

Tuesday, September 27, 2011

Cool Tutorials

This site is nice for cool arduino projects!

Here is a screen shot! It looks boring, but the tutorials seem complete:




      I think this site is perfect since we're new to Arduino and we'll want to preform various levels of projects this year. This site gathers tutorials from different websites. We can merge these projects with those in the book. Furthermore, this site offers more advanced projects that we can attempt after mastering the basics. Maybe even find something perfect we can make for the Holiday Show!
For instance a project that sounds cool is, 'How to Play Your Favourite Melody With Arduino'. I'm assuming that all you need is an instrument to play the melody, the arduino kit, and the programming, which is conveniently available on the link. I hope this site becomes bigger in the future, there aren't sooo many projects right now.

Thursday, September 22, 2011

Arduino Joysticks!!

The joystick input shield, or the 'DFRobot Arduino Input Shield', provides a biaxial joystick and two coloured buttons that can be conveniently inserted to an Arduino.

Link to more product information (SOURCE)

     As quite simply explained at the top, this product consists of a joystick and two buttons on a shield that can be conveniently attached to the Arduino Uno (baseboard) via male to male pin headers in a stacked design. See the image below. The joystick uses potentiometer technology to control position as it has the capacity to give large output signals. The APC220 module interface enables wireless transmission and control on the Arduino. One button serves as a reset button while the other uses rocker technology. The button can pivot in the middle, and is sensitive to pressure at each end, as there are four keys located at each end, which it enables horizontal and vertical motion. Analog signals are used to achieve position control with the rocker button.


The following image shows the DFRobot Arduino Input Shield with the male to male pin headers for attachment.
(Image from lipoly.de)


     I believe that this will be useful for our class because we are going to fight with robots and we need to control them. It is easy and convenient to operate a manual joystick. It will feel like you're actually playing on your X box!! :D In addition, we gain the opportunity to learn how to program them, which will be fun, unique and especially interesting to those who want to pursue a career in the gaming industry. It's also compatible with our baseboard, so there won't be a big hassle in that area. The following link leads to a manual that contains a section specific to this product: Manual .     
An example of a robot that can be controlled!
(instructables.com)


     This product can be purchased on various sites posted on the Arduino website in the 'buy' section. The first link on this blog leads to one of these websites. The price ranges on this website are as follows:

If you buy:
1-10, cost=$22.00/product
10-100, cost=$20.24/product
100 or more, cost=$18.62/product
The price decreases as the product increases.

Shipping:
-Post Canada Expedited Parcels costs a bare minimum of $8.59 for ordering one product
-UPS costs a bare minimum of $22.16 for ordering one product
Again, the price decreases as the # of product increases. At a certain point, expedited parcels will become free! Thats a lot of product though.


Thats all!

Monday, September 19, 2011

HEYYY!

Hiii! So nothing big accomplished today. I'm lonely :( Follow meee!