Beruflich Dokumente
Kultur Dokumente
Arduino Lab
1
Arduino Music and Light Show Project using Max 32
Adapt the instructions below for the Uno to the Max32
Buzzers are widely used in computers, printers, copiers, alarms, electronic toys, automotive electronic
equipment, telephones, cell phones, timers, and etc...
A buzzer contains a crystal that changes shape slightly when voltage is applied to it. By applying high and low
voltages to a piezoelectric crystal at a rapid rate, it causes the crystal to rapidly change shape. The result is
vibration. Vibrating objects cause the air around them to vibrate also. This is what our ear detects as sounds
and tones. Every rate of vibration has a different tone.
Connect the Arduino Uno R3 compatible board with a breadboard and a passive buzzer, using jumper wires.
The following figure shows that the positive terminal of the buzzer is connected to the Uno’s digital I/O pin 7
and the negative terminal is connected to the ground.
Connect the Arduino Uno R3 compatible board with a breadboard using jumping wires, and serially connect
a 220Ω resistor with one Red light emitting diode (LED). The following figure shows that the positive terminal
of the LED is connected to the 220Ω resistor, and the 220Ω resistor is connected to the Uno’s digital I/O pin 8
and the negative terminal of the LED is connected to the ground.
Repeat the steps above again and connect another LED to the Uno’s digital I/O pin 9.
Write a c program, using the Arduino’s integrated development environment (IDE), to play a song that
contains a minimum of 30 music notes. Design your program to blink a minimum of two (2) lights after the
song to provide visual effects. Play the song again faster at 75%-80% of its original duration and follow with
another faster light show. (Blinking the lights during the song is encouraged but optional.)
The frequency of each key on a piano keyboard is listed on the following table.
Zip the entire Sketch folder for Project Music and Light Show.
Rename the folder to LastNameFirstName_Proj_ML.zip and submit the zipped file on Moodle2 with your
report.
Demo the Project to your Lab Instructor.
Arduino Project – FM Radio Stations Display Adapt
the instructions below for the Uno to the Max32
Seven-segment displays are widely used in digital clocks, digital watch, microwaves, ovens, electronic meters,
temperature controllers, radio, CD, DVD, Blu-ray players, basic calculators, pedometers, and other electronic
devices that display numerical information.
A 7-segment display is an assembly of light emitting diode-bars (segments). Each bar can be powered
individually. They are arranged and labeled as shown in the diagram below. When all the segments are
powered on, the display shows the number 8. Powering up segments a, b, c, d, and g will display the number
3. Some single displays have an additional input pin for the decimal point (DP) in their lower right or left hand
corner.
Potentiometers are commonly used to control electrical devices such as volume controls on audio equipment
and light dimmers. A potentiometer is a simple knob that provides a variable resistance. It is a three-terminal
resistor with a rotating or sliding contact that forms an adjustable voltage divider. It is used for measuring
electric potential (voltage).
Connect the middle pin of the potentiometer to the analog pin A0.
By turning the knob of the potentiometer, we change the amount of resistance of the potentiometer. The
voltage of the potentiometer changes between 0 volts and 5 volts. When we read the value from the analog
pin A0, we will read a value between 0 and 1023. If there is 0 volt going to the analog pin A0, we read 0. If
there is 5 volt going to the analog pin A0, we read 1023. The values in between is proportional to the amount
of voltage being applied to the pin.
A multi-digit 7-segment display is an integration of several 7-segment displays into a single package. To
reduce the total number of registers needed to control many digits, the segment pins are shared by all the
digits. There is a single pin that connects to all the “a” segments, a single pin that connects all the “b”
segments, etc. When all the segments are powered on at the same time, every digit will display the same
number.
Time division multiplexing allows each digit to take a turn to be enabled to display a particular digit. When
this is done fast enough, our eyes are not able to tell the difference. The numbers will appear to be lit at the
same time, although they are not.
There are 12 pins in one 4-digit 7-segment display. The pin numbers for the 4-digit 7-segment display are
shown below.
Connect the Arduino Uno R3 compatible board with a breadboard and a 4-digit 7-segment display module
using the circuit diagram below.
Instead of a button, connect a LED light to digital pin 13.
The FM broadcast band, used for FM broadcast radio by radio stations, usually spans from 87.5 to 108.0
megahertz (MHz).
Write a c program, using the Arduino’s integrated development environment (IDE), to simulate a FM
broadcast radio display. Rotating the Potentiometer should display radio frequency from 87.5 to 108.0
megahertz (MHz).
When the potentiometer is turned to the following FM radio stations, turn the LED light ON.
The LED light should be turned off when the 4-digit 7-segment display is not showing any FM radio station.
Turning the light on for additional FM radio stations is welcome.
When the radio frequencies are 3 digits, for example 88.9, the leading 0 should be omitted in the display.
Zip the entire Sketch folder for Project FM Radio Stations Display.
Rename the folder to LastNameFirstName_Proj_FM-Disp.zip and submit the zipped file on Moodle2 with your
report.
Demo the Project to your Lab Instructor.
Arduino Project – Multi-purpose Infrared Remote Control
Adapt the instructions below for the Uno to the Max32
Infrared remote controls are commonly used to control TVs, DVD players, stereos, cable boxes, and so on…
Infrared remote controls send a series of binary pulse code using infrared light signals. The signal between a
remote control handset and the device it controls consists of pulses of infrared light, which is invisible to the
human eye, but can be seen through a digital camera, video camera, or a phone camera.
The transmitter in the remote control handset sends out a stream of pulses of infrared light when the user
presses a button on the handset. A transmitter is often a light emitting diode (LED) which is built into the
pointing end of the remote control handset. The infrared light pulses form a pattern unique to that button.
The receiver in the device can be programmed to recognize the pattern and causes the device to respond
accordingly.
Connect the Arduino Uno R3 compatible board with a breadboard and a passive buzzer, using jumper wires.
The following figure shows that the positive terminal of the buzzer is connected to the Uno’s digital I/O pin 7
and the negative terminal is connected to the ground.
Connect the Arduino Uno R3 compatible board with a breadboard using jumping wires, and serially connect
a 220Ω resistor with one light emitting diode (LED). The following figure shows that the positive terminal of
the LED is connected to the 220Ω resistor, and the 220Ω resistor is connected to the Uno’s digital I/O pin 8
and the negative terminal of the LED is connected to the ground.
Repeat the steps above again and connect a different color LED to the Uno’s digital I/O pin 3, 4, 5, 6, 9, 10, and
11. Install a total of 8 LED lights (using I/O Pins 3, 4, 5, 6, 8, 9, 10, and 11) in one line.
Connect the 3 pins of the infrared receiver sensor to the bread board and add jumping wires as follows:
1. A piano keyboard.
2. Garage door opener.
3. Sound volume controller.
4. Play a song.
IMPORTANT:
The Arduino IRremote library functions and the Arduino built-in tone() and noTone() functions can NOT be
used in the same program! Functions to send/receive infrared light frequency and the functions to produce
sound frequency are both trying to control the same hardware interrupt timer 2 on the Arduino board.
The workaround is to use the NewTone library functions to produce sound. The NewTone library functions
use the hardware interrupt timer 1 to produce the desired frequency.
To use the <NewTone.h> library functions, include the NewTone.h header file in the program.
The syntax of the NewTone() function call is:
Using the <IRremote.h> library functions, we can capture and decode the signals send from each infrared
remote control buttons (for example):
#include <IRremote.h>
int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop()
{
if (irrecv.decode(&results))
{
Serial.println(results.value, HEX);
irrecv.resume();
}
delay(100);
}
The IR decoded value of each button from the SainSmart remote control is listed below. The button IR
decode results need to be defined in your program for your program to recognize the IR signal.
Infrared Remote Control Button Decoded Value in Hexadecimal Format
Mode 0xFF629D
+ 0xFF906F
- 0xFFA857
0xFF9867
U/SD 0xFFB04F
0 0xFF6897
1 0xFF30CF
2 0xFF18E7
3 0xFF7A85
4 0xFF10EF
5 0xFF38C7
6 0xFF5AA5
7 0xFF42BD
8 0xFF4AB5
9 0xFF52AD
Zip the entire Sketch folder for Project Infrared Remote Control.
Rename the folder to LastNameFirstName_Proj_IR-Remote.zip and submit the zipped file on Moodle2 with
your report.
Demo the Project to your Lab Instructor.
Arduino Project – a Keypad Controlled Pink Panther and Detective Game
Adapt the instructions below for the Uno to the Max32
A keypad is a set of buttons arranged in a block or “pad” which usually bear digits, symbols and usually a
complete set of alphabetical letters. Keypads are commonly found on many alphanumeric keyboards
and on other devices such as calculators, telephones, microwaves, combination locks, and digital door
locks, which require mainly numeric input.
The keypad that comes with the Starter Kits has buttons arranged in 4 rows and 4 columns. A
connection is made between the corresponding row line and column line when a button is pressed.
When none of the button is pressed, there is no connection between the row or column lines.
Connect the left most pin of the keypad to the Uno’s digital I/O pin 9 and connect the remaining pins
in succession, so that the right most pin of the keypad connects to the Uno’s digital I/O pin 2.
Since the keypad is using Uno’s digital I/O pin 2 through 9, the buzzer and lights can’t use digital I/O pin
2 through 9.
Install a circle of 8 LED lights on the bread board. The following light numbers can be used to identify
the location and wiring of each light:
3 4 5
2 6
1 8 7
Connect 3 LEDs to the Uno’s digital I/O pin 11, 12, and 13 to represent the LED light #1, #2, and #3.
The Arduino IDE Serial data connections, Serial.begin() and Serial.println() functions, use digital I/O pin
0 and 1. Therefore, if we want to use the 9600 baud rate window to print debug statements, the use of
digital I/O pin 0 and 1 should be avoided.
The 6 Analog pins (A0 – A5) on the Uno board can also be used to send digital output as digital pins
14-19.
Connect the fourth (4th) LED to the Uno’s analog pin A2 (digital I/O pin 16) to represent the light #4.
Connect the fifth (5th) LED to the Uno’s analog pin A3 (digital I/O pin 17) to represent the light #5.
Connect the fifth (6th) LED to the Uno’s analog pin A3 (digital I/O pin 18) to represent the light #6.
Connect the fifth (7th) LED to the Uno’s analog pin A3 (digital I/O pin 19) to represent the light #7.
Connect the fifth (8th) LED to the Uno’s analog pin A3 (digital I/O pin 15) to represent the light #8.
Write a c program, using the Arduino’s integrated development environment (IDE), to make a Pink
Panther and Detective Game that utilizes a keypad to obtain the player inputs.
Keypad #
1 2 3 A
4 6
7 8 9
* 0 D
The following table contains the keypad key functions:
Keypad Function
Key
A Start the game.
D End the game and report score. Blink light 1 and buzz frequency 262 for 50 ms for each score
point.
* Turn on all 8 lights when not playing the game.
0 Turn off all 8 lights when not playing the game.
7 During the game, if light 1 is on, turn off light 1,buzz frequency 262 for 25 ms., and score 1 pt.
4 During the game, if light 2 is on, turn off light 2,buzz frequency 262 for 25 ms., and score 1 pt.
1 During the game, if light 3 is on, turn off light 3,buzz frequency 262 for 25 ms., and score 1 pt.
2 During the game, if light 4 is on, turn off light 4,buzz frequency 262 for 25 ms., and score 1 pt.
3 During the game, if light 5 is on, turn off light 5,buzz frequency 262 for 25 ms., and score 1 pt.
6 During the game, if light 6 is on, turn off light 6,buzz frequency 262 for 25 ms., and score 1 pt.
9 During the game, if light 7 is on, turn off light 7,buzz frequency 262 for 25 ms., and score 1 pt.
8 During the game, if light 8 is on, turn off light 8,buzz frequency 262 for 25 ms., and score 1 pt.
The following table suggests the mapping between the light numbers and the Keypad numbers.
Light # Keypad #
3 4 5 1 3 2
2 6 4 6
1 8 7 7 8 9
The program should automatically turn on each light by looping through the circle clockwise one at a
time.
When the program starts, each light stays on for 1 second during the first circle. During the second
circle, each light stays on 90% of the previous duration, 900 milliseconds (1000 ms * 90 / 100 = 900
ms). During the third circle, each light stays on 810 milliseconds (900 ms * 90 / 100 = 810 ms). The
lights loop faster and faster after each circle by reducing the duration 10% each circle.
The millis() function in the Arduino Library (http://arduino.cc/en/reference/millis ) can be used to track
time in milliseconds after the game starts. The millis() function returns the number of milliseconds since
the Arduino board began running the current program. This number will go back to zero after
approximately 50 days. To calculate the actual game time in milliseconds, the value returned by the
millis() function call should be compared to a value returned by a previous call to the millis() function.
The millis() function call output is a unsigned long data type.
The player can turn off the light by pressing the keypad key when the light is on. A successful hit
scores 1 point. Pressing the keypad key when the light is off will not score any point.
Add sound effect from the buzzer when each light turns on.