Thursday, October 20, 2011

LilyPad Arduino

SUMMARY:

The LilyPad Arduino is a microcontroller board made for wearables and e-textiles; it includes sewable electronic components that allow you to build your own soft, interactive fashion.


SITE LINK:


DETAILS:

The LilyPad Arduino is an awesome looking Arduino microcontroller board that has a set of sewable electronic components which you can use to create your own soft, interactive fashion. The Lilypad Arduino can be sewn to fabric and similarly mounted power supplies, sensors and actuators with conductive thread. Thus, it would be a very useful kit to us and we should buy it for our class.
Basic facts:

Microcontroller
ATmega168V or ATmega328V
Operating Voltage
2.7-5.5 V
Input Voltage
2.7-5.5 V
Digital I/O Pins
14 (of which 6 provide PWM output)
Analog Input Pins
6
DC Current per I/O Pin
40 mA
Flash Memory
16 KB (of which 2 KB used by bootloader)
SRAM
1 KB
EEPROM
512 bytes
Clock Speed
8 MHz


The LilyPad Arduino can be programmed with the Arduino software (the link is below). *Note*, you should only be programming this with software versions 0010 or higher. However, you can program it with earlier versions but it won’t be as efficient and as fast as you want it to be.

The Lilypad Starter Kit costs $128.50 in total and includes the following parts:

Additional Info:
To get your LilyPad Arduino working, see this guide.
SparkFun Electronics has a range of accessories for use with the LilyPad Arduino.

Want to Buy from Arduino Store?
Arduino Store
Want to Buy from Distributors?
Distributors

Spin Motor Spin (CIRC-03)

PURPOSE:

The purpose of this circuit experiment is to incorporate the usage of a transistor and a motor.

EQUIPMENT:

·         1 x Toy Motor
·         1 x Diode(1N4001)
·         1 x 10k Ohm Resistor
·         1 x Transistor P2N2222AG(TO92)
·         7 x Wires (any color)
·         1 x CIRC-03 Breadboard Sheet
·         1 x Arduino Uno
·         1 x Breadboard
·         1 x USB cable

PROGRAM DETAILS:
In this circuit, 3 new parts were introduced, Transistor Toy Motor and Diode. The transistor is to control a circuit that's carrying higher current and voltage from the microcontroller (operates like an electronic switch). The one used for this circuit is a NPN transistor. It's designed for switching high-current loads. It has three connections, the base, the collector, and the emitter. The base is connected to the microcontroller's output. The high-current load (i.e. the motor or light) is attached to its power source, and then to the collector of the transistor. The emitter of the transistor is connected to ground.

A DC motor spins when a current is passed through it. A DC motor was attached to the collector of the transistor. Most motors will require more strength of an electric current than the microcontroller can supply, so sometimes you might need to add a separate power supply as well. If the motor you are using runs on around 9V, you could use a 9V battery. The ground of the motor power supply connects to the ground of the microcontroller, on the breadboard.

Finally, a diode was added in parallel with the collector and emitter of the transistor, pointing away from ground. The diode is used to protect the transistor from back voltage generated when the motor shuts off, or if the motor is turned in the reverse direction.

At first, we put the Arduino Holder on the table, attached the Breadboard on the left side and Arduino microcontroller on the right. All the necessary parts for this circuit were gathered. We was decided that attaching the transistor, toy motor, diode and 10k Ohm resistor to the breadboard, respectively and, doing the colorful wiring at the very last would be better so that the other parts don’t come off.  

In terms of coding, along with the previous basics few new methods were introduced as shown below.

/*
* motorAcceleration() - accelerates the motor to full speed then
 * back down to zero
*/
void motorAcceleration(){
  int delayTime = 50; //milliseconds between each speed step
 
  //Accelerates the motor
  for(int i = 0; i < 256; i++){ //goes through each speed from 0 to 255
    analogWrite(motorPin, i);   //sets the new speed
    delay(delayTime);           // waits for delayTime milliseconds
  }
 
  //Decelerates the motor
  for(int i = 255; i >= 0; i--){ //goes through each speed from 255 to 0
    analogWrite(motorPin, i);   //sets the new speed
    delay(delayTime);           // waits for delayTime milliseconds
  }


TIME TO COMPLETE:
This circuit experiment took 22 minutes to complete (17 minutes to create the circuit and 5 minutes to download and upload the code).
RESULTS:
The code was downloaded from (http://ardx.org/CODE03). Fortunately, the program uploaded successfully and the motor was spinning as it was supposed to.
PHOTOS OF PROJECT:
TIPS:

When choosing transistor, make sure you don’t mix it up with the Temperature Sensor which looks very similar to the NPN Transistor. Check the back of the black part to avoid doing this mistake. Also, when you have the transistor make sure you plug in the right way round.
FURTHER WORK:
To take this circuit experiment further, I would like to control the speed of the motor. The Arduino does this by using something called Pulse Width Modulation (PWM). The Arduino can operate its motor really, really fast. Rather than directly controlling the voltage coming from the pin the Arduino will switch the pin on/off very quickly. To do this:
In the loop() section, I’ve to change it to this:

// motorOnThenOff();
 //motorOnThenOffWithSpeed();
 //motorAcceleration();

PROGRAM MODIFICATIONS:
My program was exactly the same as the one in the Sprakfun Inventor’s Guide except, the only difference is that I shortened the on and off time so that the whole process goes faster.
PROGRAM (with comments):
*/

int motorPin = 9;  // define the pin the motor is connected to
                   // (if you use pin 9,10,11 or 3you can also control speed)

/*
* setup() - this function runs once when you turn your Arduino on
* We set the motors pin to be an output (turning the pin high (+5v) or low (ground) (-))
* rather than an input (checking whether a pin is high or low)
*/
void setup()
{
pinMode(motorPin, OUTPUT);
}


/*
* loop() - this function will start after setup finishes and then repeat
* we call a function called motorOnThenOff()
*/

void loop()                     // run over and over again
{
motorOnThenOff();
//motorOnThenOffWithSpeed();
//motorAcceleration();
}

/*
* motorOnThenOff() - turns motor on then off
* (notice this code is identical to the code we used for
* the blinking LED)
*/
void motorOnThenOff(){
  int onTime = 2500;  //the number of milliseconds for the motor to turn on for
  int offTime = 1000; //the number of milliseconds for the motor to turn off for
 
  digitalWrite(motorPin, HIGH); // turns the motor On
  delay(onTime);                // waits for onTime milliseconds
  digitalWrite(motorPin, LOW);  // turns the motor Off
  delay(offTime);               // waits for offTime milliseconds
}

/*
* motorOnThenOffWithSpeed() - turns motor on then off but uses speed values as well
* (notice this code is identical to the code we used for
* the blinking LED)
*/
void motorOnThenOffWithSpeed(){
 
  int onSpeed = 200;  // a number between 0 (stopped) and 255 (full speed)
  int onTime = 2500;  //the number of milliseconds for the motor to turn on for
 
  int offSpeed = 50;  // a number between 0 (stopped) and 255 (full speed)
  int offTime = 1000; //the number of milliseconds for the motor to turn off for
 
  analogWrite(motorPin, onSpeed);   // turns the motor On
  delay(onTime);                    // waits for onTime milliseconds
  analogWrite(motorPin, offSpeed);  // turns the motor Off
  delay(offTime);                   // waits for offTime milliseconds
}

/*
* motorAcceleration() - accelerates the motor to full speed then
* back down to zero
*/
void motorAcceleration(){
  int delayTime = 50; //milliseconds between each speed step
 
  //Accelerates the motor
  for(int i = 0; i < 256; i++){ //goes through each speed from 0 to 255
    analogWrite(motorPin, i);   //sets the new speed
    delay(delayTime);           // waits for delayTime milliseconds
  }
 
  //Decelerates the motor
  for(int i = 255; i >= 0; i--){ //goes through each speed from 255 to 0
    analogWrite(motorPin, i);   //sets the new speed
    delay(delayTime);           // waits for delayTime milliseconds
  }
}
REFERENCE:

1.  Image Reference
2.  The Sparkfun Inventor’s Guide


Wednesday, October 19, 2011

CIRC-02: Multiple LEDs

PURPOSE:                                                                                                                             Multiple LED Tutorial Video
To make 8 LEDs blink using 330 Ohm Resistor.
                       
EQUIPMENT:

·    CIRC-02 Breadboard Sheet
·    5mm Yellow LED x 8
·    330 Ohm Resistor (Orange-Orange-Brown) x 8
·    Wires (any colors)

REFERENCE:
Link 1
Link 2

PROGRAM DETAILS:

In the first circuit, we caused one LED to blink but in this circuit, we played around with 8 LEDs and had an opportunity to extend our Arduino knowledge a bit by making a range of lighting sequences. This circuit also gave us an opportunity to experiment with coding our own programs and getting a feel for how Arduino works. In addition to controlling the LEDs, we started investigating a few simple programming methods to keep our programs small and efficient. For example, we used the for() loops to run a piece of code several times and we used arrays[] to hold and manage variables easily.

Me and my partner, Varshini started off by gathering the parts we need for our Arduino. We attached the LEDs, resistors and wires respectively on the breadboard. We made sure the longer side of the LED goes to the positive side (the (+) and (-) are shown in the breadboard. We were being very careful with the resistors due to their fragileness. We chose different colored wires so that we don’t confuse ourselves and so that it looks better.

TIME TO COMPLETE:

Approximately 45mins

RESULTS:

When creating the circuit was completed, we analyzed the codes given in the Sparkfun Inventor’s Guide and we took an attempt to write our own code. We switched the serial port to the correct one and uploaded the program to see all the 8 LEDs blink. However, an unknown problem occurred and only 5 LEDs were blinking ( 1st, 4th and 6th LEDs weren’t blinking). We double checked our code and tried the 2 things out of the 3things the Sparkfun Guide tells you to do in cases when things don’t work out. The 2 things were: Checking the LEDs that weren’t working to ensure that they are the right way around and, double checked that the first LED is plugged into pin 2 and each pin thereafter. The 3rd thing was pulling everything out and starting with a fresh slate which we didn’t do because we didn’t want to start over again. Although, we tried these different things to solve our problem, we were still unsuccessful.


1st, 4th and 6th LEDs are not blinking!





Then Mr. Kee came in, checked our circuit and realized that the 1st, 4th and 6th LEDs weren’t blinking because their resistors were touching the LED’s side (when metal touches another metal, it doesn’t work). Finally, our problem was solved and all the 8 LEDs blinked.







PHOTOS OF PROJECT:
 
CIRC-02 Breadboard Sheet
and Schematic Diagram
 
Fritzing Diagram
TIPS:

One tip I can give everyone is that you should always gather the parts you need to build your circuit before building it. This will make you more organized and it will reduce the chances of losing any parts. Another tip I would give is that if things don’t work out, do NOT panic! Try to do the things from the “Not Working?” section in the Sparkfun Guide or ask your peers/Mr.Kee for help.

FURTHER WORK:

The animation for this circuit is not so interesting and so, I would like to try the other two sample animations. To do this, I will have to uncomment their lines and upload the program to my board and enjoy the new light animations. I would also like to jump into the included code and start changing things to test out my own animations by turning on/off LEDs in different sequences/patterns. I can do this easily by using digitalWrite(pinNumber, HIGH) and digitalWrite(pinNumber,LOW) since the main point is to turn an LED on and off.

 
PROGRAM MODIFICATIONS:

The program I was following is the same as the one found in this link.

PROGRAM (with comments):

/*     ———————————————————
*     |  Arduino Experimentation Kit Example Code             |
*     |  CIRC-05 .: 8 More LEDs :. (74HC595 Shift Register)   |
*     ———————————————————
*
* We have already controlled 8 LEDs however this does it in a slightly
* different manner. Rather than using 8 pins we will use just three
* and an additional chip.
*
*
*/



//Pin Definitions
//The 74HC595 using a protocol called SPI (for more details http://www.arduino.cc/en/Tutorial/ShiftOut)
//Which has three pins
int data = 2;
int clock = 3;
int latch = 4;
//Used for single LED manipulation
int ledState = 0;
const int ON = HIGH;
const int OFF = LOW;
                
/*
* setup() – this function runs once when you turn your Arduino on
* We set the three control pins to outputs
*/
void setup()
{
  pinMode(data, OUTPUT);
  pinMode(clock, OUTPUT);
  pinMode(latch, OUTPUT);
}
/*
* loop() – this function will start after setup finishes and then repeat
* we set which LEDs we want on then call a routine which sends the states to the 74HC595
*/
void loop()                     // run over and over again
{
  int delayTime = 100; //the number of milliseconds to delay between LED updates
  for(int i = 0; i < 256; i++){
   updateLEDs(i);
   delay(delayTime);
  }
}
/*
* updateLEDs() - sends the LED states set in ledStates to the 74HC595
* sequence
*/
void updateLEDs(int value){
  digitalWrite(latch, LOW);     //Pulls the chips latch low
  shiftOut(data, clock, MSBFIRST, value); //Shifts out the 8 bits to the shift register
  digitalWrite(latch, HIGH);   //Pulls the latch high displaying the data
}
/*
* updateLEDsLong() - sends the LED states set in ledStates to the 74HC595
* sequence. Same as updateLEDs except the shifting out is done in software
* so you can see what is happening.
*/
void updateLEDsLong(int value){
  digitalWrite(latch, LOW);    //Pulls the chips latch low
  for(int i = 0; i < 8; i++){  //Will repeat 8 times (once for each bit)
  int bit = value & B10000000; //We use a "bitmask" to select only the eighth
                               //bit in our number (the one we are addressing this time through
  value = value << 1;          //we move our number up one bit value so next time bit 7 will be
                               //bit 8 and we will do our math on it
  if(bit == 128){digitalWrite(data, HIGH);} //if bit 8 is set then set our data pin high
  else{digitalWrite(data, LOW);}            //if bit 8 is unset then set the data pin low
  digitalWrite(clock, HIGH);                //the next three lines pulse the clock pin
  delay(1);
  digitalWrite(clock, LOW);
  }
  digitalWrite(latch, HIGH);  //pulls the latch high shifting our data into being displayed
}
//These are used in the bitwise math that we use to change individual LEDs
//For more details http://en.wikipedia.org/wiki/Bitwise_operation
int bits[] = {B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000};
int masks[] = {B11111110, B11111101, B11111011, B11110111, B11101111, B11011111, B10111111, B01111111};
/*
* changeLED(int led, int state) - changes an individual LED
* LEDs are 0 to 7 and state is either 0 - OFF or 1 - ON
*/
void changeLED(int led, int state){
   ledState = ledState & masks[led];  //clears ledState of the bit we are addressing
   if(state == ON){ledState = ledState | bits[led];} //if the bit is on we will add it to ledState
   updateLEDs(ledState);              //send the new LED state to the shift register
}

Tuesday, October 18, 2011

ARDUINO-Home Page

SUMMARY:

The ARDUINO-Home Page is a great website for starters; here, you can find all the information you need to learn and understand Arduino before working on the projects.

SITE SCREENSHOT:


SITE LINK:


REVIEW:

In this website, you can learn a number of things. For example,  you can learn what an Arduino is, what it can do for us, the different parts involved in Arduino, the software/hardware of Arduino and information about the Arduino team. You can also learn about the different Arduino distributors and manufacturing companies around the world. In addition, if you are interested in downloading Arduino software or buying Arduino kits then this website is just right for you.  

There is a “Getting Started with Arduino” section in this website which is my favorite section of the website because it includes some significant things you need to know before starting to do the Arduino labs. For instance, it includes:

·         Introduction: What is Arduino? Why would you want to use it?
·         Installation: Step-by-step instructions for setting up the Arduino software and connecting it to an Arduino Uno, Mega2560, Duemilanove, Mega, or Diecimila.
·         Environment: Description of the Arduino development environment.
·         Troubleshooting: What can you do if things don’t work out?
·         Instructions for other boards: How to use different types of Arduino boards?


The “Learning” section is also as great as the “Getting Started with Arduino” section. The “Learning” section includes a number of things as shown below:
·         Core Functions: Simple programs that demonstrate basic Arduino commands.
·         Basics: The very basic things that you can create with Arduino.
·         Digital: Digital things you can do with Arduino such as Blink without Delay, Button, Debounce, Tone, Pitch follower and etc.
·         Analog: AnalogInOutSerial, Analog Input, AnalogWriteMega, Calibration, Fading, Smoothing.
·         Communication: Includes examples with code that allows the Arduino to talk to Processing sketches running on the computer.
·         Control Structures: If Statement, For/While Loop, Switch Case, Switch Case 2.
·         Sensors: 4 different sensors.
·         Display: Examples of basic display control.
·         Strings: Different String Methods.

In the “Learning” section, there are also different libraries of Arduino software and different libraries of parts of Arduino. You will also find a “Language Reference” section in this site which is very useful for coding. Another section available in this site is the “Hardware” section which provides information of Official Arduino Boards and Official Arduino Shields. The very last section is the “FAQ” section where you will find the answers for questions you might be having about Arduino.


 

Saturday, October 15, 2011

Lab #1: CIRC-01: Blinking LED

Purpose: To emit light and produce a pleasant blinking effect using a LED and a 330 Ohm resistor.

 
Equipment(s):

-CIRC-01 Breadboard Sheet x1
-2 Pin Header x4
-5mm Yellow LED x1
-Wire
-330 Ohm Resistor (Orange-Orange-Brown) x1
Program Details:

         In this lab, the main component that was used is LED(Light Emitting Diode) that emits light when a small current is passed through it. This light emits in only one direction. The LED looks like a small light bulb. It has 2 leads; the longer lead is positive and the shorter is negative. One 330 Ohm Resistor (Orange-Orange-Brown) was also used along with 3 wires. The resistor restricts the amount of current that can flow through a circuit. It looks like a cylinder with wires extending from either end. The value is displayed using a colour coding system. In this case, the tolerance of the resistor is 20% according to the resistor colour code. Resistors are very fragile so you have to be extra carefull and delicate while using them.

       At the start of this lab, I was a little nervous because I had no previous experience with circuits. However, the lab was fairly easy and simple. At first, me and my partner read though the first pages in order to get familiar with the parts and to know its functions. We read the lab, understood it and got the parts required to create the circuit. Then, we built the circuit, analyzed the code and typed it up from the booklet excluding the comments. Lastly, we uploaded the code by connecting the USB to the computer and Arduino.

Time to Complete: 20mins

Results:

      Unfortunately, when we were uploading the program, it didn’t upload properly and the LED did not light up. We knew that LEDs only works in one direction so we tried taking it out and twisting it 180 degrees but it still didn't work. A moment later, we realized that there is no problem with the LED; there was a conflict uploading the program because we forgot to change our serial port from COM1 to COM5. Thus, we changed the serial port and, watched the LED turn on for one second, then turn off for one second, repeatedly.

Photo(s) of Project:

Blinking LED :)

Tips:

        Although, this lab is easy and simple to accomplish if you have no previous experience with Arduino then you might feel challenged. That’s why, I can advise all the starters to browse through the booklet, get familiar with the Arduino parts, understand the labs/projects and its expected outcome. This way, you can accomplish your goal easily and efficiently.

Further Work:

       If you want to make your project better and take it to the next level then you can try to do the following four things:

1)     Change the pin: -Plug in wire into any pin of your choice from pin 0-13 or analog 0-5.  -Change the code line and assign the new pin number to the ledPin variable.

2)     Change the blink time: Modify the delay time.

3)     Control the brightness: -Change the LED to pin9 (int ledPin = 9 ;)
                                           -Also change the wire)
                                                 -Replace the code inside the {}’s of loop ( ) with this:
                                                  analogWrite(ledPin, new number);
                                                  (new number) = any number between 0 and 225.
                                                  0 = off, 255 = on, in between = different brightness.

4)     Fading: -Go to File>Examples> 3.Analog>Fading
                -Upload it to your board

Program Modifications:  This program is the same as the one from the following link.
                                                           CLICK ME and I'll take you to the link!

Program with comments:

/*
  *Blink
  *Turns on an LED on for one second, then off for one second, repeatedly.
  *The circuit:
  * LED connected from digital pin 13 to ground.
  * Note: On most Arduino boards, there is already an LED on the board
  * connected to pin 13, so you don’t need any extra components for this example.

  *Created 1 June 2005
  *By David Cuartielles
  *http://arduino.cc/en/Tutorial/Blink
  *based on an orginal by H. Barragan for the Wiring i/o board
*/

int ledPin =  13;    // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

void setup()   {        
  // initialize the digital pin as an output:
  pinMode(ledPin, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()            
{
  digitalWrite(ledPin, HIGH);   // set the LED on
  delay(1000);                  // wait for a second
  digitalWrite(ledPin, LOW);    // set the LED off
  delay(1000);                  // wait for a second
}

Wednesday, October 5, 2011

Arduino Based CPU Temperature Sensor

Summary: Arduino can now monitor temperature of GPU using the RGB LED light indicator when hooked up to a temperature sensor and placed near the GPU.  



A gentle man named ,Taylor Niver bought a graphics card for his computer, his GPU started overheating since his energy suppy wasn't efficient enough to power up his new graphics card properly. Mr.Niver did not want a potentially burnt out GPU so he came up with his own temperature monitoring system. His system basically included Arduino, temperature sensor, and RGB LED light. He hooked up  the Arduino to the temperature sensor, which was placed near the GPU in order to monitor its temperature. The RGB LED light was used as an indicator to inform him the temperatures of his GPU.  He set the threshold at 50C. If the temperature went above 50C, the RGB LED turned red, indicating an overheat but if everything was normal the RGB LED stayed blue.

If you want to set up your own Arduino Based CPU Temperature Sensor then check out Taylor Niver's blog to get the instructions and code that he used to set it up!