Thursday 1 May 2008

Tuesday 29 April 2008

WEEK 4 - 2 Switches 2 LED's

This week we moved onto 2 switches to control 2 LEDs.
Here is an image of my completed circuit:

Here are 2 video's of the switches, notice they have different functions simply by making simple alterations to the code:

And finally here is the code used for the circuit:
int ledPin = 13; // choose the pin for the LED
int inPin = 2; //choose the input pin (for a pushbutton)
int ledPin2 = 10;
int inPin2 = 3;
int val = 0; //variable for reading the pin status
int val2 = 0; 

void setup() {
  pinMode (ledPin, OUTPUT); //declare LED as output
  pinMode (inPin, INPUT); //declare pushbutton as input
  pinMode (ledPin2, OUTPUT); //declare LED as output
  pinMode (inPin2, INPUT); //declare pushbutton as input
}
void loop() {
  val = digitalRead(inPin); //read input value
  if (val == HIGH) { //check if the input is HIGH (button Released)
  digitalWrite (ledPin, LOW); //turn LED OFF
  } else 
   digitalWrite (ledPin, HIGH); //turn LED ON

  val2 = digitalRead(inPin2); //read input value
  if (val2 == HIGH) { //check if the input is HIGH (button Released)
  digitalWrite (ledPin2, LOW); //turn LED OFF
  } else 
   digitalWrite (ledPin2, HIGH); //turn LED ON
 }

Week 3 - Switch



During this workshop we were instructed to create a circuit which and LED would be controlled by a switch. We were given a handout which gave some basic information on how switches work and how they are used. We were also introduced to resistors and also given brief information on their purpose.
Here are images of my completed circuit:

And here is a video of my working switch within the circuit:

On the worksheet we were provided with the code in order to make this circuit work:
int ledPin = 13;
int inPin = 2;
int val = 0;

void setup() {
  pinMode (ledPin, OUTPUT);
  pinMode (inPin, INPUT);
}

void loop () {
  val = digitalRead(inPin);
  if (val ==HIGH) {
  digitalWrite(ledPin, LOW);
  } else {
    digitalWrite (ledPin, HIGH);
  }
}

Monday 28 April 2008

Week 2 - Analogue Input Potentiometer


In week 2 we were instructed to create a circuit once again using a LED but this time with a Potentiometer. A potentiometer is a variable resistor which allows you to control the amount of current or voltage going through a particular circuit. The objective of this circuit was to control the speed of the blink the LED depending on the position of the potentiometer. 
Here are images and a video of my completed circuit:

The code used was taken from the arduino official website:
int potPin = 2;    // select the input pin for the potentiometer 
int ledPin = 13;   // select the pin for the LED 
int val = 0;       // variable to store the value coming from the sensor  

void setup() {  
 pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT 
 }  

 void loop() {   
 val = analogRead(potPin);    // read the value from the sensor   
 digitalWrite(ledPin, HIGH);  // turn the ledPin on   
 delay(val);                  // stop the program for some time   
 digitalWrite(ledPin, LOW);   // turn the ledPin off   
 delay(val);                  // stop the program for some time 
 }

Week 1 - Introduction



This was an introduction to the module, in the lecture we were presented with a 'What is Arduino?' worksheet. On this sheet it had links to websites thats contained information ontghe Arduino programming language and basic tutorials. These links were:

We were instructed to create a simple circuit which involved a LED and of course the arduino board.
Here is some images of my working circuit with a video:
The code for this circuit was obtained from the arduino software examples (File - Sketchbook - Examples -  Digital - Blink).
Here is the code used:
/*
 * Blink
 *
 * The basic Arduino example.  Turns on an LED on for one second,
 * then off for one second, and so on...  We use pin 13 because,
 * depending on your Arduino board, it has either a built-in LED
 * or a built-in resistor so that you need only an LED.
 *
 * http://www.arduino.cc/en/Tutorial/Blink
 */

int ledPin = 13;                // LED connected to digital pin 13

void setup()                    // run once, when the sketch starts
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop()                     // run over and over again
{
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(1000);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(1000);                  // waits for a second
}