Tuesday, 1 November 2011

CIRC-11: Relays

Purpose: 
Use the relay to light up 2 LEDs in a simple sequence

Equipment:
•1 x Arduino Uno
•1 x Breadboard
•14 x Wire
•1 x 1N4001
•1 x Transistor
•1 x Relay DPDT
•1 x 560 Ohm Resistor
•1 x 2.2k Ohm Resistor
•2 x LED

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

Program Details: 
There's no new content in the code compared to the other labs


Time to Complete: 
 15 minutes


Results:
The relay used was different than the one on the breadboard sheet, a few wires had to be moved to get one of the LEDs into the circuit. After moving the wires, the relay would perform a constant clicking sound and light up the LEDs one at a time.

Photos of Project: 




Tips:
Check to see if the relay is the same as the one in the breadboard sheet.

Further Work:
Instead of LEDs, we can use motors.

Program Modifications:
The program is exactly the one from http://www.oomlout.com/a/products/ardx/circ-11

int ledPin =  2;    // pin that the LED is connected to

void setup()  
{             
    pinMode(ledPin, OUTPUT);    //initializes pin 2 as an output
}

void loop()                    //Continuously runs
{
  digitalWrite(ledPin, HIGH);   // set the state of ledPin to high(on)
  delay(1000);                  // delay for 1000ms
  digitalWrite(ledPin, LOW);    // set the state of ledPin to low(off)
  delay(1000);                  // delay for 1000ms
}

CIRC-10: Temperature

Purpose: 
Get a measurement of temperature with the TMP36 sensor.

Equipment:
•1 x Arduino Uno
•1 x Breadboard
•5 x Wire
•1 x TMP36 Temperature Sensor


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

Program Details: 
The program in this lab introduces serial connection.

Time to Complete: 
 20 minutes

Results:
This lab was a failure. The temperature was not outputted. In an attempt to change the temperature value, one of my group members tried to pinch the sensor to heat it up. He then found out it was ridiculously hot and burned himself. We suspect the temperature sensor to be faulty.

Photos of Project: 




Tips:
This lab taught us about safety. Remember to work with the Arduino hardware cautiously and carefully.

Further Work:
A simple calculation can be added to show the temperature in fahrenheit instead of celsius.

Program Modifications:
The program is exactly the one from http://www.oomlout.com/a/products/ardx/circ-10

Program:
int temperaturePin = 0; //sets the pin the sensor is connected to
      
void setup()
{
  Serial.begin(9600);  //Start a serial connection
  
}
void loop()                     // continuously runs
{
//calls the function and sends it parameters
float temperature = getVoltage(temperaturePin);  
temperature = (temperature – .5) * 100;          //converts the value of temperature
Serial.println(temperature);                    //outputs the value of temperature
delay(1000);                                     //delay of 1000ms
}
//creates function of return type float with one parameter
float getVoltage(int pin)                      
{
//returns the value back to the variable, temperature
return (analogRead(pin) * .004882814);                                     
}

CIRC-09: Photo-Resistors

Purpose: 
Adjust the brightness of an LED with the photo-resistor by the amount of light that comes in contact.

Equipment:
•1 x Arduino Uno
•1 x Breadboard
•6 x Wire
•1 x Photo-Resistor
•1 x 560 Ohm Resistor
•1 x 10k Ohm Resistor
•1 x LED

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

Program Details: 
The code for this lab is identical to CIRC-08. No new concepts are present.

Time to Complete: 
 15 minutes

Results:
The LED was brighter with the exposure to light. The lab worked without a problem.

Photos of Project: 




Tips:
The two different resistors belong in two different places. Make sure you don't mix them up.

Further Work:
Create different actions for different thresholds. For example, blinking when exposed to no light, off when exposed to light.

Program Modifications:
The program is exactly the one from http://www.oomlout.com/a/products/ardx/circ-09

Program:
int sensorPin = 0;    // the pin the sensor is connected to
int ledPin = 13;      // the pin the LED is connected to
int sensorValue = 0;  // a variable to hold the state of the sensor
void setup()
{
  pinMode(ledPin, OUTPUT);  //initialize pin 13 as an output
}
void loop()
 {
  //reads the value from the sensor and sets it to sensorValue
  sensorValue = analogRead(sensorPin);    
  digitalWrite(ledPin, HIGH);  //sets the state of ledPin to high(on)
  delay(sensorValue);          //delay equal to the value of sensorValue
  digitalWrite(ledPin, LOW);  //sets the state of ledPin to low(off)
  delay(sensorValue);         //delay equal to the value of sensorValue

 }

CIRC-08: Potentiometers

Purpose: 
Adjust the brightness of an LED with the potentiometer threshold.

Equipment:
•1 x Arduino Uno
•1 x Breadboard
•6 x Wire
•1 x Potentiometer 10k  Ohm
•1 x 560 Ohm Resistor
•1 x LED


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

Program Details: 
No new concepts in the code for this lab.

Time to Complete: 
15 minutes

Results:
No problems with this lab, the brightness of the LED increases when the potentiometer is turned clockwise.


Photos of Project: 




Tips:
Make sure the potentiometer is in the right way. If nothing is happening, flip it 180 degrees.


Further Work:
Make the LED to turn off after a certain degree on the potentiometer.

Program Modifications:
The program is exactly the one from http://www.oomlout.com/a/products/ardx/circ-08

Program:
int sensorPin = 0;    // the pin the sensor is connected to
int ledPin = 13;      // the pin the LED is connected to
int sensorValue = 0;  // a variable to hold the state of the sensor
void setup()
{
  pinMode(ledPin, OUTPUT);  //initialize pin 13 as an output
}
void loop()
 {
  //reads the value from the sensor and sets it to sensorValue
  sensorValue = analogRead(sensorPin);    
  digitalWrite(ledPin, HIGH);  //sets the state of ledPin to high(on)
  delay(sensorValue);          //delay equal to the value of sensorValue
  digitalWrite(ledPin, LOW);  //sets the state of ledPin to low(off)
  delay(sensorValue);         //delay equal to the value of sensorValue    
 }

CIRC-07: Pushbuttons

Purpose: 
Turn on an LED by holding down a push button.


Equipment:
•1 x Arduino Uno
•1 x Breadboard
•7 x Wire
•2 x Pushbutton
•1 x LED
•1 x 560 Ohm Resistor
•2 x 10k Ohm Resistor

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

Program Details: 
Pushbuttons are initialized the same way LEDs are.

Time to Complete: 
25 minutes

Results:
The first pushbutton lit up the LED when held down. However, the second pushbutton did not do anything.

Photos of Project: 


Tips:
Pushbuttons can be misplaced on the breadboard. If nothing is happening, try rotating your pushbuttons 90 degrees.

Further Work:
Code can be added to make the second pushbutton have a function.

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

Program:
const int buttonPin = 2;     // sets the pin the button is connected to as a constant
const int ledPin =  13;      // sets the pin the LED is connected to as a constant
int buttonState = 0;         // int for reading state of button
void setup()
{
  pinMode(ledPin, OUTPUT); //initializes pin 13 as an output 
  pinMode(buttonPin, INPUT);   //initializes pin 2 as an input  
}
void loop()
 {
  //reads the state of the button and assigns it to buttonState
  buttonState = digitalRead(buttonPin);        

  if (buttonState == HIGH) {  //checks if the button is pushed then the LED will go on
     digitalWrite(ledPin, HIGH);
  }
  else {                     //if not the LED will go off
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

CIRC-06: Piezo Speaker

Purpose: 
Make the speaker play a simple tune using a range of frequencies.

Equipment:
•1 x Arduino Uno
•1 x Breadboard
•4 x Wire
•1 x Piezo Element

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

Program Details: 
The same concepts are used, but for a different purpose for this lab. The initializing and loops are usually for the LED. This time, those simple concepts are used to play notes in a loop and initialize the speaker.

Time to Complete: 
10 minutes

Results:
The speaker in our Arduino set was not functioning properly. When we switched the speakers from another kit, the music began to play.

Photos of Project: 




Tips:
The speaker can be easily misplaced in the wrong holes. Double check to see if they are placed correctly.

Further Work:
We can attempt to use the creative part our minds and code a new song by using the different frequencies.

Program Modifications:
The program is exactly the one from http://www.oomlout.com/a/products/ardx/circ-06

Program:
int speakerPin = 9;
int length = 15; // the number of notes
char notes[] = “ccggaagffeeddc “; // creates an array of type char
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 }; /*creates an array of type int */
int tempo = 300;

void playTone(int tone, int duration) /* creates a function, playTone that has to parameters of type int */
 {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);      //changes state of speakerPin to high
    delayMicroseconds(tone);             //delay equal to the value of tone
    digitalWrite(speakerPin, LOW); //changes state of speakerPin to low
    delayMicroseconds(tone);             //delay equal to the value of tone
  }
}
void playNote(char note, int duration) {
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

  // play the tone corresponding to the note name
  for (int i = 0; i < 8; i++) {
    if (names[i] == note) {
      playTone(tones[i], duration);      //send tones at i  and duration to playRone
    }
  }
}
void setup() {
  pinMode(speakerPin, OUTPUT);           //initializes pin 9 as an output
}
void loop() {
  for (int i = 0; i < length; i++) {
    if (notes[i] == ' ') {
      delay(beats[i] * tempo); // rest
    } else {
      playNote(notes[i], beats[i] * tempo);  //sends as parameters for playNote
    }


    delay(tempo / 2);
  }
}

CIRC-05: 74HC595 Shift Registers

Purpose: 
Get 8 LEDs to light up in a sequence using a shift register.


Equipment:
•1 x Arduino Uno
•1 x Breadboard
•20 x Wire
•8 x LED
•1 x Shift Register 74HC959
•8 x 560 Ohm Resistor

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

Program Details: 
Shift register and shift bit values were introduced in the code.

Time to Complete: 
25 minutes

Results:
The circuit was built and the code was created, but it didn't work. After inspecting the circuit, we found that the 5V and ground wires were switched around by accident. Once the wires were changed, the LEDs lit up in  a sequence.

Photos of Project: 



Tips:
Again, watch out for the positive and negative parts of the LED. There's many parts to this lab, try to put the same piece of equipment consistently spaced out.

Further Work:
Make a different sequence rather than the one provided by the website.


Program Modifications:
The program is exactly the one from http://www.oomlout.com/a/products/ardx/circ-05

Program:

//used to set three control pins
int data = 2;
int clock = 3;
int latch = 4;

//Sets to variables as constants
int ledState = 0;
const int ON = HIGH;
const int OFF = LOW;
                        
//initializes the three control pins as outputs
void setup()
{
  pinMode(data, OUTPUT);
  pinMode(clock, OUTPUT);
  pinMode(latch, OUTPUT);
}

void loop()                     // continuously runs
{
  int delayTime = 100; //sets a delay time
  for(int i = 0; i < 256; i++){
   updateLEDs(i);
   delay(delayTime); //delay equal to the value of delayTime
  }
}

/*creates a void-type function, updateLEDs. Which Receives a parameter of type int from loop()*/
void updateLEDs(int value){
  digitalWrite(latch, LOW);     //changes the state of latch to low
  shiftOut(data, clock, MSBFIRST, value);
  digitalWrite(latch, HIGH);   // changes the state of latch to high
}

void updateLEDsLong(int value){
  digitalWrite(latch, LOW);    //changes the state of latch to low
  for(int i = 0; i < 8; i++){  //loop that will repeat 8 times
  int bit = value & B10000000;
                     
  value = value << 1;          
                     
  if(bit == 128){digitalWrite(data, HIGH);} /*if bit is set to 128 then the state of data will be changed to HIGH */
  else{digitalWrite(data, LOW);}            /*if bit isn't set to 128 then the state of data will be changed to LOW */
  digitalWrite(clock, HIGH);                //sets the state of clock to High
  delay(1);
  digitalWrite(clock, LOW);          //sets the state of clock to High
  }
  digitalWrite(latch, HIGH);  ////sets the state of latch to High }

//Creates an array, bits
int bits[] = {B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000};
//Creates an array, marks
int masks[] = {B11111110, B11111101, B11111011, B11110111, B11101111, B11011111, B10111111, B01111111};

//Creates a void-type function with to int type parameters
void changeLED(int led, int state){
   ledState = ledState & masks[led];  
   if(state == ON){ledState = ledState | bits[led];}
   updateLEDs(ledState);              //sends ledState to updateLEDs
}