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

  • Finally, you can manage your Google Docs, uploads, and email attachments (plus Dropbox and Slack files) in one convenient place. Claim a free account, and in less than 2 minutes, Dokkio (from the makers of PBworks) can automatically organize your content for you.


Rane Sunayana Lab 2

Page history last edited by xinyi xie 6 years, 10 months ago

Part B

1. Blinking LEDs and Arduino

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

When I commented out the code inside of the mandatory loop, the LED would not turn on at all. Then, I removed just these three lines out of the four (in other words, i left the code to turn the LED on, but not off):

delay(1000);               // wait for a second

digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW

delay(1000);               // wait for a second

When removed, these lines prevented the LED from blinking--it just remained on. Specifically, it is this line that turns the LED off, and therefore makes it "blink":

digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW

To make the LED blink, this line of code has to be added with some form  of delay.

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

The delay() method causes the rate of blinking you need to change the following two bolded lines to change that rate:

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

  delay(1000);               // wait for a second

  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW

  delay(1000);               // wait for a second

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

I would want to add resistance of some sort.This could be in the form of a resistor or potentiometer, among other circuit elements.

Part 2: Toggle LED and Pushbutton Switch

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

I had to modify the following line:

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

I changed it to const int ledPin =  9; because I needed to make sure that the pushbutton was controlling the external LED, which was connected to pin 9, not the internal one at pin 13.

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 simply changed the instructions in the if-else loop to have LOW voltage when the button was not depressed and HIGH voltage when it was.


My code is as follows:





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

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



 The circuit:

 * LED attached from pin 13 to ground 

 * pushbutton attached to pin 2 from +5V

 * 10K resistor attached to pin 2 from ground


 * Note: on most Arduinos there is already an LED on the board

 attached to pin 13.



 created 2005

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

 modified 30 Aug 2011

 by Tom Igoe


 This example code is in the public domain.





// 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, LOW);  


  else {

    // turn LED off:

    digitalWrite(ledPin, HIGH); 




End of code.


3. Fading (breathing) lights

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

I just had to make sure that the pin the LED was attached to was pin 9:

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

b) How would you change the rate of fading?

I can change the rate of fading by changing the fadeAmount constant. If I set it equal to 10 instead of 5, the rate of fading is much 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?


Part C: Frankenlight


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

Accounting for forward voltage drop, there is only 1.8 V left after the part which is allocated to the LED:

30 mA = 0.030 A



R = 1.8V/0.030 A = 60 ohms

So the minimum resistance needed is 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?"

Yes, there is computation in the computer mouse. The microprocessor does the computation (the long black part of the circuit). This most probably reads and processes simple user inputs, like clicks (a push button switch is closed, and the microprocessor interprets this signal to mean that the user wants to perform an action on the computer.

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

Yes, there are sensors. The push buttons are "sensors" in that they sense the user's touch and allow the user to input "data". The sense information must be conveyed to the microprocessor in the form of electric differences in current when the switch is on versus off (these differences are shown by my Frankenlight).

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 through a computer, thus implying standard 5 volt voltage throughout. The input is DC voltage, but the power is regulated from the standard PS/2 connector into a form that the components can use properly. The PCB shows that the power is then divided into several paths leading to different components.

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

Information that the user inputs is stored in the device and is then conveyed to the computer, which executes the command that it represents. The information is computed and stored in the microprocessor, and is then sent to the computer.

Comments (0)

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