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


Easwaran_Vinay_Lab 2

Page history last edited by Vinay 5 years ago

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

No lines of code need to be changed to make the LED blink, the code works and only needs to be uploaded onto the Arduino to make the LED blink

The lines of code that make this happen are the:

pinMode(ledPin,OUTPUT) - a function which initializes the pin the LED is connected to as an output

digitalWrite(ledPin,HIGH) - sends a high voltage or writes a high value to the LED connected to pin 13 to make it glow and then stay on for a second - delay(1000)

digitalWrite(ledPin,LOW)) - sends a low voltage to writes a low value to the LED connected to pin 13 to turn it off and then stay off for a second - delay(1000)

This constant forever looping of these functions causes the LED to blink 

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

We need to change the value in the delay function in the Loop command, which changes the amount of time for which the LED is left glowing or is not glowing. Reducing the values in both the delay functions to say 200, makes the LED blink faster as it stays on and off for 200 milliseconds, and changing it to say 2000 makes the rate slower as it now stays on and off for 2 seconds at at time.

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

We would need a resistor to protect the board and LED from high current

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

We need to modify the line that defines the constant integer of ledPin as pin 13 to pin 9 since we have our LED connected to pin 9. No lines are required to be modified to correspond to the button pin since the button is connected to pin 2, where the constant buttonPin integer is defined as. 

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.

const int buttonPin = 2;    

const int ledPin =  9;      


int buttonState = 0;         


void setup() { 

  pinMode(ledPin, OUTPUT);

  pinMode(buttonPin, INPUT);



void loop() {

  buttonState = digitalRead(buttonPin);


  if (buttonState == HIGH) {

    digitalWrite(ledPin, HIGH);


  else {

    digitalWrite(ledPin, LOW);



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

No lines of code need to be modified to correspond with the LED pin the ledPin integer is already defined as digital pin 9. which also happens to be the pin to which the LED is already connected

b) How would you change the rate of fading?

To change the rate of fading we need to change the number in the fade value function from the pre-set value 5 to any other number. A number lower than 5 decreases the rate of fading and a number higher than 5 increases the rate of fading as it now increments in values higher than 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?

The 'for' function is made to repeat another 2 times. The maximum of the original is reduced, and the new one's minimum value is the same as the predecessor's maximum value, and the delay time after the first 'for' increases to a higher value after the second 'for'.

Similarly, for the fading from maximum to minimum, the minimum of one is made the maximum of the following and the delay time increases between it's two uses.

The crux is namely: Higher delay values are used for smaller fade values, and smaller delay values for higher fade values. 

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

The minimum resistance required is the quotient of dividing the difference between the voltage supplied and the forward voltage drop, and the maximum current of the LED, which with these LED's is 30mA. 

so what is the answer? 

R = (Vcc - Vf) / If = (5V – 3.2V) / 20mA = 90 Ohms.





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

Yes there is computation. Clicks made on the device are sent in the from of bits to the computer, every click is sent as a 1, and in rest the mouse sends 0's. 

no schematic -0.5

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

There are sensors which detect if a button on the mouse is pressed. They send this sensed information in the form of binary digits to the computer which is interpreted and processed on the computer to show a visible result on screen. The mouse also senses the direction in which it is moved through a sensor on the bottom and this sensed information is also sent to the computer in the form of bits which provide information about the movements and locations of the mouse.

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 drawing current from the computer it is connected to. The white light on the Frankenlight is powered by a continuous current, and the red light is powered by PWM (Pulse Width Modulation) as the on and offs are visible when moved at a high speed

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

No information is stored on the device as such 





Comments (2)

zahraa@... said

at 9:50 am on Jul 15, 2015

good job

Vinay said

at 9:58 am on Jul 15, 2015

I did upload my schematic to the lab reports page, its been removed for some reason, can I upload it again?

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