Vous êtes sur la page 1sur 7

Print Your Name: __________________________________

Red Box Number:______

Arduino Microcontroller Exercises


An Open-Source Single-Board Protot ping Plat!orm In this in-class exercise we will improve upon previous circuits and code that we had developed using the Arduino Microcontroller. Procedure Put a check () in each box to the left as ou complete each task.

!ogin to our computer as an Administrator. !ocate the Arduino


folder on the desktop or go to the "#omework $ocuments% link on the course home page (www.danbruton.com&'()*+*) and download the Arduino ,ip file to our desktop.

-se a -./ cable to connect the Arduino Microcontroller to our computer. 0hen go to
Start " #ontrol Panels " S stem " $ard%are &tab' " (e)ice Manager* If ou see an unrecogni1ed "-./ $evice% then do the following2 3. )ight click on "-./ $evice% and select -pdate $river. 4. .elect "5es6 now and ever time I connect the device%. *. .elect "Install from a list or specific location%. +. 0he browse to the Arduino "drivers% folder. 7. 0hen click Next and +inis, after successful installation. In the $evice Manager window under Ports (89M :!P0) what is the port number for the Arduino -;9 )* device (e.g. 89M36 89M46 etc.)< Answer2 ===========

8lose the $evice Manager and start the Arduino environment. 0o run the Arduino environment6
locate and execute >arduino.exe> in the Arduino folder on our desktop.

9pen the !'$ blink example sketch2 Arduino " +ile " Examples " -*Basics " Blin..
.elect our microcontroller board2 Arduino " /ools " Serial Port " &Select Your Port'

;ow click the >-pload> button in the environment as shown to


the right. ?erif Microcontroller. that !'$ 3* is blinking on our Arduino

8onnect a ellow !'$ and **@ resistor in series on our red


breadboard. Place this series connection between pin 3* and (;$. /e ver careful not to connect the !'$ directl between Pin 3* and (;$. It is important to have the resistor in series with the !'$. ?erif that the ellow !'$ blinks along with the !'$ that is located on the Arduino board.

-pload

8onnect another **@ resistor in series with a red !'$ on a


separate area on our breadboard. between (;$ and pin 34. 8onnect this series pair

Modif the code so that the red and ellow !'$ alternate at a
rate of about + times each second. working circuit. .how our instructor our

InstructorAs Approval2 =========

Ma.ing Music - /,e So!tPot and Bu00er

!oad the Analog)ead.erial code (Arduino " +ile " Examples " -*Basics " AnalogReadSerial). (entl push the connectors of the .oftPot into the red breadboard. Attach the center pin of the .oftPot to pin A@6 and the outside pins of the .oftPot to B7? and ground. Also6 add a 3@k resistor between the center pin of the .oftPot and (;$ to act as a pull-down resistor. -pload Analog)ead.erial to the Arduino Microcontroller. Monitor the readings using the serial monitor. (Arduino " /ools " Serial Monitor).

)ecord the maximum and minimum values read b the .erial Monitor while ou are touching the .oftPot in various places (e.g. from the top of the sensor to the bottom). Maximum2 ============= Minimum2 =============== Add the follow code before the setup() function in our code. int Min = 100; int Max = 200; int freqout = 440; //Replace with your minimum serial value //Replace with your maximum serial value //An output frequency of 440 ! is concert A

0he tone function in the Arduino environment generates a sCuare wave of the specified freCuenc on a pin. 0he s ntax is tone(pin6 freCuenc 6 duration). Dor example6 tone(E6 ++@6 3@@)F will pla a ++@#1 tone for 3@@ milliseconds to a bu11er connected to pin E. 0he freCuencies ++@#1 and GG@#1 both correspond to the musical note A6 but one octave apart. 0o convert the range of serial sensor values to this freCuenc range6 we can use the following code inside the loop() function2 if "sensor#alue $ 100% & freqout = 440'0 ( "sensor#alue ) Min% * "++0'0 ) 440'0% / "Max ) Min%; tone",- freqout- 100%; .

5ou should hear a tone onl when our press various parts of the .oftPot. .how our instructor our working circuit. InstructorAs Approval2 ========= ;ow remove the .oftPot from our circuit. !eave the 3@k resistor connected between (;$ and pin A@. 8onnect a Dlex .ensor between pin A@ and B7?. 5ou should hear the pitch change as the flex sensor is bent. .how our instructor our working circuit. InstructorAs Approval2 =========

Nig,t 1ig,t - /,e P,otoresistor


8onnect 3@k resistor in series with a photoresistor
on our breadboard. 8onnect this series pair between (;$ and B7?. 8onnect pin A@ to the Hunction between the resistor and photoresistor.

!oad the Analog)ead.erial example code (Arduino


" +ile " Examples " -*Basics " AnalogReadSerial). -pload Analog)ead.erial to the Arduino Microcontroller. Monitor the readings using the serial monitor. (Arduino " /ools " Serial Monitor).

8onnect a ellow !'$ and **@ resistor in series on


our red breadboard. Place this series connection between pin 33 and (;$.

$evelop code that will cause the ellow !'$ to light


up when ou place our finger on top of the photoresistor. .how our instructor our working circuit. InstructorAs Approval2 =========

$eat (etector - /,e /,ermistor


8onnect 3@k resistor in series with a
thermistor on our breadboard. 8onnect this series pair between (;$ and B7?. 8onnect pin A@ to the Hunction between the resistor and thermistor.

!oad the Analog)ead.erial example code


(Arduino " +ile " Examples " -*Basics " AnalogReadSerial). -pload Analog)ead.erial to the Arduino Microcontroller. Monitor the readings using the serial monitor. (Arduino " /ools " Serial Monitor).

8onnect a red !'$ and **@ resistor in series


on our red breadboard. Place this series connection between pin 3@ and (;$.

$evelop code that will cause the red !'$ to light up when ou place our finger on top of the
thermistor. ;ote that it ma take some time for the resistance of the thermistor to change. 0herefore it is acceptable if the !'$ does not light up instantl . .how our instructor our working circuit. InstructorAs Approval2 =========

+ade - Pulse 2idt, Modulation


8onnect a ellow !'$ and **@ resistor in series on our red breadboard. Place this series
connection between pin E and (;$.

!oad the +ade example code (Arduino " +ile " Examples " -*Basics " +ade ). -pload +ade to the
Arduino Microcontroller.

8onnect an oscilloscope between pin E and (;$ and monitor the output waveform. Is the waveform a sawtooth wave6 sCuare wave6 or sine wave< =========================== ;ote that the !'$ is getting brighter and dimmer because of a techniCue called
>Pulse 2idt, Modulation>. 0he !'$ is actuall blinking so fast that our e es cannot detect it -much like a computer monitor or 0?. InstructorAs Approval2 =========

(ebounce - Button
8onnect a ellow !'$ and **@ resistor in series on our red breadboard. Place this series
connection between pin 3* and (;$.

!oad the (ebounce example code (Arduino " +ile " Examples " 3*(igital " (ebounce). -pload
(ebounce to the Arduino Microcontroller.

8onnect a button between pin 4 to B7?.

8onnect a 3@k resistor between from pin 4 and (;$.

'ach time the input pin goes from !9I to #I(# (e.g. because of a push-button press)6 the output pin
is toggled from !9I to #I(# or #I(# to !9I. 0here is a minimum dela between toggles to debounce the circuit (i.e. to ignore noise).

In the code6 change debounce$ela to 3@@@ and note the effect on the behavior of the circuit. .how
our instructor our working circuit. InstructorAs Approval2 =========

#ross%al. /ra!!ic 1ig,t - /ri-#olor 1E(



8onnect pin 4 of the 0ri-8olor !'$ to the (;$ pin of the Arduino microcontroller. !ocate three **@ resistors. Place these * resistors across the valle of the breadboard and connect them to pins 36 * and + of the 0ri-8olor !'$. -se Humper wires to connect the other side of the resistors to pins E6 3@ and 33 of the Arduino microcontroller.

8onnect a button between pin 4 to B7?.

8onnect a 3@k resistor between from pin 4 and (;$.

!oad the (ebounce example code (Arduino " +ile " Examples " 3*(igital " (ebounce). At the top of our program initiali1e variables that will define the pins used as follows2 int int int 2lue0in = 10; Re/0in 1reen0in = = ,; 11;

Inside of the setup() function ou must declare these pins as outputs. pinMo/e"Re/0in- 345045%; pinMo/e"1reen0in- 345045%; pinMo/e"2lue0in- 345045%;

0he following code will turn on the red component of the 0ri-8olor !'$ when the button is pressed if it is placed at the bottom of the loop() function. if "6utton7tate == 81 %& analo9:rite "Re/0in- 2;;%; .else& analo9:rite "Re/0in- 0%; . //:rite the output //:rite the output

Irite addition code that will cause the 0ri-8olor !'$ to go through the following seCuence of colors if the button is pressed2 green for 7 seconds6 ellow for 4 seconds6 and then run on red again until the button is pressed again. 0hink of this as a protot pe for a crosswalk traffic light. .how our instructor our working circuit. InstructorAs Approval2 =========

Vous aimerez peut-être aussi