Académique Documents
Professionnel Documents
Culture Documents
-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'
-pload
Modif the code so that the red and ellow !'$ alternate at a
rate of about + times each second. working circuit. .how our instructor our
!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 =========
$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 =========
!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.
'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 =========
!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 =========