Monday, 31 October 2011

Virtual Breadboard

Summary:
This piece of software allows us to virtually create any circuit we want, and test these circuits to make sure they work as they are supposed to.

Source:
http://www.virtualbreadboard.net/


This site is used to create and experiment with circuits. This is helpful because it can save a lot of time wiring, as it is all done virtually. This will also give us the ability to tinker more with our circuits. This extra time will allow us to be more creative and elaborate with our circuits. It will also allow use to use parts which are very expensive  or parts which we don't have very many of in our starter kits. This factors will in turn will create more efficient robots on a larger scale than we could previously handle.

The software itself is fairly user friendly. At this stage, even i can jump in and create simple circuits. The site offers a plethora of videos and .pdf files to help explain how to do use the software. And because this software imitates real world physics, you can be assured that anything which works in this program will work in the real world.

Motor Control Shield KIT

Summary:
This kit gives Arduino enough current to power larger motors which it normally could not.

Source:
http://www.amazon.com/Motor-control-shield-KIT-Arduino/dp/B002VH9APQ

Details:
This shield would save a lot of time in terms of creating the circuits for the motors. This is because we wouldn't need to create all of those transistor related circuits. The shield gives Arduino the ability to produce enough current to power these motors.

We can use this in class because it will help us save time when creating the moving parts for our robots. The circuits required for the motors will be less cumbersome for the motors. Also this will give us more time to work on making more creative robots, rather than focusing on wire management. Finally this shield will teach us how to solder, as it is not prebuilt. It does not come with instructions, so you will have to figure out what goes where yourself.
A picture of a non-built Motor Control Shield

This will cost 15.50 post shipping and taxes. The kit itself costs $11.99

Easy VR Arduino Shield

Summary:
This shield makes it easy for Arduino to have voice recognition. It also has an audio-jack output, along with a programmable LED.

Source:
http://www.seeedstudio.com/depot/easyvr-arduino-shield-p-997.html

Details:
This shield is very simple to attach, as it fits directly over the Arduino Uno. This kit is designed to be very easy to use, as it wants to make Voice Recognition with Arduino a simple process.

This shield will introduce a new library of programming. It will teach us how to create voice encoded passwords, which will help introduce us to software security. We can also use these on the lego robots, as it will allow us to control these robots by voice. For example if there were a project where we had to have a lego race, the user could say "LEFT" and "RIGHT" to control the direction of the lego car. Finally this can teach us how to create user friendly interfaces through the voice commands. This shield will help us learn some useful areas which programmers should know if they want to create programs for the general public.

To program this you can use a built in Arduino Library. It attaches directly over the Arduino Uno, as all of the pins line up.

A picture of the shield itself

This Shield would cost $46.50 for the item itself, and $2.85 for shipping (10 - 30 days). The grand total comes to $55.77. 

Sunday, 30 October 2011

CIRC-11: Larger Loads

Purpose:
To use one Relay in order to supply power to two separate LEDs.

Equipment:

  • 1x Arduino Uno
  • 1x Breadboard
  • 2x LED
  • 2x 330 Ohm Resistor
  • 1x 10k Ohm Resistor
  • 1x Transistor
  • 1x Relay
  • 1x Diode
Reference:

Program Details:
This program introduces one new piece of hardware, which is the relay. This relay is a mechanical relay, meaning it manually switches from one circuit to another. This switch creates a clicking sound, and helps you know that the relay is working. the relay itself has 5 pins. The lone pin over the pin pair is the one which takes in the voltage. The pair of pins are not connected to one another, as they are on two separate circuits. These two pins output the voltage which is taken in. The reaming two pins  have a coil in the middle of them, and require a current pass through.  The which circuit receives voltage is dependent on how much  current passes through the coil. A large amount results in a switch, while a small amount reverts is back to its normal position. 

As complicated as the circuit is, the programming for this experiment is very simple. It is the same code we had used in experiment one, but with Pin 13 replaced with Pin 2. This is because Pin 13 is not used in this experiment, and Pin 2 is the one which supplies the current to the base of the transistor.

This is a fairly complicated looking circuit, and therefore takes longer to assemble then our previous circuits. First take a 5V output from the 5V pin. Run this through the coil of the relay. Then connect this to the load of a transistor, with the emitter being directly connected to ground. Connect the base of the transistor to Pin 2, and place a 10k ohm resistor to lower the current. Between the coil and the transistor, place a bridging connection to the com; and a diode to prevent flyback. Finally connect the NO and NC ports to LEDs, with the negative ends grounded via a 330 Ohm resistor. 

Results:
It worked as intended the fist time it was put together.

Photo:
Done with Milind Shah


Tips:
For this circuit, it might be helpful to draw the Schematics, so you can get an under standing of what goes where. Also make sure you place a 10K Ohm resistor between Pin 2 and ground, else you might overload your transistor. 

Further Work:
You can set up a series of relay's. This would allow you to control an unlimited amount of LEDs, but each LED would receive a very small voltage.

Program Modifications:
No modifications were made to the program found in the reference:

Program:

int ledPin = 2;                              //This pin actually controls the current 

void setup()
{
    pinMode(ledPin, OUTPUT);    //Sets Pin 2 to output
}

void loop()
{
    digitalWrite(ledPin, HIGH);      //Transistor circuit is complete (LED A is on. LED B is off)
    delay(1000);                            //Halts program for 1 second
    digitalWrite(ledPin, LOW);      //Transitor circuit is incomplete (LED A is off. LED B is on)
    delay(1000);                            //Halts program for 1 second
}

Sunday, 23 October 2011

CIRC-09: Light

Purpose:
To use information from a photo resistor to change the brightness of a LED.

Equipment:

  • 1x Arduino Uno
  • 1x Breadboard
  • 1x LED
  • 1x 330 Ohm Resistor
  • 1x 10k Ohm Resistor
  • 1x Photo Resistor
  • Who knows how many wires
Reference:

Program Details:
The new piece of hardware being introduced here is a Photo Resistor. This works like the Potentiometer in the sense that it returns an analog signal, but unlike a Potentiometer it is controlled by environmental factors. The Photo Resistor also only has two pins, for the electricity to pass through. So the information must be takes in after the current has passed through. The amount of voltage the reading pin receives is dependent on how much light is present, with brighter areas receiving low voltages.

The experiment also introduces two new methods on the programming side. These two methods are map(value, fromLow, fromHigh, toLow, toHigh); and constrain(value, low, high); Map takes a value from on range, and then scales it down to another range. This is done in this program because Arduino can only output 8-bit, so the number given by the Photo Resistor needs to be scaled down. We also use constrain because map() does not set limits to how high the value can be, it only scales. So constrain() insures that the value will not exceed the 8-bit limit. 

To put this together we first created an independant circuit, to power 1 LED. The power for this LED comes through Pin 13. In the second circuit, we had 5V plass through a Photoresistor. After it has passed through we read the current with Analog Pin 0. Afterwards the electricity continues through a 10K ohm resistor, and is then grounded.

Results:
At first glance the program appeared to be working fine, as the LED was lit and we were in a bright room. After I placed my finger directly on the Photo Resistor, I was expecting the LED to go off. Rather in only got dimmer, which maybe due to the room being too bright or a faulty sensor.

Photo:
Done with Milind



Tips:
Make sure you don't forget to place the 10K oh resistor between the analog pin and ground. Else Pin 0  may get a faulty reading. 

Further Work:
You can create a threshold for the Photo Resistor, so it can behave like a  pushbutton; in the sense that its only two options for the LED would be on and off. To do this create a threshold so that when the lighlevel exceeds the threshold - the LED turns on, and if the lightlevel is lower than this threshold the LED turns off.

Program Modification;
The program is like the one found in the book and in the reference:

Program:

int lightPin = 0;  //Analog pin which reads the info from the Photo Resistor
int ledPin = 9;   //A PWM digital pin which controls the LED


void setup()
{
    pinMode(ledPin, Output);          //Sets Pin 9 to only output
}


void loop()
{
    int lightLevel = analogRead(lightPin);         //Sets light level to the info taken from Pin 0

    lightLevel = map(lightLevel, 0, 900, 0, 255);            //Changes the range from 0-900 --> 0-255
    lightLevel = constrain(lightLevel, 0, 255);                 //Value cannot exceed this range, and is capped
    
    analogWrite(ledPin, lightLevel);                               //Outputs the value (brightness of LED)
}

Saturday, 22 October 2011

CIRC-08: Twisting

Purpose:
Use a Potentiometer to control the time interval between an LED turning off and on.

Equipment:

  • 1x Arduino Uno
  • 1x Breadboard
  • 1x Potentiometer
  • 1x 330 Ohm Resistor
  • 1x LED
  • 6x Wires
Reference:

Program Details:
In terms of hardware, one new piece of hardware is introduced. This is another user controlled device, like the pushbutton. The difference being this one has more than two values, as it returns a 10 bit signal. This is helpful as it gives us more control than a pushbutton. For this Potentiometer to work, it needs 3 connections. The first two is a 5 Volt signal passing through it, with one end receiving the electricity, and the other end being grounded. The final pin, the one in the middle, is needed to give data to an analog pin.The number which it gives out is between 0 (0 volts) and 1024(5 volts). This number changes depend on the angle which the knob it twisted by the user. This particular Potentiometer has a 10k Ohm resistor. 

In terms of programming, we are introduced to a new yet familiar method. This method is anologRead(pin #). This means that this is the first time we are working with an actual analog pin, rather that a PWM digital pin. The anologRead behaves just like digitalRead(pin #), but this time it reads more than just HIGH and LOW. This is needed because the Potentiometer sends an analog signal, not a digital one. 

Finally, to assemble this we need to fist create two independent circuits. The first circuit is a very simple single LED circuit; which looks just like the one from Experiment 1and Experiment 7. Then we create another circuit for the Potentiometer, but this one is a bit more complex. The two end pins have a circuit flowing through it, with 5V coming from one end, and being grounded at the other. Then a wire carries the signal from the center to Pin 0. 

Results:
It worked at intended the first time we uploaded the code and supplied power.

Photo:
Done with Milind


Tips:
If the Potentiometer is not consistent, try taping it down. This should secure the connection.

Further Work:
You can change how long the delay lasts by altering the sensorValue. Dividing it or multiplying it by numbers can increase or decrease the delay time. 

Program Modifications: 
The program its identical to the one from:

Program: 

int sensorPin = 0;                             // Analog Pin 0 will take in the data from the Potentiometer 
int ledPin = 13;                                // LED is controlled by Pin 13
int sensorValue = 0;                        // Stores the info given to Pin 0

void setup
{
    pinMode( ledPin, OUTPUT);    //Pin 13 is set to only Output
}

void loop()
{
    sensorValue = analogRead(sensorPin);   //Become the value given by the Potentiometer
    digitalWrite(ledPin, HIGH);                    //Turns the LED on
    delay(sensorValue);                               //Waits for however long the user wants
    digitalWrite(ledPin, LOW);                    //Turns the LED off
    delay(sensorValue);                               //Waits again for however long the user wants
}

CIRC-07: Button Pressing

Purpose:
To turn a single LED on and off via a button press.

Equipment:

  • 1x Arduino Uno
  • 1x Breadboard
  • 1x 330 Ohm Resistor
  • 1x 10k Ohm Resistor
  • 1x Pushbutton
  • 1x LED
  • 5x Wires
Reference:

Program Details:
The one new piece of hardware this program has introduced is the Pushbutton. This button is a user controlled device. Our push button model works by completing a connection when pressed, and can complete up to two separate circuits.

In terms of programming, this is the firs time we have had Arduino take in information. Every experiment before this involved setting the pins to Output, but this time we are taking in an input. This is done by the method pinMode(pin #, INPUT). Since we are taking in an input, we will be using digitalRead, rather than digitalWirte. digitalRead(pin #) checks whether or not it is receiving any electricity. For this method, it creates a value of HIGH if there is electricity present, and LOW if there is not.

To put this circuit together we first create an interdependent circuit of the LED. This circuit looks just like the one from Experiment 1. It is a very simple circuit, as it receives its power from Pin 13, and the other end is grounded with a 330 Ohm resistor in the middle of the (-) end and ground.

Another circuit is also created for the pushbutton. 5V travels trough a 10k Ohm resistor to ground. But there is a pushbutton in the middle of this, so the circuit isn't always complete.The resistor is there because it is possible for the voltage to float when the button isn't pressed.  Pin 2 is connected to this circuit as well, and it will only receive voltage if the button is not pressed. Pin 2 checks whether or not it is reviving voltage, and without the resistor it is possible that Pin 2 will continue to receive voltage even though the circuit is grounded.


Time to complete:
10 minutes to build, 10 minutes to code.

Results:
The first time we uploaded the code, the LED turned on even though the button was not pressed. This was due to a programming error, as we accidentally flipped the behavior of Pin 13. After we flipped it back around it worked as intended.

Photos:




Tips:
Make sure that when you press the button that the circuit is actually completed. It is easy to miss align the pins on the pushbutton.

Further Work:
You can reverse the behavior of Pin 13. Doing this means that it would turn off when the button is pressed, and off when it is not. This can be done in the loop() by swapping the two digitalWrites. Change the LOW to HIGH, and vice versa.

Program Modifications:
The program looks just like the one from:
http://www.oomlout.com/a/products/ardx/circ-07

Program:


int ledPin = 13;                //Pin 13 controls LED
int inputPin = 2;                //Pin 2checks the button
int val = 0;                       // Stores pins status (set to LOW)

void setup
{
    pinMode(ledPin, OUTPUT);   //sets Pin 13 to output
    pinMode(inputPin, INPUT);    //sets Pin 2 to input
}

void loop()
{
    val = digitalRead(inputPin)      //Stores the state of the button

    if (val == HIGH){                  //When the button is not pressed
        digitalWrite(ledPin, LOW);    //LED does not receive electricity
 
    }else{                                   //When the button is pressed (else because there are only 2 options)
        digitalWrite(ledPin, HIGH);    //LED receives electricity
    }
}


Tuesday, 18 October 2011

CIRC-10: Temperature

Purpose:
To get Arduino to tell the computer what the ambient temperature is in the room.

Equipment:

  • 1x Arduino Uno
  • 1x Breadboard
  • 1x Temperature Sensor
  • 5x Wire
Reference:

Program Details:
This program introduces another integrated circuit which is packaged in a shell which looks exactly like the P2N2222AG transistors which we have worked with before. The only way too tell the difference would be to closely examine the case, as this one will be labeled TMP36. For this piece of hardware to work, it needs 3 connections: Voltage, signal, and ground. For the signal, it sends a signal, rather than take one in; as it tells arduino what the temperature is. And so, the signal is sent to an analog pin, where it can be read.

This code is the first time we have done a serial connection with the computer. And in doing so, there is a new method called Serial.begin(number);. This method is used in the setup to establish at which speed arduino sends information, and how quickly the computer reads it. Modern computers can read information much faster than 9600 killlabits per seconds, but we choose this speed because arduino cannot communicate any faster than this. Another new method we use is Serial.println(temperature); which is used for arduino to print the information it has received onto the serial monitor. Without it, arduino would tell the computer that it wants to communicate, but would say nothing. We use println rather than print because we want a break after every other statement, else it would all just be one big line, and difficult for the user to read.

Finally putting this together is very simple. We can save time by not using the (+) and the (-) column, as it is inefficient to do so since there is only one device which need voltage and is grounded. So we can connect 5V directly to the +5V pin, and ground to the gnd pin on the TMP36. Finally we take a wire from analog pin0, and connect it to the signal pin on arduino.

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

Results:
At first it was stating that the temperature in the room was below 10 degrees Celsius. After leaving it alone for a few seconds, it adjusted itself to the 17 - 21 degree range; which seems like the range the room temperature probably is.

Photos:




Tips:
Make sure you read what you are working with carefully, as this Temperature Sensor looks just like a Transistor. If you look at the black head closely, it should state the model number, which in turn will indicate what it is you are working with.


Further Work:
We can convert the temperature which is uploaded to a different form of measurement. You can do this by changing the outputted value from (temperature) --> (temperature - 273). This should print the value from Celsius to Kelvin. 

Program Modifactions:
Very similar to the one found in the reference:

The only thing which I changed was how often the temperature is displayed. I felt it was being displayed too slowly, so I shortened the time gap between when each temperature was being printed. I simply did this by going inot void loop(); and changing the delay(1000) ---> delay(200).

Program:


void setup()
{
  Serial.begin(9600);  //Sets the speed at which Arduino and the Computer communicate
}



void loop()                     
{
float temperature = getVoltage(temperaturePin);//Gets the voltage from the TMP36(calls method)
temperature = (temperature – .5) * 100;          //Converts the voltage to Celcius
                                                  
Serial.println(temperature);                    //Prints the temperature on the serial monitor
delay(1000);                                    //1 second wait
}


float getVoltage(int pin){             //Returns a float
return (analogRead(pin) * .004882814); //Reduces range from 0 - 1024 --> 0 - 5, Gives number
}

Monday, 17 October 2011

CIRC-05 - 8 More LEDs

Purpose:
To creates an 8 Bit binary timer using the 74HC595 Shift Register.

Equipment:

  • 1x Breadboard
  • 1x Arduino Uno
  • 8x LEDs
  • 8x 330 ohm Resistor
  • 1x Shift Register
  • Too many wires to count


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

Program Details:
This experiment introduces one new piece of hardware, which is the shift regiester. A shift Register is a complex circuit, which is integrated into a chip shape. This is done so they take up less space, and save the time and resources actually having to build the circuit yourself. In this case our shift register takes in data. clock, ground, and voltage; and outputs from 7 different areas and ground.

The programming part of this experiment introduces assigning ints values of HIGH or LOW. This can be done because HIGH means 1, and LOW means 0. This program also introduces a new method called shiftOut(pin, pin, MSBFIRST, int); This method is the simple way to send Arduino the 8 bit data which it needs to display.

Finally putting this circuit together was very simple, but there were a lot of wires so it was easy to loose track. First connect the 5V to the 16th port (VCC), and the 8th port to ground. Port 11, 12, and 14 are for Clock(3), Latch(4), and Data(2). Then connect wires from Q0 - Q7 to the 8 LEDs, all of which should be parallel to one another, not in sequence. Make sure these LEDs are grounded, and have 330 ohm resistors to prevent the LEDs from receiving too much voltage.

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

Results:
All of the LEDs lit up in a consistent pattern. Most likely was counting like it was meant too, but cannot confirm as i cannot count in Binary.


Photo:


Tips:
Color coding the wires is vital for this project. But because of the shear amount of wires required, you might run out of a certain color. So make sure you keep your wires in order and track which one goes where.

Program Modification:
Very similar to the one found on:
http://www.oomlout.com/a/products/ardx/circ-05

The only difference is I removed the methods changeLED(int a, int b) and updateLEDsLong(int a). This is because these two methods were never called upon, so I found it a bit confusing to have them linger around without any purpose.

I also used the int ON and int OFF whenever it asked for HIGH or LOW. This is because i wanted to check to see how it worked.

Program:



int data = 2;
int clock = 3;
int latch = 4;                                      //initializes the pin# for the three inputs which the shift register takes

const int ON = HIGH;                       //Gives ON value of 1
const int OFF = LOW;                      //Gives OFF value of 0

void setup()                                       //Sets pins 2,3,4 for OUTPUT
{
   pinMode(data, OUTPUT);
   pinMode(clock, OUTPUT);
   pinMode( latch, OUTPUT);
}

void loop()
{
    for(int i = 0; i < 256; i++)               //repeats 256 times
    {
        updateLEDs(i);                         //Calls the method updateLEDs(int a) and gives it the value of the loop#
        delay(100);                                //Tenth of a second delay
    }
}

void updateLEDs(int value)
{
    digitalWrite(latch, OFF);                                  //Latch doesn't receive voltage(LEDs stop blinking)
    shiftOut(data, clock, MSBFIRST, value);         //Gives new set of data (Latch must be off)
    digitalWrite(latch, ON);                                   //Latch revives Voltage again(LEDs blink again)
}

    


Sunday, 16 October 2011

CIRC-06 - Music

Purpose:
To get a Piezo Element to play the nursery rhyme "Twinkle Twinkle Little Star".

Equipment:

  • 1x Arduino Uno
  • 1x Piezo Element
  • 1x Breadboard
  • 2x Wires
Reference:

Program Details:
Because this is a very simple circuit, not many new pieces of hardware were introduced. The only new piece of hardware is the Piezo Element. What a Piezo Element does esentially is make a cliking sound everytime it recieves a current. If we send alot of pulses in a short period, we can attain differnt frequencies, and thus play different notes. For this piece to work it needs a voltage, provided by Pin 9, and be grounded on the other end. 

Nothing new is introduced in terms of coding except for a new method: delayMicroseconds(us). This method is very similar to delay, as it stops the program for a very short amount of time. One microsecond is equal to 1/1000th of a millisecond, which in turn is 1/1000th of a second; meaning 1 microsecond = 1 millionth of a second. This is done in this program to give the program time to send the voltage to the speaker, rather than turning on and off instantly. The length of the delay determines the note which will be played in this case.

This is very simple to put together. First place the Piezo element onto the breadboard with each pin on its own row, and check which end is positive. This can be done by looking at the top, as the positive end will have a (+) with a circle around it. Then take a wire, and connect one end to Pin 9, and the other to the positive row. Afterwards take a wire, with one end connected to the ground, and the other to the negative row. 

Results:
The Piezo Element played "Twinkle Twinkle Little Star" flawlessly, as intended.

Photo:


Tips:
Make sure that you connect it the right way, as it only works in one direction. If you didn't its very simple to fix: just take it out , rotate it 180, and place it back in.

Further Work:
You can modify beats[] and the notes[] to essentially play any song that you want. The possibilities are endless.

Program Modifacations:
The program is exactly like the one from:

This is because this is the only way to play "Twinkle Twinkle Little Star". Modifying this would mean that you are no longer playing this song.

Program:

int speakerPin = 9;                                                   //Output pin for speaker

int length = 15;                                  // the number of notes in the song (w/ rest)     
char notes[] = “ccggaagffeeddc “;                                // The final space means rest
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };           //length of each note
int tempo = 300;                                              //Speed at which the music plays

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


void loop() 
{
  for (int i = 0; i < length; i++)                             //Repeats 15 times (1 per note)
  {
    
    if (notes[i] == ' ')                                                     //Checks for rest
    {
      delay(beats[i] * tempo);      
                                    //rests for however long the beat lasts at the given tempo
    } 
   
    else                                                        //When there is no rest (note)
    {
      playNote(notes[i], beats[i] * tempo);                
                               //Calls method play note, gives current note and length of note
    }
   
    delay(tempo / 2);                                     //Little rest after the song is done
  }
}



void playNote(char note, int duration) 
{
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };           //all notes in Octave
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 }; //Corresponding 1/2timeHIGH

  for (int i = 0; i < 8; i++)                                 //Cycles 8 times (once per note)
  {
    if (names[i] == note)          //When the given note lines up with the notes in the octave
    {
      playTone(tones[i], duration);                       //Calls Playtone method to play note
    }
  }
}




void playTone(int tone, int duration)                   //Needs the 1/2timeHIGH and the length
{
  for (long i = 0; i < duration * 1000L; i += tone * 2)       //WTFQUISDHIUFSH
  {
    digitalWrite(speakerPin, HIGH);                                 //Sends voltage to speaker
    delayMicroseconds(tone);                   //Waits for signal to send (time = note played)
    digitalWrite(speakerPin, LOW);                                     //Stops sending voltage
    delayMicroseconds(tone);                                    //Waits AGAINOSDIFNOSD
  }
}




Saturday, 15 October 2011

CIRC-04: A Single Servo

Purpose:
To create a loop of a servo motor spinning 180 degrees, then resetting back to 0.

Equipment:

  • 1x Arduino Uno
  • 1x Breadboard
  • 5x Wires
  • 1x 3 Pin Header
  • 1x Mini Servo
Reference

Program Details:
In terms of new hardware, this program introduces the Pin Headers. This was seen in previous experiments, but was only used to attach the 'breadboard layout sheet' to the breadboard. But in this experiment, it is being used to connect the Servo Motor to the breadboard. It acts like a middleman, and though it isn't necessary, it does help connect two objects that have only holes, no pins. The main new piece of hardware being introduced here is the Servo Motor. A servo motor is a motor which has a lot of torque and precision. It also takes 3 inputs: voltage, data, and ground.

In terms of software, a new library is introduced. This library is called Servo.h and is imported like so: #include <Servo.h>. This also introduces the concept of creating objects, as it requires you to create an object of type Servo to control the methods in the class. A new method introduced here is Servo.attach; which designates which pin works with the servo. Also we use a method call Servo.write, which is used to tell the servo which degree to go to.

This is a very simple circuit to build. You can cut out the breadboard entirely by attaching the Pin 9 to data, 5V to Signal, and Ground to Ground. The circuit they ask you to do has a lot of middle-manning, and this way it is less cumbersome.

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

Results:
When we finished putting the circuit together, the servo was not spinning. This is because the Servo had tipped over, and was no longer attached to the bread 3 Pin Header. So we decided to hold the Servo in place, which then functioned as programmed.

Photo:


Tips:
The 3 pin header is not neccesary, you can just connect the Voltage, Data, and Ground directly to the servo. 

Further Work:
You could adjust how far the motor spins or how quickly it spins. You can adjust the degree by adjusting the for loop. Make pos < 90 as the condition to get 90 degrees of rotation. You can also adjust the speed by changing the delay time in to a smaller number for a faster rotation, or a bigger number for a slower rotation.

Program Modification
The program is the exact same as the one from the website:

Program

#include <Servo.h>;                      //Imports the library
Servo myservo ;                            //Creates an object of type Servo to control the new methodds

int pos = 0;                                 //Variable to control position

void setup()  {
    myservo.attach(9);                   //Pin 9 now controls the Servo
}

void loop() {
    for(pos = 0; 0 < 180 ; pos = pos+1)             //Resets to 0, then goes to 180 by increments of 1
    {
        myservo.write(pos);                                   //move to position pos
        delay(15);                                                 //Waits for servo to reach the positon
    }

     for(pos = 0; 0 < 180 ; pos = pos+1)             //Counts from 180 down to 0 by increments of 1
    {
        myservo.write(pos);                                   //move to position pos
        delay(15);                                                 //Waits for servo to reach the positon
    }      
}

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
}


Monday, 10 October 2011

CIRC-02: 8 LED Fun

Purpose:
To get a series of 8 LEDs to turn on is sequence over a 1 second span. Then get this same series to turn off in sequence over a one second span. Finally cause this on and off pattern to repeat as long as the Arduino Uno is receiving power.


Equipment:

  • 1x Arduino Uno
  • 1x Breadboard
  • 10x Wires
  • 8x 330 Ohm resistors
  • 8x LEDs

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


Program Details:
The second experiment adds on to what we learned in the first experiment. Now instead of 1 LED, there are 8 LEDs; which turn on and off in a pattern. No new hardware is introduced in this experiment, it only increases the quantity of items we need to use.

A few new concepts are added in the programming section. This includes for() loops, which are used to repeat a section of code until the condition is met. This can be seen in the setup(), where the for loop is used to quickly set pins 2 - 9 to output. Arrays [] are also introduced, which are used to store groups of similar variables. This is used to make the management of variables easier, as sometimes a large amount of individual variables can be hard to track. This can be seen before the initial setup, as the ledPins[] array is used to hold the pin #s which are meant to output.

Finally to make the circuit, we pretty much followed what the diagram showed us. Two ground connections went to the (+) and (-). Then four resistors connect to each ground connection, giving a total of 8. These 8 resistors are then connected to the negative end of the LEDs. The power for the 8 LEDs is provided by wires which connect from Pins 2 - 9 directly to the positive end. Each LED gets one pin, meaning they each initially receive 5 volts.


Time to Complete: 
5 minutes to code, 15 to build

Results:
Again, this is another fairly simple circuit; I had no difficulties when I put everything together. The LEDs blinked as they were supposed to.


Photo:




Tips:
The two ground columns are not necessary, as only one will suffice. Also make sure you color code your wires, as it can get confusing which wire does what when there are ten all jumbled up.


Further Work:
There are ALOT of different patterns you can try with the LEDs. This can be done by adjusting the order in which they light up, and how long they light up for.


Program Modifications: 
For the code, I did delete all of the commented out loops; as they took up space and were not actually being applied in the pattern I am doing. I did replace the oneAfterAnotherNoLoop(); with oneAfterAnotherLoop();. I did this because it takes much less space this way, and is much more efficient.


Program:


//This array sets which pins will be used to output
int ledPins[ ] = {2,3,4,5,6,7,8,9};       //Creates an array of integers containing values 2 through 9

void setup()
{
        for(int i = 0; i< 8; i++)                //loops 8 times for  the 8 indexes in array ledPins
        {      
                pinMode(ledPins[i], OUTPUT);             //Sets all of the 8 pins to Output. Indexes 0 - 7
        }
}

void loop()
{
        oneAfterAnotherLoop();                               //Calls the method oneAfterAnotherLoop
}

void oneAfterAnotherLoop()                             // Method (no return)
{
        int delayTime = 100;                                 // Creates new int with value of 100
     
        for(int i = 0; i < 8; i++)                              // Loops 8 times, counts forwards
        {
                digitalWrite(ledPins[i], HIGH);          // Sets the pins to output 5V in sequence
                delay(delayTime);                             // 1/10th second delay
        }


         for(int i = 8; i > 0; i--)                              // Loops 8 times, counts backwards
        {
                digitalWrite(ledPins[i], LOW);          // Sets pins to ground in sequence, backwards
                delay(delayTime);                             // 1/10th second delay
        }

 }

Tuesday, 4 October 2011

CIRC-01: Blinking Lights

Purpose:
To get 1 LED to blink on and off in a 2 second span.

Equipment:
  • 1x Breadboard 
  • 1x Arduino Uno
  • 3x Wires
  • 1x 330 Ohm Resistor
  • 1x 5mm Yellow LED

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


Program Details:
Because this is the first experiment, alot of new methods and hardware were introduced. In terms of new hardware, this experiment introduces the LED and the resistor. One thing to note when working with LEDs is that they only work in one direction, so it is important to make sure that the longer end connects to the positive end. Also LEDs require resistors, so they don't burn out if there is ever a surge.

In terms of new programming method, this program introduces the two required functions needed for arduino: void setup( ) and void loop( ). It also introduces methods such as pinmode(pin , mode); which you use to address which pin to activate with either an INPUT or OUTPUT. It also introduces digitalWrite(pin, value); which sets the OUTPUT to either HIGH (5 Volts) or LOW (Grounded). Finally the last method this program introduces is the delay(time); which sets a delay of however much you want, with 1 representing 1/1000 of a second.

To put this together we followed what the diagram show pretty closely, with the exception of the location of the LED on the breadboard. One wire went from ground to the (-) column, while the other went from PIN 13 to the (+) column. Then a wire went from the (+) column to to the positive end of the LED. Finally a 330 Ohm resistor went from the negative end of the LED to the (-) column.


Time to Complete:
5 Minute Build, 5 Minute Code


Results:
The circuit is very simple, and there is very little room for error. It worked as intended the first time I put it together.


Photo:






Tips:
You can save some time by going from PIN 13 directly to the positive end, as the (+) column connection really isn't necessary for this simple circuit.


Further Work:
In the future I may try to alter the constant blinking into a random pattern by using a Random variable in the delay( ); method.


Program Modifications:
I only made a very slight modification, which was making the LED blink more frequently. To do so I changed the delay(1000) --> delay(500).

Otherwise the code is the exact same as the one from:
http://www.oomlout.com/a/products/ardx/circ-01




Program:  
 
int ledPin =  13;               // Creates a variable for the PIN # 
 



void setup()                    // Runs once to initialize parts of the program
{                
  pinMode(ledPin, OUTPUT);      // Assigns LED 13 with an OUTPUT signal

}
 

void loop()                     
// Loops until there is no power                   
{
  digitalWrite(ledPin, HIGH);   // Gives PIN 13 a 5 Volt signal
  delay(500);                   // Creates an 0.5 second delay
  digitalWrite(ledPin, LOW);    // Pulls PIN 13 to ground
  delay(500);                   // Another 0.5 second delay
}                               // Loops again