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
}