| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Get control of your email attachments. Connect all your Gmail accounts and in less than 2 minutes, Dokkio will automatically organize your file attachments. You can also connect Dokkio to Drive, Dropbox, and Slack. Sign up for free.

View
 

Shah Pooja Lab 2

Page history last edited by zahraa@... 4 years, 11 months ago

Part B. Arduino micro LED!

 

1. Blinking LEDs with Arduino Micro

  

a. What line(s) of code do you need to change to make the LED blink (like, at all)?

 

The sample code works without any changes needing to be made on our end. However, there are a few key parts of the code that are necessary, without which the LED would not blink:

  1. The setup of the pin as an OUTPUT pin in the setup() function. If the pin is not set up as an OUTPUT pin, the Arduino board will default it to an INPUT pin and the pin may not blink.
  2. No delay() function calls between alternating digitalWrite() calls that set the LED to HIGH (+5V) and LOW (0V) voltage. If there are no delays in between each digitalWrite(), the blink will be imperceptible to the human eye.
  3. No alternating digitalWrite() calls. If either digitalWrite(13, HIGH) or digitalWrite(13, LOW) is missing, the LED will be either continuously on (in the first case) or off (in the second case), and thus no blinking will occur.

 

b. What line(s) of code do you need to change to change the rate of blinking?

 

  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

 

Changing the calls to delay() changes how long the light will be either on/off, thus changing the rate of blinking.

 

c. What circuit element would you want to add to protect the board and LED?

 

You would want to add a resistor to protect the board and LED.

 

2. Toggle LEDs on and off using Arduino Micro

 

a. Which lines do you need to modify to correspond with your button and LED pins? 

 

I am using the alternate design, with circuit diagrams as shown in the pictures on the lab page. This circuit design works so that when the button is pressed, the LED turns on.

 

The lines that must be changed in order to correspond with my button and LED pins are:

 

const int buttonPin = 2;     // the number of the pushbutton pin

const int ledPin =  9;      // the number of the LED pin

 

b. Modify the code or the circuit so that the LED lights only while the button is depressed. Include your code in your lab write-up.

 

I only had to modify the part of the code where the LEDpin variable was assigned to the LED pin (changed it from 13 to 9, which is the pin to which my external LED was attached). I did also change the comments to reflect my particular circuit. The bulk of the sample code works as-is with the alternative circuit design.

 

/*

  Button

 

 Turns on and off a light emitting diode(LED) connected to digital

 pin 9, when pressing a pushbutton attached to pin 2.

 

 

 The circuit:

 * LED attached from +5V to pin 9

 * pushbutton attached to pin 2 from ground

 * 10K resistor attached to pin 2 from +5V 

 

 created 2005

 by DojoDave <http://www.0j0.org>

 modified 30 Aug 2011

 by Tom Igoe

modified 6 July 2015

by Pooja Shah

  

 http://www.arduino.cc/en/Tutorial/Button

 */

 

// constants won't change. They're used here to

// set pin numbers:

const int buttonPin = 2;     // the number of the pushbutton pin

const int ledPin =  9;      // the number of the LED pin

 

// variables will change:

int buttonState = 0;         // variable for reading the pushbutton status

 

void setup() {

  // initialize the LED pin as an output:

  pinMode(ledPin, OUTPUT);

  // initialize the pushbutton pin as an input:

  pinMode(buttonPin, INPUT);

}

 

void loop() {

  // read the state of the pushbutton value:

  buttonState = digitalRead(buttonPin);

 

  // check if the pushbutton is pressed.

  // if it is, the buttonState is HIGH:

  if (buttonState == HIGH) {

    // turn LED on:

    digitalWrite(ledPin, HIGH);

  }

  else {

    // turn LED off:

    digitalWrite(ledPin, LOW);

  }

}

 

3. Fading LEDs on and off using Arduino Micro 

 

a) Which line(s) of code do you need to modify to correspond with your LED pin?

 

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

 

b) How would you change the rate of fading?

 

Change the values of the arguments passed to the delay() calls in the for loops in the loop() function.

 

If you increase the values of the arguments to delay > 30ms, the rate of fading will decrease.

If you decrease the values of the arguments to delay < 30ms, the rate of fading will increase.

 

c) (Extra) Since the human eye doesn't see increases in brightness linearly and the diode brightness is also nonlinear with voltage, how could you change the code to make the light appear to fade linearly?

 

You could change the code so that the values of fadeValue increase/decrease logarithmically instead of linearly as they do in the example code (increments of 5).

 

In theory, say you wanted to change the code so that the light appeared to fade linearly and you wanted to break the change into 10 increments. You could calculate the logarithmic value of the fade value.

 

Ax Bx Cx Dx Ex Fx
Value log(Ax) Duty Cycle Cx * 255 = logarithmic fade value Dx rounded up/down  Comma-separated list of fade values
    % = (1-Bx)      
1 0 1 255 255 255
2 0.301029996 0.698970004 178.2373511 178 255,178
3 0.477121255 0.522878745 133.33408 133 255,178,133
4 0.602059991 0.397940009 101.4747022 101 255,178,133,101
5 0.698970004 0.301029996 76.76264889 77 255,178,133,101,77
6 0.77815125 0.22184875 56.57143115 57 255,178,133,101,77,57
7 0.84509804 0.15490196 39.4999998 39 255,178,133,101,77,57,39
8 0.903089987 0.096910013 24.71205332 25 255,178,133,101,77,57,39,25
9 0.954242509 0.045757491 11.66816009 12 255,178,133,101,77,57,39,25,12
10 1 0 0 0 255,178,133,101,77,57,39,25,12,0

 

You could then change the Fading example code to look something like this:

 

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

int arrayFadeVal[10] = {255,178,133,101,77,57,39,25,12,0};

 

void setup() {

  // nothing happens in setup

}

 

void loop() {

 

  //fadeValue should increase logarithmically from the last element of the array to

  //the first, in the direction of 0 -> 255. 

 

  for (int fadeIndex = 9; fadeIndex >= 0; fadeIndex -= 1) {

    int fadeValue = arrayFadeVal[fadeIndex];

    analogWrite(ledPin, fadeValue);

    delay(100);

  }

 

  //fadeValue should decrease logarithmically from the first element of the array to

  //the last, in the direction of 255->0. 

 

  for (int fadeIndex = 0; fadeIndex <= 9; fadeIndex += 1) {

    int fadeValue = arrayFadeVal[fadeIndex];

    analogWrite(ledPin, fadeValue);

    delay(100);

  }

 

}

 

In theory, this should make the fading of the light appear more linear to the human eye.

✔ Great

 

 

Part C. Frankenlight

 

1. Super bright LEDs

 

a. What is the minimum resistor size that should be used with these LEDs? (Hint: think about your voltage supply and what the diode voltage drop means.) 

 

If we are using a 5V power supply:

 

Vpower = 5V

Vf = 3.2V

Imax = 30mA = 0.03A

Rmin = ?

Vpower - Vf = ImaxRmin

5 - 3.2 = (0.03)Rmin

Rmin = 1.8/(0.03)

Rmin = 60 Ohms

✔ Cool

We must use at least 60 Ohms of resistance with these superbright LEDs.

 

2. Take apart your electronic device, and draw a schematic of what is inside.

 

Schematics for Question #2 and #3 are attached as files.

  

a. Is there computation in your device? Where is it? What do you think is happening inside the "computer?"

 

I'm not really sure, but there are a few integrated circuits on the board (AGRSCORPIO and AGRSCRP1037B -- labeled (A) and (B)) that could be doing some computation. I gathered this part from the electronics heap in Room 130 and it was just a rogue board, so I really don't know what it could be doing!

b. Are there sensors on your device? How do they work? How is the sensed information conveyed to other portions of the device?

 

Not that I can see. There is an area that seems like it is relevant for power supply, lots of capacitors and transistors, a couple integrated circuits, and ground.

c. How is the device powered? Is there any transformation or regulation of the power? How is that done? What voltages are used throughout the system?

 

There is a section for power supply on the schematic above. The voltage from the power source is regulated by a voltage regulator (C) and it seems to be transformed by an induction coil (D) that could have transformed the DC power supply to what was necessary for the rest of the system. 

d. Is information stored in your device? Where? How?

 

Again, it's difficult for me to say because I have no idea where this board came from and it's difficult to tell just by looking at the parts!

3. Using your schematic, figure out where a good point would be to hijack your device and implant an LED.

(or, if the thing you are hacking is an LED light, hijack it so that you can turn the light on and off)-- be creative.

 

See schematic attached as file. 

4. Build your light!

 

 

Comments (1)

zahraa@... said

at 3:19 pm on Jul 15, 2015

great job

You don't have permission to comment on this page.