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.