Monday, October 31, 2011

Temperature (CIRC-10)

PURPOSE:

To measure the temperature with a complicated IC (integrated circuit).

EQUIPMENT:
·         1 x TMP36 Temperature Sensor
·         1 x CIRC-10 Breadboard Sheet
·         5 x Wire (any colour)
·         1 x Arduino Holder
·         1 x Arduino
·         1 x Breadboard

PROGRAM DETAILS:


A Temperature Sensor. (Image link)

In this circuit experiment, the phenomena we measure with our Arduino is the temperature with the help of a device called IC (integrated circuit). It is very similar looking to our P2N2222AG transistors. It has three pin’s, ground, signal and =5 volts, and is easy to use. It can output 10 millivolts per degree centigrade on the signal pin. There is a 500 mV offset to allow measuring temperatures below the freezing level.

This is the first circuit so far that uses the Arduino’s IDE serial monitor. In the code, the Serial.begin(number) method is used to make a serial connection with the computer. This method also helps determine the speed at which the Arduino sends information, and how fast the computer reads it. A speed of 9600 kilobits per second is chosen to read information because 9600 kilobits/second is the fastest speed at which the Arduino can read information. The Serial.println(temperature) is another method used to program this circuit. This method prints the received information (results) on to the serial monitor. Moreover, some mathematical operations and calculations are done in this circuit to convert temperature units. The variable float is also introduced here for floating point math (decimals). It takes 4 bytes of RAM and has a range between -3.4028235E+38 and 3.4028235E+38.

As a final point, we put the circuits together simply. We gathered the parts we need. Picking the temperature sensor was a little confusing since it’s identical to the P2N2222AG transistor so, we checked to see if the chip has a TMP36 printed on it or not. The wiring was done as instructed in the CIRC-10 Breadboard Sheet.

TIME TO COMPLETE:

4 minutes to build, 10 minutes to program.

RESULTS:


Monitor showing the temperature errors
Our programming took over 10 minutes because our Temperature Sensor wasn’t working properly. At first, when the program was running it was giving us really low negative numbers starting from -50 and it went up to +200. So we quickly took out the temperature sensor, keeping in mind that it can burn our hand since it’s too hot. Then we replaced the previous temperature sensor with a new temperature sensor. We did this 3 times in total but still unexpected, undesired degrees were outputted on the monitor. At last, Mr. Kee came in and concluded that it won’t work because of some unknown programs with the temperature sensor.


PHOTOS OF PROJECT:

CIRC-10 Arduino Circuit

TIPS:

1)      Sometimes, gibberish is displayed on the screen because the serial monitor is receiving data at a different speed than expected. To fix this issue, mouse click the pull-down box that reads “*** baud* and change it to “9600 baud”.

2)      If temperature value is unchanging, try pinching the temperature sensor with your fingers to heat it up or press a bag of ice against it to cool it down.

3)      When working with a partner or in a team, one must be co-operative, responsible and reliable. He/she should also have patience, teamwork skills and excellent communication skills. If you carry these qualities in you then you can work on anything with anyone, anywhere at any time!

FURTHER WORK:

There are four awesome things you can do to make your program better such as, Outputting voltage, Outputting degrees Fahrenheit, More information output, and Changing the serial speed. I would like to output degrees Fahrenheit and to do this, I need to use the formula (F = C * 1.8) + 32. I would also have to add the line temperature = (((temperature – 0.5) * 100)*1.8) + 32; before Serial.println(temperature);.

PROGRAM MODIFICATIONS:

My program is identical to the program from:

PROGRAM (with comments):

/*     ---------------------------------------------------------
 *     |  Arduino Experimentation Kit Example Code             |
 *     |  CIRC-10 .: Temperature :. (TMP36 Temperature Sensor) |
 *     ---------------------------------------------------------
 *  
 *  A simple program to output the current temperature to the IDE's debug window
 *
 *  For more details on this circuit: http://tinyurl.com/c89tvd
 */

//TMP36 Pin Variables
int temperaturePin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
                        //the resolution is 10 mV / degree centigrade
                        //(500 mV offset) to make negative temperatures an option

/*
 * setup() - this function runs once when you turn your Arduino on
 * We initialize the serial connection with the computer
 */
void setup()
{
  Serial.begin(9600);  //Start the serial connection with the copmuter
                       //to view the result open the serial monitor
                       //last button beneath the file bar (looks like a box with an antenae)
}

void loop()                     // run over and over again
{
 float temperature = getVoltage(temperaturePin);  //getting the voltage reading from the temperature sensor
 temperature = (temperature - .5) * 100;          //converting from 10 mv per degree wit 500 mV offset
                                                  //to degrees ((volatge - 500mV) times 100)
 Serial.println(temperature);                     //printing the result
 delay(1000);                                     //waiting a second
}

/*
 * getVoltage() - returns the voltage on the analog input defined by
 * pin
 */
float getVoltage(int pin){
 return (analogRead(pin) * .004882814); //converting from a 0 to 1024 digital range
                                        // to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
}

REFERENCE:

Sparkfun Inventor’s Guide. Page 26 and 27.




Light (CIRC-09)

PURPOSE:

To turn a LED on using a Photo Resistor (light based resistance). 

EQUIPMENT:

·         1 x Photo-Resistor
·         1 x Yellow LED
·         1 x 10k Ohm Resistor
·         1 x 330 Ohm Resistor
·         1 x CIRC-09 Breadboard Sheet
·         6 x Wire (any colour)

PROGRAM DETAILS:

A Photo Resistor (Image Link)

The new part introduced in this program is called the photo resistor which is a light based resistance. Photo resistor is a device that produces a variable resistance dependant on the on the amount of incident light. It has 2 leads and it looks like a little disk with a transparent top and a curvy line underneath. They are good for environmentally controlled experiments. The principles we use for a photo resistor is same as the potentiometer’s principles except the fact that a photo resistor is light based whereas, the potentiometer is a twist based resistance.

In terms of coding, no new methods were introduced. What the program did is simply change the intensity of an LED based on the amount of light incident on the photo resistor. For this circuit, the pin the led got connected to is pin 9 because here, we are controlling brightness so we use one of the PWM (Pulse Width Modulation Pins).  The methods analogRead() and analogWrite() were also used in this lab to read/write the light level.

With the help of the CIRC-09 Breadboard Sheet, we put together this simple circuit. The Arduino Uno senses voltage and it can’t directly sense resistance so we had to set up a voltage divider. The voltage at the sensing pin is always assessable, but our purpose is sensing relative light so we experimented with the values to see what works for us.

TIME TO COMPLETE:

It took us exactly 8 minutes to build the circuit and about 6 minutes to code.

RESULTS:

The circuit was set up well and the program was coded, downloaded the right way. Hence, our circuit worked effectively in our first try. A low value occurred when the sensor was well lit and a high value occurred when it was in darkness.

PHOTOS OF PROJECT:


Due to the lack of Varshini's photography skills,
the LED in the above pictures is not lighting up.
TIPS:

Don’t forget that a photo resistor needs to be in a voltage divider before it provides a useful input.

After you program your circuit, if the LED remains dark then pull it up and give it a twist.

If you're in a room that is either too bright or dark, your circuit might not work. Try turning the light on or off to see if it works or, take a flashlight and give that a try.

FURTHER WORK:

To make my program better, I would like to reverse the response of the circuit. This can be easily done by changing the analogWrite(ledPin, lightLevel); -----> analogWrite(ledPin, 225 - lightLevel); . In addition, rather than controlling the brightness of the LED in response to light, I would like to turn it on and off based on a threshold value. This can be obtained by changing the loop() code with:

void loop()
 {
    int threshold = 300;
    if(analogRead(lightPin) > threshold){
       digitalWrite(ledPin, HIGH);
    }else{
       digitalWrite(ledPin, LOW);
    }
}
  
PROGRAM MODIFICATIONS:

My program is exactly the same as the one from:

PROGRAM (with comments):

/*
 * A simple programme that will change the intensity of
 * an LED based  * on the amount of light incident on
 * the photo resistor.
 *
 */

//PhotoResistor Pin
int lightPin = 0; //the analog pin the photoresistor is
                  //connected to
                  //the photoresistor is not calibrated to any units so
                  //this is simply a raw sensor value (relative light)
//LED Pin
int ledPin = 9;   //the pin the LED is connected to
                  //we are controlling brightness so
                  //we use one of the PWM (pulse width
                  // modulation pins)
void setup()
{
  pinMode(ledPin, OUTPUT); //sets the led pin to output
}
 /*
 * loop() - this function will start after setup
 * finishes and then repeat
 */
void loop()
{
 int lightLevel = analogRead(lightPin); //Read the
                                        // lightlevel
 lightLevel = map(lightLevel, 0, 900, 0, 255);
         //adjust the value 0 to 900 to
         //span 0 to 255



 lightLevel = constrain(lightLevel, 0, 255);//make sure the
                                           //value is betwween
                                           //0 and 255
 analogWrite(ledPin, lightLevel);  //write the value
}

REFERENCE:
·         http://ardx.org/VODI
·         http://ardx.org/VIDE09


Sunday, October 30, 2011

Twisting (CIRC-08)

PURPOSE:

To turn on and off a LED by using the potentiometer.

EQUIPMENT:
  • 1 x Yellow LED
  • 1 x Potentiometer (10k ohm)
  • 1 x 330 Ohm Resistor (Orange-Orange-Brown)
  • 6 x Wire (any colour)
  • 1 x CIRC-08 Breadboard Sheet
  • 1 x Arduino Uno
  • 1 x Arduino Holder
  • 1 x Breadbaord
PROGRAM DETAILS:

In this circuit lab, a potentiometer was introduced. A potentiometer is an useful device that provides a variable resistance dependant on the angle to which it turns. An Arduino microcontroller has digital pins and 6 analog pins for analog input. These inputs take in a volt of 0-5 and convert it to a digital number between 0 and 1024. The potentiometer is called called a variable resistor. If connected with 5V across its outer pins the middle pin will give some value between 0 and 5 volts dependant on the angular location of the shaft (e.g. 2.5V in the middle). The returned values can be used as a variable in the program.

In the programming part, we learned how to deal with things that aren't digital. Although, the Arduino is a digital machine, it has the ability to operate with the analog pins and inputs. The analogRead(pin) method was used in this lab. When the analog input pins are set to input you can read their voltage which is a integer between 0(0 volts) and 1024(5volts). Therefore, this method gave a value which helped to determine the amount of time the LED should be on and off.

Simple circuits can sometimes be a headache while you attach the parts on to the breadboard. So we chose to start off with the main component (for this lab, it's the potentiometer) and we left  the wiring for the very last. We studied the schematic diagram at the start as well , as we knew that it will give us a better understanding of the current flow path in our circuit.

Fritzing Diagram of CIRC-08. (Image Link)
Click ME for the Image Link!
TIME TO COMPLETE:

7 minutes to build, 5 minutes to program.

RESULTS:

Our potentiometer was not working from time to time. We guessed that it was most likely due to a slightly dodgy connection with the potentiometer's pins. So we taped the potentiometer down to obtain better connections. Afterwards, it worked successfully and the yellow LED turned on and off as it was programmed to do so.

PHOTOS OF PROJECT:

Ultimate Functional Twisting Circuit (CIRC-08)
TIPS:

Things not working out? Check to see if you have accidentally connected the potentiometer's wiper to digital pin 2, rather than analog pin 2.

Still backward? You can try operating your circuit upside down because sometimes this helps.

FURTHER WORK:

There are two things I would like to try to expand my knowledge on this circuit lab:

1) Threshold switching: Switching an output when a value exceeds a specific threshold. This can be done with a potentiometer by changing the loop() code to:
void loop() {
   int threshold = 512;
   if(analogRead(sensorPin)> threshold){
digitalWrite(ledPin, HIGH);}
   else{digitalWrite(ledPin, LOW);}
}
   
This will make the LED turn on when the value is above 512(hallway), sensitivity can be adjusted by changing the threshold value.

2)Fading: Controlling brightness of LED directly from the potentiometer. To do this the pin the LED is connected to must be moved ( for instance, moving the wire from pin 13 to pin 9 will do so). Then I need to change only one line of code. int ledPin = 13; -----> int ledPin = 9; Lastly, the loop code needs to be modified to the follwoing:
void loop() {
   int value = analogRead(potPin) / 4;
   analogWrite(ledPin, value);
}
The above codes will make the LED fade in relation to our potentiometer spining.

PROGRAM MODIFICATIONS:

My program is the very same as the one in the Sparkfun Inventor's Guide (Pg. 22 and 23).
It's also the same as the one in this LINK.

PROGRAM (with comments):

*/
int sensorPin = 0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor
void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT); 
}
void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);   
  // turn the ledPin on
  digitalWrite(ledPin, HIGH); 
  // stop the program for milliseconds:
  delay(sensorValue);         
  // turn the ledPin off:       
  digitalWrite(ledPin, LOW); 
  // stop the program for for milliseconds:
  delay(sensorValue);                 
}

REFERENCE: 




Button Pressing (CIRC-07)

PURPOSE:

The purpose of this circuit experiment is to turn a LED on and off via a pushbutton.

EQUIPMENT:
·         1 x Arduino Holder
·         1 x Arduino Uno
·         1 x Arduino Breadboard
·         1 x Breadboard Sheet (CIRC-07)
·         1 x 330 Ohm Resistor (Orange-orange-Brown)
·         1 x 10k Ohm Resistor (Brown-Black-Orange)
·         2 x Pushbutton
·         1 LED (Red or Yellow)
·         7 x Wire (any colour)

PROGRAM DETAILS:

The new component of hardware introduced in this program is called the Pushbutton which is a device controlled by the user. When pressed, the pushbutton completes a circuit, and it can complete up to two different circuits. It looks like a small black square with four silver leads out
at the bottom and a button on the top.

This is the first lab where the pinMode is set to INPUT. The pinMode(pin, INPUT) code line  declares pushbutton as input. Here, the Arduino takes in an input so we must use the digitalRead(pin) method, rather than digitalWirte(pin). The method digitalRead(pin) returns whether it is HIGH(pulled to +5volts) or LOW(pulled to ground).

Putting this circuit together and wiring up the pushbutton was fairly easy.  However, the component, pull up resistor can seem out of place at times. The pull up resistor is included in the circuit because the Arduino Uno doesn’t sense the same way humans do. Instead it requires checking the voltage on the pin and then it decides whether it is HIGH or LOW. The button is set up so that when pressed, the Arduino’s pin can be pulled to LOW. When unpressed, the voltage of the pin will float and this can cause occasional errors. To make the Arduino read the pin as HIGH when the pushbutton is unpressed, the pull up resistor was added.

TIME TO COMPLETE:

10 minutes to build the circuit, 7 minutes to code.

RESULTS:

In our first try, the LED was not turning on. The pushbutton is a small square which is why it’s very easy to attach it to the breadboard in the wrong way. Since we attached it in the wrong way, the LED didn’t blink so we gave it a 90 degree twist and then, it worked as it was supposed to.
PHOTOS OF PROJECT:


Final CIRC-07 Circuit
 TIPS:

The first tip I would give is when you press the pushbutton, make sure you press it hard or else the circuit won’t be complete. Another tip is that you should be carefully choosing the Ohm Resistors. Since there are two different types of resistor (10k and 330) involved in this circuit, you might confuse yourself and choose the wrong one.

FURTHER WORK:

To make the program better and a little more complicated, I can make one button turn the LED on and the other button will turn the LED off. This can be done by changing the code to:  

int ledPin = 13; // choose the pin for the LED
int inputPin1 = 3; // button 1
int inputPin2 = 2; // button 2
 
void setup() {
  pinMode(ledPin, OUTPUT); // declare LED as output
  pinMode(inputPin1, INPUT); // make button 1 an input
  pinMode(inputPin2, INPUT); // make button 2 an input
}
 
void loop(){
  if (digitalRead(inputPin1) == LOW) {
    digitalWrite(ledPin, LOW); // turn LED OFF
  } else if (digitalRead(inputPin2) == LOW) {
    digitalWrite(ledPin, HIGH); // turn LED ON
  }
}

PROGRAM MODIFICATIONS:

My program looks same as the one from:http://www.oomlout.com/a/products/ardx/circ-07

PROGRAM (with comments):

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
    }
}

REFERENCE:

3.      http://www.0j0.org