| 
  • 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: Frankenlight (Huangang Zheng)

Page history last edited by Huangang Zheng 7 years, 5 months ago

Lab Questions

 

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 line:

 

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

 

raises pin 13 to HIGH. If we remove this line, the LED will not blink.

 

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

 

The lines:

 

     delay(1000);               // wait for a second

     ...

     delay(1000);               // wait for a second

 

delay the arduino so that there is a time lapse of 1000 ms before the change from HI to LO on pin 13, creating the blink effect. Either raise or lower this number to slow/speed up the rate of blinking respectively (a higher number means longer delay means slower rate of blinking).

 

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

 

A resistor would help protect the board and LED to help ensure the proper current is delivered to the 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?

 

An additional line to read the value at digital pin 2 is needed to detect the state of the switch. Likewise, a conditional should be used so that a depressed button sends a HIGH and a non-depressed button sends a LO.

 

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.


//  Store pin numbers
int led = 9;
int inPin = 2;

void setup()
{
  //  Init pin 9 for LED output and 2 for reading voltage DC input
  pinMode(inPin, INPUT);
  pinMode(led, OUTPUT);     
}

void loop()
{
  //  Read digital input on pin 2; if switch is on, ground is connected and pin 2 should read LOW. We turn the light on when LOW, or not HIGH.
  if(!digitalRead(inPin))
    digitalWrite(led,HIGH);
  //  Otherwise, we turn the light off.
  else
    digitalWrite(led,LOW);
  //  Give the detection a resolution of 10 times per second to prevent superfluous looping
  delay(100);
}

 

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?

 

Luckily, my LED is hooked up onto pin 9, the default for the Fade code. If it were not hooked on pin 9, I would change this line of code:

 

     int led = 9;           // the pin that the LED is attached to

 

to reflect the pin my LED was connected to.

 

b) How would you change the rate of fading?

 

Either change the fadeAmount variable or change the delay after each loop iteration. Increasing the fadeAmount corresponds to a brighter intensity per loop iteration while decreasing the delay would make the loop iterate faster and advance the brightness faster.

 

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?

 

Change the algorithm to instead of adding an intensity to represent a logarithmic function (make some helper function that returns a logarithmic value with respect to a linear input) and pass the brightness to the helper function, setting the PWM output to the return of that function to get a more logarithmic behavior.

 

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

 

Because the total voltage drop across the circuit needs to be 5V and the forward voltage drop across the red LED is typically 3.2 V, the drop across the resistor should be around 1.8V. The current across the resistor and the LED is 30 mA, so by Ohm's Law the needed resistance is 1.8V / (30 mA), or about 60 ohms.

 

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 no computation in this device.

 

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

 

There is one sensor (the push button) that has a mechanical spring function and latch that keeps it either in a released or a depressed state. The switch physically connects two parts of the circuit, delivering power from the battery to the LED.

 

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?

 

The device is powered by two 3V Lithium batteries. There is no transformation throughout the system. The voltage across the LED is slightly below 6V.

 

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

 

State is stored by a mechanical push button that toggles the light into an on or off state. Once depressed, the button physically gets placed into a lowered state, waiting for the next press to release it. This stores the state of the light, whether its on ON or OFF mode.

 

4. Build your light!

 

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

 

 

Here is my hacked Frankenlight. I have taken a small reading light and taken it apart. It consists of 2 Lithium 3V batteries connected up to a switch and then to an LED. I have removed the batteries, finding the pieces of metal intended to connect to the positive and negative ends of the battery. I then connected these to jumper wires to give the light a pin interface. I created a simple circuit for the Arduino Micro that reads the input from three different buttons. Using the internal pull-up resistors in the Arduino Micro, I was able to bypass the setup shown above. I then read the inputs and had the Arduino adjust the intensity of the light (using analogWrite seen in a previous example; 0 buttons pressed meant no light, any 1 button some light, any 2 buttons more light, and any 3 buttons full light). Notice in the video when I toggle between 2 buttons and 3 buttons by simply lifting and pressing my third finger that the light intensity changes. To show the effects of the circuitry I set up, I left the switch on the reading light depressed at all times; it is worth noting that at any time a user can depress/undepress the switch on the reading light to break the circuit and no light at all would come out regardless of the switches.

 

Here is a schematic of the hacked light:

 

 

The portion labeled Frankenlight Component reflects the actual device that I hacked. There may be internal resistance in the reading light that I did not include on my schematic.

 

Here is the schematic of the original device unhacked:

 

 

Comments (0)

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