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

Saturday, November 19, 2011

Button Control Assignment (CIRC07)

Purpose
The purpose of this assignment is to investigate the code that utilizes the buttons in circuit seven.

Equipment

  • 2 x Pushbutton
  • 2 x 10k Ohm Resistor
  • 4 x 330 Ohm Resistor
  • 4 x LED
  • 10 x Wires
  • 1 x Arduino Uno
  • 1 x Breadboard & reference sheet
Assembly


     Assembling this circuit takes around 7-10 minutes. It has the same format as circuit seven, except there are 3 more LEDs. You can note that the number of wires and resistors increase accordingly. Simply follow the same pattern of assembly for the extra LEDs, resistors and wires. Make sure the pushbutton is securely inserted before uploading the program.


Program Details

   This assignment consists of 3 sets of codes. Each explained within their own comments. The main purpose is to use the 'analogread' function to read the state of the button, then use 'if, else if, else'  to connect the corresponding state to the output (LEDs). If the button is pressed, the state is 'LOW', it it's unpressed the state is 'HIGH'. The last set of code, uses the 'and' function within one of it's if statements. This only executes the if statement if both conditions are met. In fact, set 3 is almost a direct copy of set 2 except the parts that are commented (and function one of them). 

Set 1: When button A is pressed all even LEDs are turned on for 0.5 seconds. When button B is pressed, all odd LEDs are turned on for 0.5 seconds.





Set 2: First, the number of times button A is pressed corresponds to the LED that will be turned on. Each time it's pressed, the first LED turns on for confirmation. Then, button B is pressed, and the corresponding LED (according to previous # of presses) is turned on for 0.5 seconds. Button A must be pressed before button B. If not, nothing will happen. Also if nothing is pressed, nothing happens.





Set 3: This is similar to Set 2. However, the LED that will turn on is determined by the number of times both button A and B are pressed. Both buttons must be pressed before pressing button B. 



*The three different sets of code serve as modifications of each other. Refer to the Next Steps & Modifications section in CIRC07 for more modifications that utilize the pushbuttons.*

Results


     All programs worked, however there is strict timing, which is annoying. For instance, button A has to be pressed soon after the LED confirming this turns off.Or else, the program will jump to the 'else if' block. Besides this, the circuit worked as instructed by the program. It's also nice to learn efficient and complex programming techniques. The challenge is fun, versus programming as the kit instructs. 

Tips


     After assembling the circuit check to make sure everything is wired properly, especially resistors. The resistors for the buttons are especially important because if the resistors are missing, it'll be short circuited!! For the program, first make sure your pins correspond to the actual circuit. Before programming, have a rough sketch of how you're going to implement the basic functions. Also try to be as efficient as possible. As you're programming, remember to consider every possibility, so that everything is tackled in the 'if, else if, else' statements. Occasionally, stop and run through the program from the beginning to avoid care less mistakes, repetitions, and have flow. You'll often do this subconsciously. It's easy to miss brackets and such as the program gets bigger. To make sure you have brackets, click on a bracket. This signals it's corresponding bracket. At the end, click play to verify your program. 


Resources


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

Thursday, October 27, 2011

Relays (CIRC11)

Purpose
The purpose of this circuit is to explore the role of a relay.


Equipment
  • 1 x Transistor
  • 1 x Relay
  • 1 x Diode
  • 1 x 560 Ohm Resistor
  • 1 x 2.2K Resistor
  • 2 x LEDs
  • 14 x Wires
  • 1 x Arduino Uno
  • 1 x Breadboard & reference sheet
Program Details

     Assembling this circuit takes up to around 7 minutes. There are a lot of important pieces besides the wires that need to be placed correctly. Some of these pieces have been used before, however it is still important to know how each piece functions to understand the circuit. The diode allows one way current flow, and the transistor either switches or amplifies current. This function is similar to the relay which acts as a switch for even large amounts of current. Since we're working with a lot of current the resistors are stronger as well. Below & beside are pictures of assembled circuits. 



     The code for the following circuit is as straightforward as blinking. In fact it follows the same format except instead of turning the LED on and off directly. We send the message to the pin connected to the relay. The LEDs are connected to the relay as well, so we're using one pin to control the bulk of the outputs. 

Results
     
     The LEDs worked fine, as instructed by the program. It did seem some what underwhelming, however I can imagine that it more LEDs were added it'd be pretty significant. This would be a good next step.

Tips

     The only important tip with this circuit is to connect the relay properly. If one of its 3 pins aren't connected properly, it won't function. Also make sure the wire that connects the relay to the Arduino board is connected to pin 2 on the Arduino board. 

Next Steps & Associated Modifications

     A simple addition would be to connect more LEDs to the circuit (specifically to the relay). This way we can see how useful the relay really is. The program code for this stays the same. However this circuit isn't simply limited to LEDs, try a motor! Or even the piezo element! The code that can be applied to basically all these outputs is explained below.


int ledPin=2; //the relay is connected to pin 2

void setup()
{ pinMode (ledPin, OUTPUT); } //make it so the relay sends output to LED

void loop()
{
  digitalWrite (ledPin, HIGH); //turns LED on via relay
  delay (1000); //wait a second
  digitalWrite (ledPin, LOW); //turns LED off via relay
  delay (1000); //wait a second before repeating this blinking effect
  
}

References:

1. Spark Fun Inventor's Starter Guide
2. http://www.oomlout.com/a/products/ardx/circ-11 

Wednesday, October 26, 2011

The Piezo Element (CIRC-06)

Purpose
     This circuit investigates how to operate a piezo element (creates sound) using the analog system and pulse frequency.


Equipment

  • 1 x Piezo Element
  • 4 x Wires
  • 1 x Breadboard & breadboard sheet
  • 1 x Arduino Uno
Program Details

     This circuit is probably one of the most easily assembled circuits, yet very effective. Assembly takes about 2-4 minutes. Simply attach the wires to the appropriate pins, and make sure one of them (9) is analog. This gives output signals to the piezo element, whose pin is connected parallel to the pin 9 wire on the breadboard. The assembled circuit looks like this.


     The program for this circuit uses various functions to play the note. First we introduce the number of notes, the notes, beats and temp. Then each note is given a frequency. The program then combines all the variables with the appropriate operators (multiplication and division), to play the note for the designated amount of time. The main function, which plays the tune is a repeating loop at the end of the code, after setting everything up. More detail is in the comments in the last section of this report.

Results


     Music to my ears! After watching LEDs for all this time, finally we can hear something different. The programming associated to this circuit plays a simple melody, however by adding your own notes, you can play any tune! Definitely trying this one later.


Tips


     Assembly is not hard to follow. Simply be careful with your programming, make sure the numerical values correspond. Also, make sure you understand the program format before initializing it.


Next Steps & Associated Program Modifications


     There are several tricks you can play on with this program. This includes changing the tempo (int tempo=#), tuning the notes by adjusting their individual frequencies as desired, and changing the melody!! I think that last one is fun, so below is the code for playing Happy Birthday.



  
int speakerPin = 9; //the piezo element is connected to this digital pin


int length = 13; // the number of notes in this tune+1
char notes[] = "ccdcfeccdcgf "; // the notes in this tune, where each note 
//corresponds to a specific frequency
int beats[] = { 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 4 }; //the beat, or length of
//each note introduced above
int tempo = 300; //the tempo for the tune


void playTone(int tone, int duration) 
{
  for (long i = 0; i < duration * 1000L; i += tone * 2) //sets up how long the tone is played
  {
    digitalWrite(speakerPin, HIGH);//turns the piezo on
    delayMicroseconds(tone); //for the length of the tone
    digitalWrite(speakerPin, LOW);//then the piezo is turned off
    delayMicroseconds(tone); //delayed for length of tone
  }
}


void playNote(char note, int duration) 
{
  char names[] = { 'c', 'd','f', 'e', 'g', 'f' }; //the different notes for the tune
  int tones[] = { 1915, 1700, 1432, 1519, 1275,}; 
  //their corresponding tone calculated by: 1/(2*notefrequency) 
  
  for (int i = 0; i < 6; i++)
  {
    if (names[i] == note)
    {
      playTone(tones[i], duration); //plays the note and tones introduced just above
    }
  }
}


void setup() 
{
  pinMode(speakerPin, OUTPUT); //setting pin 9 as output
}


void loop() 
{
  for (int i = 0; i < length; i++) 
  {
    if (notes[i] == ' ') //this section plays all the notes introduced earlier in
    //the array notes[], until all notes (12), the # less than variable 'length' is played
    {
      delay(beats[i] * tempo); // after the 'for' section there is a rest before repeating
    } 
    else 
    {
      playNote(notes[i], beats[i] * tempo); 
    }
    
    delay(tempo / 2); 
  }
}




Reference: Spark Fun Inventor's Guide

Temperature (CIRC-10)

Purpose
The purpose of this lab is to analyze how a temperature sensor works. Here we are reporting information instead of controlling something.


Equipment

  • 1 x Temperature Sensor (TMP36)
  • 5 x Wires
  • 1 x Breadboard & reference sheet
  • 1 x Arduino Uno
Program Details

     Assembling this circuit takes up to 5 minutes, usually less. It is important to wire the temperature sensor correctly, it is often overlooked. See the assembled circuit below.




     The program starts by introducing the only variable component attached to a pin, the temperature sensor. In the setup the program establishes a 'serial' connection with the computer so that later we can print the results. There is a button beside upload, a box with an antenna which opens the screen to display the output. The number in the brackets is the transmitting speed.  Since this program looks at a different overall function, displaying output on the computer, the program is a little different, but not necessarily hard. The main loop starts by branching off into the function 'getVoltage'. This function reads the temperature, converts it to a readable code and then returns the value. This value, 'temperature' is then converted to an actual temperature reading. Finally, 'Serial.println(temperature0' displays the temperature.

Results

      Due to the malfunction of our temperature sensor, the outputs that were printed on the screen were unreliable. The temperature was constantly fluctuating from numbers as low as -40, to numbers as high as 300, and then numbers close to 0. We tried another sensor, but none of them worked properly (same problem).Afraid of the sensor catching on fire, we were advised to detach the temperature sensor. Below is a screen shot of the outputs we were getting:




Tips

     The most important precaution is not to touch the temperature sensor with your hands, while and right after it is unplugged. This is because there is a risk of malfunction, you can burn yourself and the sensor can even catch on fire. As soon as you notice that the temperatures are drastically incorrect, unplug the Arduino from the computer. Also while assembling, make sure the temperature sensor is pugged in correctly before uploading the program.

Next Steps & Associated Program Modifications

     The output of this program is so basic, there are only small possible modifications. For example, the serial speed at the beginning can be changed. We can also display the temperature in another way, farenheit! This can be done by simply changing the line that calculates the temperature. See the code below.





int temperaturePin = 0; //the temperature sensor is connected to analog pin 0


void setup()
{
  Serial.begin(9600);  //in the setup we are starting a connection with the computer in order
  //to later print the information
}


void loop()                    
{
float temperature = getVoltage(temperaturePin);  //gets the digital reading from the temperature
                                                  //sensor by running the function getVoltage (see bottom)
temperature = (((temperature – .5) * 100)*1.8) +32;          //converts the digital number to the appropriate
                                                  //temperature in farenheit
Serial.println(temperature);                     //prints the temperature
delay(1000);                                     //pause for a second before repeating
}


float getVoltage(int pin)
{
return (analogRead(pin) * .004882814); //gets the appropriate temperature reading (analog),
                                        //converts it to a number in the digital range,
                                        //and returns it to float(temperature)
}


Reference: Spark Fun Inventor's Guide

Monday, October 24, 2011

Lets Fight (Arduino Robotics)!

This website is perfect to by equipment for robotics and other Arduino parts.
Below is a screenshot.




     I believe this website is perfect to buy all the necessary equipment for a robotics unit, if it were to run. It has a wide range of products, specific to robotics. You can buy a whole robotics kit (Ex: Humanoid), specific robotic parts for your own creation, and even other Arduino products. The robotic kits, for instance the Humanoid features kits by the brand of Bioloid. The problem is these are very costly, it can cause over a thousand dollars! This is not a problem because individual parts such as: wheels, hubs, casters, DC motors & controllers, acutators, hobby servos, lights, displays and pretty much any robotic element you can think of, is sold seperately. You can choose your own dimensions, brand, etc., for your own creation. The section specific for Arduino provides a wide range of equipment for starters, and creators, which is not specifically robotic. An example of these cool parts include a serial LCD display, or a buzzer (only $5). Finally, the bottom of the left menu allows you to shop for equipment based on the manufacturer, for those who have their favourites. On the top menu, the section 'Community', includes helpful forums on robotics, and cool pictures on advanced projects. I think it's definitely worth checking out to develop robotic skills.                                                                                                                   

Sunday, October 23, 2011

Welcome To Arduino

This website gives a good introduction to Arduino, answers FAQ, has hardware details, an Arduino Tutorial  and even some cool projects.

Screenshot: 







     I believe this a good introductory website because it gives a beginner user, a hardware overview to the circuit board (see Arduino FAQs on left menu). Even someone who upgraded their Arduino may find this website useful because it compares the new Arduino Uno to the older versions. In a way, the FAQ section gives the history, or evolution of the Arduino circuit board. Furthermore, the vocabulary used in this section can be applied to any programming technology, which broadens our knowledge even more. The side menu also has links to forums with helpful administrative support, advanced arduino projects, and tips for educators! I think this is great because now anyone can start teaching Arduino, or learning Arduino themselves using this website. If you want to buy the parts, the website also has a link to a reliable website (adafruit) that sells all the parts necessary to fulfill your various Arduino needs. 


     The top menu can lead you to a helpful Arduino Tutorial (to follow: Learn > Arduino Tutorial), complete with 6 lessons, a 'Help' section, and more details on additional compoenents such as: LCDs, Ethernets, etc. Lesson 0 introduces the essential pieces for this tutorial, complete with pictures and helpful details. For instance, telling the positive end of an LED from a negative. Lesson 0 also consists of software installation instructions for all Windows, Mac and Unix. Lesson 1 is somewhat of a followup which ensures that everything is fully functional, and gives you a brief description of the basics. This lesson even discusses possible errors and solutions to them so that the program runs smoothly in the future. Further lessons run you through the experiment and have follow up exercises. I believe this is an excellent tool t o make sure students understand every aspect of what they just learnt. Furthermore, whenever a new piece is brought in to the picture to use, the website recaps all the necessary equipment. The 'HELP!' section is useful because it addresses some annoying syntax errors you may run into. Again, there is a link to a website that sells the equipment. The projects (to follow: Projects > Arduino > ....) may seem advanced however if people are earnest it is complete with the necessary equipment and instructions. Definitely worth the time if you're interested.




*The website is by a university graduate named 'Limor' (go to Home>Pwr for more information). 

Photo-Resistor (CIRC-09)

Purpose
The purpose of this circuit is to explore the function and application of a photo resistor.

Equipment
  • 1 x Photo Resistor
  • 1 x LED
  • 1 x 330 Ohm Resistor
  • 1 x 10k Ohm Resistor
  • 6 x Wires
  • 1 x Breadboard & Reference Sheet
  • 1 x Arduino Uno
Program Details

     The photo resistor is yet another type of resistor, except this time sensitive to light (photons).   For this reason, in real life applications, the input value from this resistor can be fairly accurate. Another advantage is that the photo resistor doesn't require us, humans, to manipulate it. It is sensitive to the environment. When the setting is dark, there will be high resistance and no output, vice versa. The code for this program illustrates this more clearly. 

     However first, the circuit needs to be assembled, which takes 5-9 minutes. Follow the breadboard and attach the photo resistor properly. See the assembled circuit below.





     The code for this program doesn't integrate analog and digital signals, it is purely analog. The photo resistor is the input, and the LED is the output. First, the photo resistor assigns a value to 'lightlevel'. This value is then adjusted so that it ranges from 0-255. The 'analogwrite' function can then take this value and use it to change the state of the LED accordingly.

Results

     First we assumed that the photo resistor functioned the other way, so as to illuminate dark areas, so we thought we wired it wrong. However upon reading the guide and program, we understood it well. The circuit functions as it should, dimming and brightening according to the resistor. Another new aspect in the program we learnt was the ability to adjust the scale, and check over. This is the first time we've seen the program use a 'check for errors' mechanism with Arduino.

Tips

     The only major tip would be to wire the resistor properly for the circuit to function, key aspect. The photo resistor is also a fragile and sensitive piece, so handle with care. With the programming, make sure the numerical values are accurate with the ranges. If the range is too big, the 'analogwrite' function will not work.

Next Steps & Associated Program Modifications

    Again, small modifications to the program can change the results to lead to a different output. For instance, we can recreate what our group thought should happen with this circuit, dark room is illuminated, by simply altering the last line. See below.


int lightPin=0; //photo resistor is connected to analog pin 0. 
int ledPin=9; //LED is connected to pin 9 (PWM)

void setup()
{ pinMode(ledPin, OUTPUT); } //the LED is output

void loop()
{
  int lightLevel = analogRead(lightPin); //assign the input from the photo resistor to this 
  //new varuable
  lightLevel = map(lightLevel, 0, 900, 0, 255); //scale the input to 0-255 instead of 0-900
  lightLevel = constrain(lightLevel, 0, 255); //makes sure the scale is correct
  analogWrite(ledPin, 255-lightLevel); //subtract the value from 255 and send it as output
  //so that the LED functions opposite from the conventional way
}

Another easy modification is using the threshold method to create a switch. This follows the same principles as 'THE SWITCH' in the previous circuit. 


Reference: Spark Fun Inventor's Guide