Monday 5 December 2011

CIRC 04 (tiny.cc)

Purpose:
To rotate one, or a series of servo motors using one, or a series of potentiometers. To also output the position of the servos using 4 LEDs

Equipment:

  • Arduino x1
  • Breadboard x1
  • Pushbutton x 6
  • Servo x 6
  • 330 ohm resistor x4
  • LED x4
  • Wires
References:

Program Details: 
Building the circuit is not very complex. We built similar circuits like this before [2][3]. Also a picture of the circuit was provided [1]. Essentially this CIRC lab consists of 6 separate circuits, with 1 input and 5 output. The input is the resistnace reading from the potentiometer. The output is  



Program:
//PART 1

#include <Servo.h>
Servo servo;

int pos = 0;
int sensor = 0;

void setup()
{
  servo.attach(13);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
}

void loop()
{

  int value  = analogRead(sensor);

  value = map(value, 0, 1024, 0, 360);
  value = constrain(value, 0, 360);        //Sets value between 0 & 360

  delay(50);
  servo.write(value);                      //Sets  to desired position

  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);                    //Turns them off every time, to prevent stacking

  if (value == 0)
  {
    digitalWrite(2, HIGH);
  }
  else if (value == 90)
  {
    digitalWrite(3, HIGH);
  }
  else if (value == 180)
  {
    digitalWrite(4, HIGH);
  }
  else if (value == 270)
  {
    digitalWrite(5, HIGH);
  }
}

//Part 2

#include <Servo.h>

Servo rotator, joint1, joint2, joint3, wrist, gripper;
int sensorR = 0, sensorJ1 = 1, sensorJ2 = 2, sensorJ3 = 3, sensorW = 4, sensor = 5;
int valueR, valueJ1, valueJ2, valueJ3, valueW, valueG;


void setup()
{
  rotator.write(13);
  joint1.write(12);
  joint2.write(11);
  joint3.write(10);
  wrist.write(9);
  gripper.write(8);
}


void loop()
{
  delay(50);

  //Rotator
  valueR = analogRead(sensorR);  
  valueR = map(valueR, 0, 1024, 0, 360);
  valueR = constrain(valueR, 0, 360);        //Sets value between 0 & 360
  rotator.write(valueR);                  

  //Joint One
  valueJ1 = analogRead(sensorJ1);  
  valueJ1 = map(valueJ1, 0, 1024, 0, 360);
  valueJ1 = constrain(valueJ1, 0, 360);    
  joint1.write(valueJ1);                  

  //Joint Two
  valueJ2 = analogRead(sensorJ2);  
  valueJ2 = map(valueJ2, 0, 1024, 0, 360);
  valueJ2 = constrain(valueJ2, 0, 360);      
  joint2.write(valueJ2);                  

  //Joint Three
  valueJ3 = analogRead(sensorJ3);  
  valueJ3 = map(valueJ3, 0, 1024, 0, 360);
  valueJ3 = constrain(valueJ3, 0, 360);    
  joint3.write(valueJ3);                  

  //Wrist
  valueW = analogRead(sensorW);  
  valueW = map(valueW, 0, 1024, 0, 360);
  valueW = constrain(valueW, 0, 360);      
  wrist.write(valueW);                

  //Gripper
  valueG = analogRead(sensorG);  
  valueG = map(valueG, 0, 1024, 0, 360);
  valueG = constrain(valueG, 0, 360);        //Sets value between 0 & 360
  gripper.write(valueG);                  
}

Monday 28 November 2011

CIRC 03 (tiny.cc)

Purpose:
To control the speed of a motor via two pushbuttons. Then adding extensions to the program such as a series of LED's to tell the speed of the motor, and deceleration over time.

Equipment:

  • Breadboard x1
  • Arduino x1
  • Buttons x2
  • Motor x 1
  • 10k ohm resistor x3
  • Diode x1
  • Transistor x1
  • Wire x10
References:

Program Details:
The building itself is not very complicated, as a picture is provided at [1]. Furthermore we have already finished a very similar circuit layout before [2]. The only exception being that there are now 6 more independent circuits, w of which are to get button input, and another 4 output to the LEDs.

In terms of programming, Part 1 was rather simple. What the program in Part 1 does is access a custom method called buttonCheck(); which does as its name implies. After checking which button is being press, and that two buttons are not being press at once, it goes through one of two if statements. Depending on which button is pressed, the program will either accelerate or decelerate the motor. The while loops are in place to insure the value being supplied to the motor isn't greater than 255 or less than 0, as those are the motors max and min values. 

Part 2 is exactly like Part 1, except there is now another step added to the end called ledCheck(). This custom method checks the value for power (current speed) and lights the corresponding LED. Each LED is on its own circuit. The final part adds just one more line. This line reduces the power of the LED by 25% every half second, and is meant to simulate deceleration. It happens at the end of each loop().

Tips:

Further Work:
You could make it so double tapping a button causes either maximum speed or brings the motor to a halt.

Program:

//PART 1

int motorPin = 9;
int buttonA = 2;
int buttonB = 3;
int power = 0;
void setup()
{
    pinMode(motorPin, OUTPUT);
}
void loop()
{
  delay(100);
 
  int value = buttonCheck();
 
  if (value == 1)
  {
    while (power > 0)
    {
      power--;
    }
  }
 
  else if (value == 2)
  {
    while (power < 255)
    {
      power++;
    }
  }
  analogWrite(motorPin, power); 
}

int buttonCheck()
{
  int a;
 
  if ((digitalRead(buttonA) == LOW) && (digitalRead(buttonB) == HIGH))
  {
    a = 1;
  }
 
  else if ((digitalRead(buttonA) == HIGH) && (digitalRead(buttonB) == LOW))
  {
    a = 2;
  }
  return a;
}

//PART 2

int motorPin = 9;
int buttonA = 2;
int buttonB = 3;
int power = 0;
void setup()
{
    pinMode(motorPin, OUTPUT);
    pinMode(10, OUTPUT);
    pinMode(11, OUTPUT);
    pinMode(12, OUTPUT);
    pinMode(13, OUTPUT);
}
void loop()
{
  delay(100);
 
  int value = buttonCheck();
 
  if (value == 1)
  {
    while (power > 0)
    {
      power--;
    }
  }
 
  else if (value == 2)
  {
    while (power < 255)
    {
      power++;
    }
  }
  analogWrite(motorPin, power);

  ledCheck();
}
int buttonCheck()
{
  int a;
 
  if ((digitalRead(buttonA) == LOW) && (digitalRead(buttonB) == HIGH))
  {
    a = 1;
  }
 
  else if ((digitalRead(buttonA) == HIGH) && (digitalRead(buttonB) == LOW))
  {
    a = 2;
  }
  return a;
}
void ledCheck();
{
  digitalWrite(10,LOW);
  digitalWrite(11,LOW);
  digitalWrite(12,LOW);
  digitalWrite(13,LOW);
 
  if (power <= 64)
  {
    digitalWrite(10, HIGH);
  }
 
  else if ((power > 64) && (power <= 128))
  {
    digitalWrite(11, HIGH);
  }
 
  else if ((power > 128) && (power <= 192))
  {
    digitalWrite(12, HIGH);
  }
 
  else
  {
    digitalWrite(13, HIGH);
  }
}

//PART 3


int motorPin = 9;
int buttonA = 2;
int buttonB = 3;
int power = 0;
void setup()
{
    pinMode(motorPin, OUTPUT);
    pinMode(10, OUTPUT);
    pinMode(11, OUTPUT);
    pinMode(12, OUTPUT);
    pinMode(13, OUTPUT);
}
void loop()
{
  delay(100);
 
  int value = buttonCheck();
 
  if (value == 1)
  {
    while (power > 0)
    {
      power--;
    }
  }
 
  else if (value == 2)
  {
    while (power < 255)
    {
      power++;
    }
  }
  analogWrite(motorPin, power);
 
  power -= 5;                   //Power decreases by 5(1/5 of 25 as delay = 1/5 0.5)

  ledCheck();
}
int buttonCheck()
{
  int a;
 
  if ((digitalRead(buttonA) == LOW) && (digitalRead(buttonB) == HIGH))
  {
    a = 1;
  }
 
  else if ((digitalRead(buttonA) == HIGH) && (digitalRead(buttonB) == LOW))
  {
    a = 2;
  }
  return a;
}
void ledCheck();
{
  digitalWrite(10,LOW);
  digitalWrite(11,LOW);
  digitalWrite(12,LOW);
  digitalWrite(13,LOW);
 
  if (power <= 64)
  {
    digitalWrite(10, HIGH);
  }
 
  else if ((power > 64) && (power <= 128))
  {
    digitalWrite(11, HIGH);
  }
 
  else if ((power > 128) && (power <= 192))
  {
    digitalWrite(12, HIGH);
  }
 
  else
  {
    digitalWrite(13, HIGH);
  }
}

Tuesday 15 November 2011

Tiny.cc/ArdiunoGuide - Circ - 07

//PART 1
int ledPin [] = {13, 12, 11, 10};
int buttonA = 0, buttonB = 0, time = 500;

void setup()
{
  for (int i = 0; i < 4; i++)
  {
    pinMode(ledPin[i], OUTPUT);
  }
 
  pinMode (2, INPUT);
  pinMode (3, INPUT);
}

void loop()
{
  buttonA = digitalRead(2);
  buttonB = digitalRead(3);
 
    if ((buttonA == HIGH) && (buttonB == LOW))
    {
      evenLED();
    }
   
    else if ((buttonB == HIGH) && (buttonA == LOW))
    {
      oddLED();
    }
}

void evenLED()
{
  for(int i = 0; i < 4; i +=2)
  {
    digitalWrite(ledPin[i], HIGH);
    delay(time);
    digitalWrite(ledPin[i], LOW);
    delay(time);
  }
}

void oddLED()
{
  for(int i = 1; i < 4; i +=2)
  {
    digitalWrite(ledPin[i], HIGH);
    delay(time);
    digitalWrite(ledPin[i], LOW);
    delay(time);
  }
}
     
//PART 2
int ledPin [] = {13, 12, 11, 10};
int buttonA = 0, buttonB = 0;
int time = 500;
int counter;

void setup()
{
  for (int i = 0; i < 4; i++)
  {
    pinMode(ledPin[i], OUTPUT);
  }
 
  pinMode (2, INPUT);
  pinMode (3, INPUT);
}

void loop()
{
  buttonA = digitalRead(2);
  buttonB = digitalRead(3);
  counter = 0;
 
  while (!((buttonA == HIGH) && (buttonB == HIGH)))     //Will not run while both buttons are pressed
  {
    if ((buttonA == HIGH) && buttonB == HIGH))
    {
      counter++;
     
      digitalWrite(ledPin[0], HIGH);
      delay(time);
      digitalWrite(ledPin[0], LOW);
      delay(time);
    }
   
    else if ((buttonB == HIGH) && (buttonA == LOW))
    {
      if (counter > 4)
      {
        allLED();
      }
     
      else if (counter == 0)
      {
        delay(1000);
      }
     
      else
      {
        counter--;                        //For approptiat index
        digitalWrite(ledPin[counter], HIGH);
        delay (time);
        digitalWrite(ledPin[counter], LOW);
        delay (time);
      }
    }
  }
}

//PART 3

int ledPin [] = {13, 12, 11, 10};
int buttonA = 0, buttonB = 0, time = 500;
void allLED()
{
  for(int i = 0; i < 4; i++)
  {
    digitalWrite(ledPin[counter], HIGH);
  }
 
  delay(time);
 
  for(int i = 0; i < 4; i++)
  {
    digitalWrite(ledPin[counter], LOW);
  }
 
  delay(time);
}
int ledPin [] = {13, 12, 11, 10};
int buttonA = 0, buttonB = 0;
int time = 500;
int counter;

void setup()
{
  for (int i = 0; i < 4; i++)
  {
    pinMode(ledPin[i], OUTPUT);
  }
 
  pinMode (2, INPUT);
  pinMode (3, INPUT);
}

void loop()
{
  buttonA = digitalRead(2);
  buttonB = digitalRead(3);
  counter = 0;
 
  while (!((buttonA == HIGH) && (buttonB == HIGH)))     //Will not run while both buttons are pressed
  {
    if (buttonA == HIGH)
    {
      counter++;
     
      digitalWrite(ledPin[0], HIGH);
      delay(time);
      digitalWrite(ledPin[0], LOW);
      delay(time);
    }
   
    else if (buttonB == HIGH)
    {
      if (counter > 4)
      {
        allLED();
      }
     
      else if (counter == 0)
      {
        delay(1000);
      }
     
      else
      {
        counter--;                        //For approptiat index
        digitalWrite(ledPin[counter], HIGH);
        delay (time);
        digitalWrite(ledPin[counter], LOW);
        delay (time);
      }
    }
  }
}

void allLED()
{
  for(int i = 0; i < 4; i++)
  {
    digitalWrite(ledPin[counter], HIGH);
  }
 
  delay(time);
 
  for(int i = 0; i < 4; i++)
  {
    digitalWrite(ledPin[counter], LOW);
  }
 
  delay(time);
}

Sunday 6 November 2011

Top 40 Arduino Projects

This post was done in case the requirement was to do 4 different news blogs on top of our existing one. If that is not the case, please dismiss this post. Thank You.


Summary:
This page links to one of forty different Arduino Projects which we can try.

Photo:




Link:
http://hacknmod.com/hack/top-40-arduino-projects-of-the-web/

Review:
Though the site itself is not Arduino focused, it does have a focus on creating and modifying pieces of software or hardware. So naturally they do have some degree of coverage on Arduino. The page itself is a central hub which links to forty different pages, each with an extensive coverage of an Arduino project. The links themselves contain information on what you need to build it, and how you build it. Most cover both the hardware and the software aspect.

It is known that modifying existing projects is much easier than creating your own. We can apply this principle in our class, as now students will be able to learn more faster my modifying these existing experiments. This will help strengthen our knowledge in both the hardware and software aspects associated with working with Arduino. One aspect of this site which I enjoyed was that I was able to see how Arduino was being applied. The shear variety of uses I saw here expanded my thinking of what I can do with Arduino.

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