rhoadley.net   music   research   courses   software   blogs

ARU    Seminars    Comp&Imp    NMP    CMC2a    CBHH
Sensor Technology    Sonic Art    Major Project    MA Resources


Resources:    Bioacoustics    Jitter    MaxMSP    OSC    Physical    PD       CBHH    sTech    SuperCollider    C/Xcode

sTech Resources:     Home     Blog     Forum     Examples     Projects     Tasks     Tutorials


Sensor Technology Tasks

Hello World

Task 1 Name: Hello World Set: w2i Due: Thursday 16th December 2010 Weighting: 0% Courses: stech
Prev Task: Next Task: Vibrating a Piezo
Task Summary All sTech tasks

Blink

"Hello World" for the Arduino - YouTube video of this exercise!

NB if you've decided to use another type of board, as long as you get a basically similar result, that's fine. We've looking here at simply familiarising yourself with the system of programming and editing.

Code for Processing/Arduino


/*
 * 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.
 * 
 * NB most LEDs have one leg shorter than the other.  This should be connected to ground.
 *
 * 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
}

Analogue in via Potentiometer


/*
 * AnalogInput
 * by DojoDave 
 * Mods by Richard Hoadley (http://rhoadley.org)
 *
 * Turns on and off a light emitting diode(LED) connected to digital  
 * pin 13. The amount of time the LED will be on and off depends on
 * the value obtained by analogRead(). In the easiest case we connect
 * a potentiometer to analog pin 2.
 *
 * NB Two outer connections of pot connect to 5v and ground of the Analogue inputs, 
 * the centre connection is for one of the analogue ins.  
 * In the code below, it's arbitrarily set to 2.
 *
 * http://www.arduino.cc/en/Tutorial/AnalogInput
 */

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
}

This is a very straightforward "Hello World" task - but there's plenty to go wrong especially if you're nervous!

Here's the original version:
http://www.arduino.cc/en/Tutorial/AnalogInput

Analogue Input

Another Version:
http://www.arduino.cc/en/Tutorial/AnalogInput

Analogue in via LDR


/*
 * AnalogInput
 * by DojoDave 
 *
 * Turns on and off a light emitting diode(LED) connected to digital  
 * pin 13. The amount of time the LED will be on and off depends on
 * the value obtained by analogRead(). In the easiest case we connect
 * a potentiometer to analog pin 2.
 * Connect an LDR to ground and analog pin 2.  The reading will depend 
 * on the range and type of range (linear or exponential) of the 
 * particular resistor you're using.
 *
 * based on:
 * http://www.arduino.cc/en/Tutorial/AnalogInput
 */

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
  val = (val*100);
  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
}

Analogue in with Print Line


/*
 * AnalogInput
 * by DojoDave 
 * Additions by Richard Hoadley 2009
 *
 * Turns on and off a light emitting diode(LED) connected to digital  
 * pin 13. The amount of time the LED will be on and off depends on
 * the value obtained by analogRead(). In the easiest case we connect
 * a potentiometer to analog pin 2.
 * Connect an LDR to ground and analog pin 2.  The reading will depend 
 * on the range and type of range (linear or exponential) of the 
 * particular resistor you're using.
 *
 * Serial.Println is useful for displaying the values themselves,
 * although again, the legibility of the value will depend on its type.
 * To display the value, you need to use the serial monitor button in
 * the task bar above (last button on right).
 *
 * based on:
 * http://www.arduino.cc/en/Tutorial/AnalogInput
 */

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
  Serial.begin(9600); // Open the serial port at 9600 bps
}

void loop() {
  val = analogRead(potPin);    // read the value from the sensor
  Serial.println(val);        // print 'val' (see reference)
  digitalWrite(ledPin, HIGH);  // turn the ledPin on
  delay(100);                  // stop the program for some time
  digitalWrite(ledPin, LOW);   // turn the ledPin off
  delay(100);                  // stop the program for some time
}


To Cover





to top of page The Task

  • Make sure you do the above. Not just once, but a number of times through the week. At least twice. You need to do it enough so that you feel reasonably comfortable and confident.

  • Clearly, I don't want you to submit your Arduinos. That means you need to submit some documentary evidence that you've completed your task. The most obvious way to do this is to submit some sort of video of your task working, as well as of the code running. If you can't do this, take photos.

  • Media files
    You must submit media files, such as video, audio or image files, but please ensure that video files are compressed to a reasonable degree. You should never submit dv files, but compress these to mp4. You should submit no file that is greater in size than 25MB/minute.

  • Added value
    By completing the details of the task you will achieve at least a pass mark. By imaginatively and creatively considering how you might implement the task originally you can add value to your submission, and this added value may increase your mark significantly. Even when making videos of short demonstration tasks try to consider musical and performance criteria.

  • Bearing this in mind, try to adapt and make more interesting your files. Simply repeating what we've already done will get minimal marks. So try each patch out in various ways. Even if it's just a blinking LED, try using patterns of colours and/or timings.

  • Compress (zip) your patches, demos, etc. into one file called your_student_number_"helloworld" (e.g. 0504335_helloworld.zip), include a readme with your name and student number and, if necessary, how to use or just open the patch.

  • Submit a copy of the files to the i-Centre on Thursday 15th December 2011

You might also be interested in:


The Projects

The projects and tasks are designed to help you through the various courses and materials that you'll have to deal with, and also to provide an active and practical element to what could otherwise become a rather dry and technical exercise. Tasks are small exercises - you may be asked to complete one or two per week. Projects are larger and carry a higher percentage of the mark. We will undertake two, three, four or more projects and tasks. The final project is usually an individual choice project, and will be worth significantly more than the others in terms of percentages in your portfolio. We will usually try to set aside a time to perform the projects in a public setting.