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

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

Lab 2 (1)

Page history last edited by Jay Minga 7 years, 4 months ago
 

 

Lab 2: Frankenlight

Arduino micro LED & Frankenlight 

Overview

In this assignment we (1) control an LED light with our own Arduino micro and 2) build our own stand-alone light by hacking apart an electronic device of our finding/choosing, figuring out what is going on inside, and hacking in an LED. 

Blinking Red LED!

http://youtu.be/t6KIftduvKQ

Frankenlight!

http://youtu.be/c3539BT8kP8

 

1. Blinking LEDs with Arduino Micro

Connect the Arduino Micro to your computer using the USB cable. The Arduino Micro board comes preloaded with a version of the Blink program on it, so its LED should start blinking as soon as the USB cable starts powering the board. This LED is hardwired to pin 13 of Arduino Micro. The pinout diagram of Arduino Micro can be found here.

 

The Blink program itself can be found in the Arduino IDE's example code folder under File->Examples->Basics->Blink. Check it out!

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

 

This Line that turns up the voltage:

  digitalWrite(led, HIGH); // turn the LED on (HIGH is       voltage level)

 

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

 

These lines control for how long the light is on and off respectively:

  delay(1000); // wait for a second

...

  delay(1000); // wait for a second

 

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

A resistor would add protection to the board and LED

 

5v-1.85 V = R (.03A)

 R= 105 Ohm

 

To compile and upload your code, take the following steps (note that 1, 2 should only have to be done once):

 

1) In the Arduino program, select the board we are using: Tools -> Board -> Arduino Micro

2) You may also have to select a communications (or COM) port (Tools -> Serial Port). Ask an instructor to help you choose the right port.

3) To compile your code, click on the "checkmark" on the upper far left of the Arduino development window.

4) To upload compiled code to Arduino Micro board, click on "right arrow" besides "checkmark".

5) When the code is uploaded, the Teensy should automatically start running your new code.

 

Now modify the circuit and program so that you can blink an external LED on pin 9. Don't forget about question (c) above! (Also, don't forget to power and ground the power and ground rails of your breadboard, respectively!)

 

Some tips and reminders:

 

We don't have extra Arduino Micro boards, so be careful.

Remember that the USB connected to the Arduino Micro boards supplies power.

Check that there are no shorts between power and ground before you plug in the USB cable (and apply power).

Unplug power before modifying circuits.

 

 

2. Toggle LEDs on and off using Arduino Micro

With your LED still connected on digital pin 9, hook up a button circuit on digital pin 2, so that the pushbutton attaches from pin 2 to ground, and so that there is a 10K resistor attached between pin 2 and Vcc. (Vcc is the supply voltage. In this case, it is 5 V. You can check out your Arduino Micro pinout diagram in your kit if you're still confused).

 

 

 

Use either the same circuit you used for the previous part for the LED or the alternative design below. The alternate circuit causes the "on" state of the LED to occur when Arduino Micro pin = LOW, not HIGH, as before.

 

        

 

The Arduino Micro pin configured as an input has a 'high input impedance.' This means that it can sense the voltage without affecting the circuit, like a probe.

 

Use the Button program (File->Examples->Digital->Button) to make your Arduino Micro into a light switch.

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

 

 

const int ledPin = 13; // the number of the LED 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.

 

  if (buttonState == HIGH) {     

    // turn LED on:    

    digitalWrite(ledPin, HIGH);  

 

  else {

    // turn LED off:

    digitalWrite(ledPin, LOW); 

  }

 

->

 

  if (buttonState == LOW) {     

    // turn LED on:    

    digitalWrite(ledPin, HIGH);  

 

  else {

    // turn LED off:

    digitalWrite(ledPin, LOW); 

  }

 

 

3. Fading LEDs on and off using Arduino Micro 

What about those "breathing" LEDs on Macs? The fading from bright to dim and back is done using pulse-width modulation (PWM). In essence, the LED is toggled on and off very rapidly, say 1,000 times a second, faster than your eye can follow. The percentage of time the LED is on (the duty) controls the perceived brightness. To control an LED using PWM, you'll have to connect it to one of the pins that support PWM output—which are 4, 5, 6, 9, 10, 11, 12 on the Arduino Micro.

 

Use the Fading program (File->Examples->Analog->Fading) to make your LED fade in and out.

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

 

None. My LED pin is connected from digital pin 9 to ground. See below:

 

/*

 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

 

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

 

 This example code is in the public domain.

 

 */

 

 

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);                            

 

}

 

 

 

b) How would you change the rate of fading?

 

I would change the delay for seeing the dimming effect either up or down from 30.

 

Alternatively, I could change the increment up or down from 5.

 

 

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?

 

Since the human eye doesn't see increases in brightness linearly and the diode brightness is also nonlinear with voltage, I would seek to change the delay or the increment exponentially across the cycle.  Exponential change would increase/decrease dramatically more quickly after initially having a low rate change of change (see Figure A for an example of an exponential curve). 

 

Figure A (credit: http://aeonblueprint.wordpress.com/2011/09/21/novelty-exponential-curve/)

 

 

The first method of creating an exponential curve would mean changing the incremental brightness (fadeValue) exponentially; this exponentially increases the brightness.  Having some difficulty producing an exponential formula, I here present at geometric substitute: For the fadeValue while fading out I would set the ending condition of the for loop to "fadeValue > 1" and the incrementation component to "fadeValue -= fadeValue/2"; for fading in I would I would set the incremental fadeValue to "fadeValue += fadeValue"; this would have an effect that substitutes, at least to the naked eye, much more closely an exponential function.

 

An Exponential Solution, though one that suffers from very quick exponential growth:

 

 

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:

  int i = 1;

  

  for(int fadeValue = 1; fadeValue <= 255; fadeValue = fadeValue^i) { 

    // sets the value (range from 0 to 255):

    analogWrite(ledPin, fadeValue);          

    i += 1;

    // wait for 30 milliseconds to see the dimming effect    

    delay(200);                            

 

 

  i = 1;

 

  // fade out from max to min in increments of 5 points:

  for(int fadeValue = 255; fadeValue > 1; fadeValue = fadeValue^-i) { 

    // sets the value (range from 0 to 255):

    analogWrite(ledPin, fadeValue);         

    i += 1;

    // wait for 30 milliseconds to see the dimming effect    

    delay(200);                            

 

}

 

 

Part C. Frankenlight

Time to hack apart an existing electronic device! In Room 36 (one of Stanford's prototyping and modeling shops) you'll be able to hack apart most anything.

 

1. Super bright LEDs

We have included some nifty superbright LEDs in your kit. They are clear and have two leads. The link to their datasheet is here. They have ~3.2V forward drop, and a max current rating of 30mA.

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.) 

 

 

 

Our voltage supply supplies 5v. The forward drop subtracts 3.2v to yield 1.8v. Divide 1.8v by 30 miliAmps to get 26.7 Ohms minimum resistance.

 

(5V- 3.2V) / 0.03 A = 26.7Ω

 

 

 

Try prototyping a circuit with the superbrights. (Be careful! They are bright enough that it hurts your eyes to look at them!)

 

 

 

 

 

 

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

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

 

there is a micro controller chip on the control perf board underneath a wad of goop protecting it from static electrical charges, the computer is receiving instructions from the remote control receiver antenna and passing signals to the 

 

 

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

 

the antenna might be a sensor, the sensor receives information from the remote control and sends that information to the micro controller chip

 

 

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?

a Ni-Cd battery pack

 

takes 6.0v, so overall resistance should be 6.0v

 

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

the device does not store information.

 

 

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.

 

(6V- 3.2V) / 0.03 A = 93.3Ω

 

 

 

4. Build your light!

We have scrap perfboards in the lab, which provide a handy way to connect your parts. (These are what we used during the soldering demo.) You may want to make your light using passive components (such as switches, resistors or potentiometers) rather than your microcontroller (also known as a μC), unless you think of a nice way to incorporate the μC into your design without soldering it inside of a light. (You'll need it back for future labs and projects!) If your design does require a μC, perhaps you can run a lead from your breadboard to the main light, although you'll lose portability that way. Clever use of components is encouraged!

 

Give yourself enough time to build your design. Consider re-visiting the lab outside of session, so you can access components, tools, soldering irons.

 

Please post a short video of your frankenlight to your lab report page. Include any schematics as well.

 

See above for video. Here are some photos and the approximated attempted schematics since the originals were not available:

 

 

 

 

 

 

 

 

 

Appendix A:Potentially Useful Datasheets 

Red LEDYellow LEDGreen LEDWhite Superbright LEDRGB LED

6mm Pushbutton12mm Pushbutton Arduino Micro Development Board introduction

Arduino Micro Schematic

Appendix B: About the Arduino Micro

Lab 2 (1)

For the remaining labs and class project, we'll use the Arduino Micro development board as our hardware platform. Compatible with the Arduinoprototyping platform, the Arduino comprises both hardwareand software. We'll use the the Arduino hardware and software Integrated Development Environment (IDE).

Install the Arduino Micro software on your machine. On the lab machines: C:\Users\Public\Documents\arduino-1.0.4-windows

 

 

Comments (0)

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