| 
  • 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 Report_Luis Villaran

Page history last edited by Luis Villaran 7 years, 3 months ago

PART B

1.

a) The following lines of code makes the LED turn on and then off.  Because it's in the loop() function it keeps repeating so the LED blinks continuously.

 

digitalWrite(13, HIGH);   // set the LED on
delay(1000);              // wait for a second
digitalWrite(13, LOW);    // set the LED off
delay(1000);              // wait for a second

 

b) To change the rate of blinking the number in the calls to delay() should be changed (i.e. the 1000 in the above code snippet).

c) To protect an external LED/ the board a resistor should be connected in series.  For the green LED:

          R = V/I = 2.5V/25mA = 100 ohms

 

2.

a) The following lines need to be changed to correspond to the pins of the button and LED, respectively, as shown.

 

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  9;      // the number of the LED pin

 

b)

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 == LOW) {    
    // turn LED on:   
    digitalWrite(ledPin, HIGH); 
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

 

3.

a) The following line of code needs to be modified to work with my circuit:

     int ledPin = 9;    // LED connected to digital pin 9

b) In the following code snippet, I would change the numbers given to delay() to change the rate of fading.  You could also change the fadeValue, which would change how fast the LED appears to be fading in and out.

 

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

 

c) To make the LED look like it is fading in and out linearly, the fadeValue in the above example would have to be dynamic.  At each time through the for loop, the fadeValue would have to be calculated and change based on where the LED is in its fading sequence.

 

PART 3

1.

a) The resistor value should be:

     R = V/I = 1.8V/30mA = 60 ohms

2.

a) I took apart a motion detection alarm.  When it is on, and it detects motion a high pitch noise is emitted from the device. I don't think there is actually any computation done in the device.  It looks like it has an IR sensor (possibly made up of an emmitter/receiver pair) and the output from that sensor is hooked up to a a high-pass filter that detects fast changes in the input.  The output of this seems to directly drive the small speaker through a darlington pair.

 

b) See answer to (a)

c) The device is powered off of two AAA batteries (~3V) but looking at the board it doesn't look like it has any regulation of the voltage so it must be driven directly from the batteries.  There are many resistors I don't know the purpose for, so it may be that the voltage from the batteries is being divided down and a lower voltage is used to drive the circuitry but I'm not sure about that.

d) There is no data that seems to be stored on the device.

 

Schematic:

 

Original Circuitry:

 

FrankenLight:

 

Video:

Comments (0)

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