Difference between revisions of "CSC231 Lab 5"

From dftwiki3
Jump to: navigation, search
(High Hrequency)
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Image:UnderConstruction.gif]]  
+
<!--[[Image:UnderConstruction.gif]] -->
 
[[CSC231_Class_Page | Back]] to CSC231 Weekly Schedule
 
[[CSC231_Class_Page | Back]] to CSC231 Weekly Schedule
  
Line 26: Line 26:
 
[[Image:CSC231_switchPullUp.png]]
 
[[Image:CSC231_switchPullUp.png]]
 
* buzzer
 
* buzzer
 +
* Light-Sensitive Resistor
 +
[[Image:CSC231 VoltageDivider.jpg]]
  
 
Do not move on to the next section until this section has been presented
 
Do not move on to the next section until this section has been presented
Line 37: Line 39:
  
 
=Connecting an LED to Pin 13=
 
=Connecting an LED to Pin 13=
 
+
[[Image:CSC231_Arduino_Schematics.png|right|150 px|Arduino Schematics (Click to enlarge)]]
 
Look at the schematics of the Arduino.  Locate Pin 13.  Observe that it is already connected to an on-board LED.  You are going to attach another LED to the same output, Pin 13.
 
Look at the schematics of the Arduino.  Locate Pin 13.  Observe that it is already connected to an on-board LED.  You are going to attach another LED to the same output, Pin 13.
  
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 +
<br />
 
==Option 1: Output to LED, to resistor, and to GND==
 
==Option 1: Output to LED, to resistor, and to GND==
  
Line 93: Line 100:
  
 
=Replace the LED and Resistor with a buzzer=
 
=Replace the LED and Resistor with a buzzer=
 +
 +
* The buzzer has a maximum voltage written on one of its sides.  It's typically 3V.  This means that it shouldn't be subjected to more than 3V of power.  However the outputs of the Arduino can vary between 0 and (close to) 5V.  So you need to protect the buzzer from getting too much voltage...  What's the solution?
  
 
=Connect a switch to Pin 11=
 
=Connect a switch to Pin 11=
 +
[[Image:CSC231_switchPullUp.png | right | 150 px]]
 +
* First '''disconnect all hardware''' from your Arduino
 +
 +
* Modify your sketch and make '''Pin 11 an input''' pin.
 +
 +
* Download your sketch to the Arduino.
 +
 +
* Now that Pin 11 is programmed as an input,  connect a switch (with a resistor) to  Pin 11.  Follow the diagram on the right.  Vout should connect to Pin 11.
 +
 +
* Change your sketch so that when the Arduino sees that the switch has been pressed, it switches the LED connected to Pin 13.
 +
 +
* Make the sketch increment a counter every time your switch is found to have changed state.  Make the Arduino display the counter on the PC screen.  Download your sketch.  Activate the switch ON and OFF quickly.  Is the Arduino keeping the right count?  Why or why not?
  
* First disconnect all hardware from your Arduino
+
=Light-sensitive Resistors=
 +
[[Image:CSC231_LightSensitiveResistor.gif | right]]
 +
If you have time, try using a Light-Sensitive Resistor
  
* Modify your sketch and make Pin 11 an input pin.
+
As the picture indicates, this resistor has a high resistance in the dark, and a low resistance under a bright light.   This can be used to detect many different conditions (day/light, proximity, etc.)
  
* Download your sketch to the Arduino
+
[[Image:CSC231_VoltageDivider.jpg]]
  
* Now that the pin is programmed as an input,  use the circuit we will have seen in class to connect a switch (with a resistor) to the Pin 11.
 
  
* Change your sketch so that you can turn the LED connected to Pin 13 ON or OFF with the switch.
 
  
* Make the sketch increment a counter every time your switch is found to have changed state. Make the Arduino display the counter on the PC screen. Activate the switch ON and OFF quickly. Is the Arduino keeping the right count?  Why or why not?
+
'''Do some research and figure out a way to make your Arduino test for light/dark conditions...
 +
'''
  
 
=Misc. References=
 
=Misc. References=
 
* [http://www.bioinspired.com/users/ajg112/electronics/debounce.shtml Debouncing] a switch, from www.bioinspired.com
 
* [http://www.bioinspired.com/users/ajg112/electronics/debounce.shtml Debouncing] a switch, from www.bioinspired.com

Latest revision as of 10:55, 3 October 2008

Back to CSC231 Weekly Schedule


CSC 231 Lab # 5

ArduinoStamp.jpg

© D. Thiebaut, 2008

This lab is designed to make you interface simple input and output devices to the Arduino.

Introduction to Electricity and Electronics

Stay tuned for a presentation at the board of the following basic principles:


  • The output of a logic gate: high and low voltages

CSC231 totemPole.jpg

  • Resistors
  • Diodes

CSC231 LED.gif Outledlow.gif Outled.gif

  • switches

CSC231 switchPullUp.png

  • buzzer
  • Light-Sensitive Resistor

CSC231 VoltageDivider.jpg

Do not move on to the next section until this section has been presented

Lab report

Write up your lab report as part of your 231a Wiki page. Feel free to take pictures of your kits and use them to illustrate your report. This will be the "theoretical" part of your final project: an explanation of how to wire-up hardware to the Arduino board.

Resistors

Find a good reference for the color coding of resistor. The first person to find a good reference should share it with the class by adding it to the reference section of the CSC231 Wiki portal.

Connecting an LED to Pin 13

Arduino Schematics (Click to enlarge)

Look at the schematics of the Arduino. Locate Pin 13. Observe that it is already connected to an on-board LED. You are going to attach another LED to the same output, Pin 13.






Option 1: Output to LED, to resistor, and to GND

Outledlow.gif


  • Turn off the Arduino by disconnecting it from the USB cable.
  • Locate the +5V, GND, and #13 pins on the Arduino side connector. Be careful, it is easy to put a wire in the wrong hole.
  • Create your circuit following the diagram on the right with one LED and one 1KOhm resistor on the digital kit (anything between 1KOhm and 20KOhm should work).
  • Use the 5V and GND of the Arduino, not those of the Kit.
  • Once you have your circuit wired up, power up the Arduino and download the Blink sketch. Does your LED blink? If not, turn it around and reverse its polarity.
  • Indicate on your report what is the right way to wire up an LED.
  • Does it blink in phase or out of phase with the on-board LED?

Option 2: +5V to resistor to LED to output

Outled.gif
  • Same steps as in the previous section, but use the picture on the right as the example.
  • Same question: is your LED blinking in phase or out of phase with the on-board LED?
  • Make sure you explain in your report the difference between the two wiring approaches.








Connecting an LED to Pin 11

  • You are now going to connect your LED to Pin 11. This way you can control two separate LEDs, on on Pin 13 (on-board), and one on Pin 11.
  • Modify your sketch so that it makes the Pin 11 LED blink.
  • Modify your sketch so that it makes both LEDs blink. Make them blink in phase and out of phase by changing only the software, not the hardware.
  • Modify the sketch so that the on-board LED blinks at 0.5 Hz and your new LED blinks at 1 Hz.

High Frequency

  • Make your Pin-11 LED blink as fast as possible.
  • How fast is it blinking? How can you find out? How can you measure this frequency precisely? Be imaginative and resourceful... :-)

Replace the LED and Resistor with a buzzer

  • The buzzer has a maximum voltage written on one of its sides. It's typically 3V. This means that it shouldn't be subjected to more than 3V of power. However the outputs of the Arduino can vary between 0 and (close to) 5V. So you need to protect the buzzer from getting too much voltage... What's the solution?

Connect a switch to Pin 11

CSC231 switchPullUp.png
  • First disconnect all hardware from your Arduino
  • Modify your sketch and make Pin 11 an input pin.
  • Download your sketch to the Arduino.
  • Now that Pin 11 is programmed as an input, connect a switch (with a resistor) to Pin 11. Follow the diagram on the right. Vout should connect to Pin 11.
  • Change your sketch so that when the Arduino sees that the switch has been pressed, it switches the LED connected to Pin 13.
  • Make the sketch increment a counter every time your switch is found to have changed state. Make the Arduino display the counter on the PC screen. Download your sketch. Activate the switch ON and OFF quickly. Is the Arduino keeping the right count? Why or why not?

Light-sensitive Resistors

CSC231 LightSensitiveResistor.gif

If you have time, try using a Light-Sensitive Resistor

As the picture indicates, this resistor has a high resistance in the dark, and a low resistance under a bright light. This can be used to detect many different conditions (day/light, proximity, etc.)

CSC231 VoltageDivider.jpg


Do some research and figure out a way to make your Arduino test for light/dark conditions...

Misc. References