Week 2: Oomlout’s Getting started guide – Single LED

Arduino Massive LED
Oomlout logo
Oomlout logo

Following on from Week 1 and talking about faking it with an Arduino, we will use UnoArduSim.exe and iCircuit to model the first few circuits from the Oomlout.com’s “Experimenter’s Guide for Arduino” (Full kit was available from here).

Oomlout have made the ARDX-circuit-sheets available separately to their guide PDF.

Circuit 01:

Using the circuit sheet as a guide, we will wire it up in the iCircuit simulator, UnoArduSim and Fitzing

/*
  Blink
  
  Turns an LED on for one second, then off for one second, repeatedly.
  
  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO it is attached to digital pin 13, on MKR1000 on pin 6. 

  on a Physical board LED_BUILTIN is set to the correct LED pin independent of which board is used, however it does not work in simulation!

  If you want to know what pin the on-board LED is connected to on your Arduino model, check the Technical Specs of your board at: https://www.arduino.cc/en/Main/Products

  modified 8 May 2014 by Scott Fitzgerald
  modified 2 Sep 2016 by Arturo Guadalupi
  modified 8 Sep 2016 by Colby Newman

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Blink
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
  delay(1000); // wait for a second
  digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
  delay(1000); // wait for a second
}

As you can see none of the Simulation applications have a ‘Large 10mm’ Red LED, so we have to make some assumptions…

The Red LED supplied by Oomlout is probably this one, with this Datasheet. Reading the datasheet, and plugging the numbers into an online calculator (I will show the maths at some point in a later post) we can work out what the minimum value of Current Limiting Resistor we need is:

Current Limiting Resistor Large red LED
Current Limiting Resistor on the Large red LED (It doesn’t matter if you put the current limiting resistor on the high side, or the low side of the LED.

Changing the pin:

The LED is connected to pin 13 but we can use any of the Arduino’s pins.

To change it take the wire plugged into pin 13 and move it to a pin of your choice (from 0- 13) (you can also use analogue 0-5, analogue 0 is 14…) Then in the code change line 24:

pinMode(13, OUTPUT);

If you want to use a variable instead of directly defining the pin you need to add a line above the setup section:

int LED = 13;

and then change what was line 24 to:

pinMode(LED, OUTPUT);

Change the blink time:

Unhappy with one second on, one second off? In the code change the number inside the () on lines 30, and 32:

delay(1000);

This is counted in milliseconds, there are 1000 milliseconds in a second, so to work out how long your delay should be: seconds x 1000

Control the brightness:

Along with digital (on/off) control the Arduino can control some pins using PWM1 this allows you to change the apparent brightness. To have a go we need to change the LED to pin 9, both in code and by moving the wire (assuming you changed to a variable).

int LED = 9;

and remove the four lines inside void loop() {…} and replace them with

analogWrite(LED, new number); // (new number) = any number between 0 and 255.

where 0 = off, 255 = on, and any number in between is a different brightness.

Fading:

/*
  Fading

  This example shows how to fade an LED using the analogWrite() function.

  The circuit:
  - LED attached from digital pin 9 to ground.

  created 1 Nov 2008
  by David A. Mellis
  modified 30 Aug 2011
  by Tom Igoe

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Fading
*/

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

void setup() {
  // nothing happens in setup
}

void loop() {
  // fade in from min to max in increments of 5 points:
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) { // sets the value (range from 0 to 255): analogWrite(ledPin, fadeValue); // wait for 30 milliseconds to see the dimming effect delay(30); } // fade out from max to min in increments of 5 points: for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
  }
}
Fading code in iCircuit
Fading code in iCircuit
  1. Pulse Width Modulation – We will cover this more later.
%d bloggers like this: