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


Kairam Lab 2

Page history last edited by sanjay.kairam@... 7 years, 6 months ago

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

* The loop() function (lines 19-24) control the blinking of the light.


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

* Line 21 controls how long the light stays on, and Line 23 controls how long the light remains off.


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

* We might want to add a small resistor to limited the current flowing through the board.


2a. Which lines do you need to modify to corresopnd with your button and LED pins.

* Just need to change the LED from 13 to 9 (line 30)


2b. 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.





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






3a. What line(s) of code do you need to modify to correspond with your LED pin.

* My LED is on pin 9, so no modification was needed.


3b. How would you change the rate of fading?

* Can either change the amount that the fadeValue is incremented in each iteration of the for loop (lines 29, 37) or change the delay between each increment (lines 33, 41)


3c. 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?

* Assuming that the eye perceives changes in brightness logarithmically, I might edit the code so that the fadeValue doubles with each iteration of the for loop (or some other base other than 2).




1a. What is the minimum resistor size that should be used with these LED's?

* (5 - 3.2) = 1.8V = (0.03) * R --> R = 60


2. Unfortunately, I didn't bring an item in and I found many of the circuit boards to be prohibitively difficult to work with.

For now, I just took a piece of a board with an LED and attached it to my circuit. If I can find some additional time, I will post something more interesting here.


Comments (0)

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