ECE 415 Laboratories Group 1
ECE 415 Laboratories Group 1
Macalintal, Keybeard
Nora, Rashid M.
Peralta, Paul
Samonte, Kyte Valerie
July 2025
I. INTRODUCTION
Microcontrollers are fundamental components in electronics and embedded systems.
These small integrated circuits combine a processor, memory, and input/output interfaces,
enabling them to perform programmed tasks repeatedly and efficiently [1]. Due to their
efficiency and versatility, microcontrollers have become essential components in a wide range of
applications including home automation, medical devices, automotive systems, and many more.
One of the most popular platforms for learning and developing microcontroller-based
systems is Arduino. Arduino is an open-source prototyping platform with simple hardware and
software components [2]. It comprises a programmable circuit board (also known as a
microcontroller) and ready-made software called Arduino IDE (Integrated Development
Environment), which is used to develop and upload computer code to the physical board [3]. It is
particularly effective for students and beginners due to its user-friendly interface and accessible
programming environment. Unlike traditional microcontroller environments that often require a
deep understanding of embedded C or assembly language, Arduino uses a simplified
programming environment based on C/C++, and its development board designs are user-friendly
[4].
The most commonly used board in the Arduino family is the Arduino Uno, which is built
around the ATmega328P microcontroller. It comes equipped with 14 digital input/output pins, 6
analog input pins, a USB connection for uploading code, and a power jack [5]. These features
make it ideal for learning how to interface with components such as LEDs, sensors, buzzers,
motors, and displays. Arduino also supports a wide range of libraries that simplify the process of
coding for different hardware modules [6]. For example, libraries for controlling servos, reading
joystick values, or playing tones through a buzzer are all readily available. The ability to upload
sketches (Arduino’s term for code) directly from a computer to the board using a USB cable
makes the process of building and testing electronic systems more immediate and engaging.
II. OBJECTIVES
In this laboratory activity, the group will work on different projects using the Arduino
Uno as the main microcontroller to control and connect electronic parts. It helps the students to
better understand the basic principles of microcontroller and electronic systems. With this,
student aims to achieve the following objectives:
1. To develop and operate various kinds of Arduino-based projects that illustrate
important capabilities such as LED manipulation, sound-based operations, servo
motor operation, LCD output, counting mechanisms, and basic security applications.
2. To enhance understanding of microcontrollers by applying theoretical knowledge
through hands-on implementation using the Arduino Uno.
3. To improve technical skills in circuit assembly, coding, and troubleshooting
Arduino-based devices.
III. MATERIALS
This section provides the list of all the materials and components utilized in the
experiment. Each item is listed along with an explanation of its specific role and function within
the overall setup.
IV. PROCEDURES
The procedures implemented in this Arduino-based laboratory project included a
methodical approach to designing, constructing, and programming various electronic circuits on
the Arduino platform. Each project was accomplished by identifying the required components,
establishing the circuit on a breadboard, writing and uploading the needed code, and performing
functional tests to confirm proper operation. Troubleshooting and iterative changes were
implemented as needed to further develop each system. The following are the related processes
used for all projects in this laboratory activity.
1.1. LED
The initial phase of this project starts by inserting the potentiometer into the
breadboard, ensuring that it is securely positioned for stable connections. The center pin
of the potentiometer is then connected to the Arduino’s analog input pin A0, which
allows the microcontroller to read varying voltage levels. One of the outer pins of the
potentiometer is connected to the +5V rail of the breadboard to provide a reference
voltage, while the other outer pin is connected to the GND rail to complete the circuit.
Center pin A0
Then, the next step is to insert the LED into the breadboard. The longer leg of the
LED, which is the positive (anode) terminal, is connected to digital pin 9 of the Arduino
through a 470-ohm resistor to limit current and protect the LED. The shorter leg, which is
the negative (cathode) terminal, is connected to the GND rail of the breadboard to
complete the circuit.
After setting up, the sketch will be uploaded, which will serve as the instructions
that will control the behavior of the components that are connected in the Arduino.The
flowchart above shows the sequence of operations in the Arduino-based light dimmer
project. Then the potentiometer was gradually changed to see how it affected the LED
brightness. As expected, moving the potentiometer changed the voltage read at the analog
input, which controlled the LED intensity via PWM. The results were recorded and
examined to ensure that the system was functional and responsive, confirming that the
light dimmer circuit had been successfully implemented.
1.2. SOUND
To begin this project, all the required components were gathered which include an
Arduino Uno board, a breadboard, jumper wires, a piezo buzzer, four momentary tactile
four-pin pushbuttons, four LEDs, and four 220-ohm resistors. This project also utilizes
the “Tone” library for sound output, which must be installed beforehand.
Figure X.X. Materials Used in Memory Figure X.X. Installed Library Used in
Game Setup Memory Game Setup
Initially, the pushbuttons are placed on the breadboard so that they straddle the
center break, with pins A and B on one side and pins C and D on the other. Following
this, pin B of each pushbutton is wired to the ground rail of the breadboard, which is then
connected to one of the Arduino’s GND pins. Meanwhile, pin D of each pushbutton is
connected to digital pins 2 through 5 of the Arduino in sequential order.
Next, the LEDs are inserted into the breadboard. Each LED’s shorter leg (the
negative leg) is connected to the same row as pin C of the corresponding pushbutton. The
longer positive leg is directed toward the right side of the board to allow space for a
resistor. Then, each 220-ohm resistor is placed between the positive leg of an LED and
Arduino digital pins 8 through 11. Specifically, the red LED is connected to pin 11,
yellow to pin 10, green to pin 9, and blue to pin 8. In the following step, the piezo buzzer
is wired into the circuit. The black (negative) wire of the buzzer is connected directly to
the Arduino’s GND, while the red (positive) wire is linked to digital pin 12.
Once all wiring is completed, the overall setup is checked against the provided
circuit diagram to ensure accuracy and correct placement of all components.
Figure X.X. Reference Circuit Diagram for Figure X.X. Final Setup for Memory Game
Memory Game Setup Setup
After confirming the setup, the provided code (See Appendix B) is uploaded to
the Arduino board.
To better understand how the memory game operates once the code is uploaded, a
flowchart is provided below. This flowchart shows the sequence of operation that the
system follows during the game, from initialization to user input validation and sequence
progression.
Figure X.X.
At the start of the game, the system plays a short melody through the piezo and
flashes an LED to signal that the game has begun. A randomly chosen LED lights up, and
the player is expected to press the corresponding pushbutton. If the correct button is
pressed, the system adds another step to the sequence and repeats the entire pattern,
making the game progressively more challenging. During each round, the code generates
a new random value that corresponds to one of the four LEDs, which is stored in an array.
The LEDs light up one by one in the stored sequence, each accompanied by a unique tone
played by the piezo buzzer. Button presses are detected using the “digitalRead()”
function and are then compared to the stored sequence in the “randomArray”. The
player must then press the pushbuttons in the correct order to match the sequence. If an
incorrect button is pressed at any point, the game immediately triggers a failure response
which flashes all LEDs and plays a distinctive tone, before resetting the sequence and
starting over.
1.3. SERVOS
This project requires a few essential components to build a joystick-controlled
laser system. The materials include an Arduino Uno board, a breadboard, jumper wires,
two Tower Pro SG90 9g servomotors, an analog two-axis joystick module, and a
pan-and-tilt servo housing. Additionally, the “Servo” library must be installed to enable
control over the servo motors.
The wiring setup starts with powering the servos. Both red power wires are
connected to the +5V rail of the breadboard, while the brown wires are grounded. The
+5V and GND rails are connected to the corresponding pins on the Arduino to complete
the power circuit. The yellow signal wire of one servo is connected to pin 9, while the
second servo’s signal wire is connected to pin 10 on the Arduino.
The joystick module is connected next. It includes five pins labeled +5V, GND,
VRx, VRy, and SW. The +5V and GND pins are connected to the power and ground rails
of the breadboard. The VRx pin, which reads horizontal motion, is wired to analog pin
A0 on the Arduino, while the VRy pin, responsible for vertical motion, is connected to
analog pin A1. The SW pin, which functions as a pushbutton, is not used in this particular
project.
Before turning on the circuit, the connections between the breadboard rails and
the Arduino’s GND and +5V pins are carefully checked for accuracy. Once the wiring is
confirmed to be accurate, both servos are secured in the pan-and-tilt housing. The laser
pointer is then placed on top of the module. Following the setup, the provided code (See
Appendix A) is uploaded to the Arduino board to enable control of the system.
Figure X.X. Reference Circuit Diagram for Figure X.X. Final Setup for
Joystick-Controlled Laser System Joystick-Controlled Laser System
Once the joystick-controlled laser system is properly assembled and the code is
uploaded to the Arduino, the program begins running its main control loop. The
flowchart below breaks down the entire process into clear, sequential steps.
Figure X.X.
To ensure compatibility with the servo motors, these analog readings, originally in
the 0 to 1023 range, are converted to pulse widths between 900 and 2100 microseconds.
This conversion allows the joystick's position to be accurately translated into servo
angles. The “write()” function is then used to send these mapped values to the respective
servos which prompt them to move accordingly.
Following each set of commands, the program pauses briefly for 15 milliseconds
which gives the servos time to adjust before the next input is processed. This loop runs
continuously which enables real-time control of the servo positions based on joystick
movements.
1.4. LCDS
In this project, an Arduino Uno microcontroller is used to interface with a Liquid
Crystal Display (LCD), which serves as the main visual output for displaying data and
messages. The LiquidCrystal library is utilized to handle the communication between the
Arduino and the LCD, simplifying the complex processes involved in rendering
characters on the screen. To enhance usability, a potentiometer is also included in the
circuit, allowing users to adjust the display contrast in real time.
Fig X. LCD Screen Writer Circuit Fig X. LiquidCrystal Library for the
Configuration LCD Screen Writer
The initial phase of this project involved the assembly of the display interface,
beginning with the soldering of a 16x2 liquid crystal display (LCD) module onto a row of
16 male header pins. Once the soldering was completed, male-to-female jumper wires
were used to interface the LCD with the breadboard. Following this, the LCD was wired
to the Arduino UNO according to the standard pin configuration, as outlined in the
corresponding connection table.
Table X presents the complete pin configuration used for connecting the LCD
module with the Arduino UNO. It outlines the specific connections established between
each pin of the LCD and the corresponding digital or analog pins of the microcontroller,
including the power supply, ground, data lines, and control lines.
Upon completion of all hardware interconnections, the code for the project was
uploaded to the Arduino UNO using the Arduino IDE. The LCD immediately displayed
the expected output, confirming that both the hardware setup and software execution
were working as intended.
Figure X illustrates the LCD Screenwriter flowchart. It begins with including the
LiquidCrystal.h library and initializing the LCD with defined pin assignments. Once set
up, the display prints the message "Arduino Sketch" and enters a repeating loop that
manipulates text scrolling with precise timing.
The project began with the placement of the seven-segment display and the
74HC595 shift register onto the breadboard. Once both components were correctly
positioned, the necessary wiring connections were made, following the appropriate pin
configuration as shown in the table below.
Table X shows the pin configuration between the seven-segment LED display and
the 74HC595 shift register. Each segment of the display is connected to a corresponding
output pin on the shift register. Specifically, the shift register's output pins are wired to
the segment pins of the seven-segment display as outlined in the table. To prevent
excessive current from damaging the LED segments, 220-ohm resistors are placed in
series between the shift register outputs and the segment input pins.
Pin 12 Pin 8
Pin 13 GND
Pin 14 Pin 11
Pin 16 +5V
Pulse Pin 2
Following this, the 74HC595 shift register was interfaced with the Arduino UNO
microcontroller. This step involved establishing precise connections between specific
shift register pins and designated Arduino pins, including power supply lines (+5V and
GND), as well as the data input, clock, and latch control lines. These connections,
detailed in Table Y, are essential for enabling the Arduino to transmit serial data to the
shift register, which in turn controls the outputs connected to the seven-segment display.
A push button was added to the circuit to allow user input, with one terminal
connected to digital pin 2 of the Arduino and the other to ground. When pressed, the
Arduino detected the input and triggered a response. After verifying the connections, the
program was uploaded using the Arduino IDE. It used the built-in shiftOut() function to
send data to the shift register, which controlled the active segments of the display. Each
button press generated a random number between 1 and 6, displaying it on the
seven-segment display like a digital die.
1.6. SECURITY
This project involves the use of an ultrasonic sensor in order to detect intruders.
The ultrasonic sensor works by using the amount of time that sound travels to measure
the distance of an object from the sensor. When the sound produced by a sensor hits an
object 15 cm in front of it, the sound bounces back and is detected by the sensor and it
sends a signal to the Arduino through the echo pin. After receiving the signal, the arduino
sends a signal to a servo motor and changes the lit LED from green to red.
Servo ARDUINO
Red +5V
Brown GND
Yellow Pin 9
TableX
Table X shows that the brown wire of the servo sensor is connected to the
Arduino GND, the red wire is connected to +5V, while the yellow wire is connected to
pin 9. This shows that the servo is operating at 5 volts.
LEDs ARDUINO
Negative legs GND
Positive leg (red) Pin 2 via
220-ohm resistor
Positive leg (green) Pin 3 via
220-ohm resistor
TableX
Table X shows that the negative legs of the LEDs are connected to the Arduino
GND, the red led positive leg is connected to pin 2, while the green led is connected to
pin 3. Resistors were used to regulate the current to prevent the LEDs from taking in
excessive power.
Fig X
Fig X shows the overall connection of the embedded system. The wires were
connected in the proper pin configuration.
Fig X
The flowchart shows how the security system works. If an object, presumably an
intruder, is detected, the servo moves and the red LED is lit while the green LED is
turned off; otherwise, the servo remains static while the green LED is lit while the red
LED is turned off.
1.1. LED
The figure shows the complete configuration of the Arduino-based light dimmer
circuit. It includes a potentiometer, an LED, and the necessary connections to the
Arduino Uno. The potentiometer is utilized as an analog input device, and the LED is the
output component whose brightness is adjustable. The circuit connects the potentiometer
to analog pin A0 and the LED to digital pin 9 via a 470-ohm resistor, allowing the
Arduino to read varying voltage levels and alter the LED intensity using Pulse Width
Modulation (PWM).
This configuration efficiently illustrates the concept of analog input and PWM
output in a microcontroller system. It demonstrates how user contact with a basic
hardware component (the potentiometer) may affect the behavior of another component
(the LED) in real time.As seen in the figure, when the potentiometer is set to a lower
resistance (low ohms), it sends a lower voltage to the Arduino, resulting in a lower PWM
signal. As a result, the LED receives shorter power pulses, making it appear less bright.
When the potentiometer is turned to its highest resistance setting, it generates a greater
analog voltage, which the Arduino converts to a wider PWM signal. This increases the
brightness of the LED, demonstrating the proportional link between analog input and
LED output intensity.
1.2. SOUND
The Memory Game system operates by flashing a sequence of LEDs
accompanied by corresponding tones from a piezo buzzer. Each LED is assigned a
distinct tone and is paired with a specific pushbutton for player input. At the beginning of
the game, all LEDs flash in a preset order, as shown in Figure X.X. This initial display
serves as a visual indicator that the system is powered on and ready to start.
Fig X.X.
Following the initialization sequence, the game begins with the Arduino selecting
a random LED to light up. This marks the first step in the pattern that the player must
observe and replicate. To ensure that the pattern changes every time the game is played,
the Arduino uses “randomSeed(analogRead(0))”, which introduces randomness by
reading electrical noise from an unused analog pin. To test if the game is working, two
test scenarios were conducted, one where the player successfully follows the sequence
and another where the player fails.
LED Sequence
Game Sequence Player Input
Step
Table X.X. Game and Player LED Sequence Showing Winning Scenario
The table presents the results from the winning scenario, in which the player
successfully followed the LED sequence generated by the game. Each step of the game
sequence, where the system lights up LEDs in a specific order (green and green) is
matched by the player’s input, with no errors in timing or order. The player pressed the
correct buttons that corresponded to each LED, and the inputs were recorded accurately
by the Arduino. Since there were no mismatches or errors, the round is considered a
successful attempt, demonstrating that the memory game operated as intended during this
trial.
In addition, each time the player correctly repeats the sequence, the system adds
another random LED to the pattern which makes the game more difficult. This process
repeats and becomes more challenging with every correct round, continuing until the
player eventually enters an incorrect input.
After completing the previous round successfully, the system proceeds to the next
by adding another random LED to the existing sequence which makes the game more
challenging. However, in the next scenario, the player will intentionally fail to correctly
replicate the extended pattern.
LED Sequence
Game Sequence Player Input
Step
4 -
Table X.X. Game and Player LED Sequence Showing Losing Scenario
In this table, the results illustrate a losing scenario in the memory game. The game
begins with a sequence of LEDs lighting up in the order which is green, green, blue, and
green. During the first two steps, the player correctly replicates the pattern by pressing
the corresponding buttons for the green LEDs. However, in the third step, the system
lights up the blue LED, but the player mistakenly presses the green LED instead.
This incorrect response marks a failure to recall the sequence accurately which
leads to being unable to continue to the fourth step. The reason behind this is when an
incorrect button is pressed, a distinct tone plays to indicate the error, and the fail()
function is executed, which resets both arrays and restarts the game. This keeps the game
in a loop and allows the player to try again.
Based on the two test scenarios conducted by the group, it can be concluded that
the memory game worked as intended. The system was able to recognize correct and
incorrect responses, provided immediate feedback, and properly reset after an error which
allowed the game to run smoothly.
1.3. SERVOS
The results of the Joystick-Controlled Laser System experiment are presented
through a series of images that clearly demonstrate how the system responds to different
joystick movements. These images provide evidence of the system’s ability to convert
analog input from the joystick into accurate servo motor adjustments, which in turn
control the laser’s direction. By manipulating the joystick in different directions, up,
down, left, and right, the user is able to control the angles of two servo motors mounted
on a pan-and-tilt platform, effectively guiding the laser’s position.
Figure X.X. Joystick Toggled in Upward Figure X.X. Joystick Toggled in Downward
Direction Direction
In Figure X.X, the joystick is pushed upward, causing the tilt servo to move the
laser platform in the same direction. This action corresponds to a decrease in the Y-axis
analog value, which the system accurately maps to a specific pulse width using the
“map()” function. The servo’s upward movement confirms that the input was processed
correctly and translated into precise motion within the intended tilt range. On the other
hand, in Figure X.X , the joystick is toggled downward, causing the tilt servo to rotate the
laser platform downward. This shows that the system correctly detected an increase in the
Y-axis analog value and responded with an appropriate adjustment in servo angle.
Figure X.X. Joystick Toggled in Leftward Figure X.X. Joystick Toggled in Rightward
Direction Direction
In terms of horizontal motion, in Figure X.X, the joystick is pushed to the left
which prompts the pan servo to rotate the laser in the same direction. This confirms that
the system correctly interprets a decrease in the X-axis analog value and maps it to a
corresponding angle for leftward movement. Similarly, in Figure X.X the joystick is
pushed to the right, and the laser adjusts accordingly by rotating in the rightward
direction. This shows that an increase in the X-axis analog reading is correctly translated
into rightward servo motion. The consistent and symmetrical behavior between left and
right movements further demonstrates that the pan servo operates reliably and responds
as expected to directional input.
1.4. LCDS
This interaction between the potentiometer and the LCD also illustrates a
fundamental concept in embedded systems of how analog inputs can influence digital
outputs. The analog voltage from the potentiometer is continuously interpreted by the
hardware, resulting in real-time changes to the digital display. From the observed figures,
it is evident that the LCD screen’s appearance clearly changes each time the
potentiometer is adjusted. This real-time response highlights how the analog and digital
parts of the circuit work well together and reinforces the Arduino’s capability to interface
effectively with external hardware for interactive applications.
[A] [B]
Fig.X [A] Roll of 6 Displayed on the Electronic Die Circuit
[B] Roll of 1 Displayed on the Electronic Die Circuit
The 74HC595 shift register is used to expand the number of digital outputs,
enabling the Arduino to control multiple display segments using fewer pins. It receives
bits of data from the Arduino, which represent the segments to be turned on. After all
data bits are sent, the latch pin updates the output so the correct number appears on the
display. When the pushbutton is pressed, the Arduino detects the input and initiates an
animation sequence. This includes cycling through digits to simulate the shaking and
rolling of a physical die. Once the animation is complete, the Arduino generates a random
number between 1 and 6 and displays the corresponding digit on the 7-segment display.
As shown in the figure, pressing the button initially displays the number six. A
subsequent press changes the output to a different number, which is three, demonstrating
that the system functions correctly by generating random values with each button press.
From the software perspective, the lookup_7seg array stores hexadecimal codes
for displaying digits 1 to 6 on the common-cathode 7-segment display. Two arrays,
shake_dice and roll_dice, define simple animation patterns to mimic shaking and rolling
effects. The setup() function initializes the I/O pins and seeds the random number
generator, ensuring varied dice outcomes. Moreover, in the loop() function, the program
waits for the button press. Once detected, it plays a shaking animation, then displays the
final random number. Functions like DiceNumber() and AnimateDice() manage the
display logic, making it easier to control how the numbers and animations are shown on
the 7-segment display through the shift register.
Overall, this project illustrates how embedded systems integrate hardware control
and programmed logic to respond to real-world inputs. It highlights efficient pin usage,
timing-based animations, and structured code organization, making it a strong example of
practical embedded system design.
1.6. SECURITY
The results of the embedded system experiment were as expected but a few
changes were needed to be made in the program. The servo write function was modified
to be at 10 degrees instead of 0 and 170 instead of 180. This was done because setting the
servo to its maximum and minimum angles causes it to vibrate and make unwanted
noises. After the modification, the device worked as expected. The activated LED is
green if there is no object 15cm or closer in front of the ultrasonic sensor(Figure X) and
the activated LED is red and the servo rotates to the expected angles if there is an object
otherwise(Figure X).
VI. CONCLUSION
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In accumsan nunc sapien, eget
condimentum purus volutpat eu. Mauris tortor magna, imperdiet a mollis eu, tempor sagittis dui.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Phasellus
suscipit felis id lorem congue lacinia. Nullam at maximus mi. Quisque ultrices lobortis risus, nec
facilisis lorem suscipit ac. Maecenas congue tristique lobortis. Quisque tincidunt a ante et
pulvinar. Morbi rhoncus pharetra mauris, non aliquam lacus dignissim at. - SN, FN MI. Member
1
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In accumsan nunc sapien, eget
condimentum purus volutpat eu. Mauris tortor magna, imperdiet a mollis eu, tempor sagittis dui.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Phasellus
suscipit felis id lorem congue lacinia. Nullam at maximus mi. Quisque ultrices lobortis risus, nec
facilisis lorem suscipit ac. Maecenas congue tristique lobortis. Quisque tincidunt a ante et
pulvinar. Morbi rhoncus pharetra mauris, non aliquam lacus dignissim at. - SN, FN MI. Member
2
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In accumsan nunc sapien, eget
condimentum purus volutpat eu. Mauris tortor magna, imperdiet a mollis eu, tempor sagittis dui.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Phasellus
suscipit felis id lorem congue lacinia. Nullam at maximus mi. Quisque ultrices lobortis risus, nec
facilisis lorem suscipit ac. Maecenas congue tristique lobortis. Quisque tincidunt a ante et
pulvinar. Morbi rhoncus pharetra mauris, non aliquam lacus dignissim at. - SN, FN MI. Member
3
REFERENCES
[1] Lutkevich, Ben. “What Is a Microcontroller and How Does It Work?” TechTarget, Nov. 2019,
www.techtarget.com/iotagenda/definition/microcontroller.
[2] Arduino. “What Is Arduino?” Www.arduino.cc, 5 Feb. 2018,
www.arduino.cc/en/Guide/Introduction/.
[3] “Arduino - Overview - Tutorialspoint.” Www.tutorialspoint.com,
www.tutorialspoint.com/arduino/arduino_overview.htm.
[4] Ben. “What Is an Arduino?” Sparkfun.com, 2019,
learn.sparkfun.com/tutorials/what-is-an-arduino/all.
[5] Arduino. “UNO R3 | Arduino Documentation.” Docs.arduino.cc, 2025,
docs.arduino.cc/hardware/uno-rev3/.
[6] Arduino. “Arduino Integrated Development Environment (IDE) v1 | Arduino Documentation
| Arduino Documentation.” Arduino.cc, 2022,
docs.arduino.cc/software/ide-v1/tutorials/arduino-ide-v1-basics/.
APPENDIX
I. Project 1: LED’s - Light Dimmer
int potPin = A0; // Analog input pin connected to the potentiometer
int potValue = 0; // Value that will be read from the potentiometer
int led = 9; // Pin 9 (connected to the LED) is capable of PWM
// Loops continuously
void loop() {
potValue = analogRead(potPin); // Read potentiometer value
// from A0 pin
analogWrite(led, potValue / 4); // Send potentiometer value to LED
// to control brightness with PWM
delay(10); // Wait for 10 ms
Tone speakerpin;
int starttune[] = { NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4,
NOTE_C4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_F4, NOTE_G4 };
int duration2[] = { 100, 200, 100, 200, 100, 400, 100, 100, 100, 100, 200, 100,
500 };
int note[] = { NOTE_C4, NOTE_C4, NOTE_G4, NOTE_C5, NOTE_G4, NOTE_C5 };
int duration[] = { 100, 100, 100, 300, 100, 300 };
boolean button[] = { 2, 3, 4, 5 }; // Pins connected to pushbutton inputs
boolean ledpin[] = { 8, 9, 10, 11 }; // Pins connected to LEDs
int turn = 0; // Turn counter
int buttonstate = 0; // Check pushbutton state
int randomArray[100]; // Array that can store up to 100 inputs
int inputArray[100];
void setup() {
Serial.begin(9600);
speakerpin.begin(12); // Pin connected to piezo buzzer
for (int x = 0; x < 4; x++) {
pinMode(ledpin[x], OUTPUT); // Set LED pins as output
void loop() {
// Generate the array to be matched by the player
for (int y = 0; y <= 99; y++) {
digitalWrite(ledpin[0], HIGH);
digitalWrite(ledpin[1], HIGH);
digitalWrite(ledpin[2], HIGH);
digitalWrite(ledpin[3], HIGH);
// Play the next note
for (int thisNote = 0; thisNote < 6; thisNote++) {
speakerpin.play(note[thisNote]); // Hold the note
delay(duration[thisNote]); // Stop for the next note
speakerpin.stop();
delay(25);
}
digitalWrite(ledpin[0], LOW);
void setup() {
tilt.attach(9); // Attach tilt servo on pin 9 to the servo object
pan.attach(10); // Attach pan servo on pin 10 to the servo object
}
void loop() {
x = joyX; // Read value of x-axis
(between 0 and 1023)
y = joyY; // Read value of y-axis
(between 0 and 1023)
void setup() {
lcd.begin(16, 2); // Set up the LCD's number of columns and rows
lcd.print("Arduino Sketch"); // Print a message to the LCD
delay(1000);
}
void loop() {
// Scroll 13 positions (string length) to the left to move it offscreen left
for (int positionCounter = 0; positionCounter < 13;
positionCounter++) {
// Scroll one position left
lcd.scrollDisplayLeft();
// Wait a bit
delay(150);
}
// Scroll 29 positions (string length + display length) to the right to move
it offscreen right
for (int positionCounter = 0; positionCounter < 29;
positionCounter++) {
// Scroll one position right
lcd.scrollDisplayRight();
// Wait a bit
delay(150);
}
// Scroll 16 positions (display length + string length) to the left to move
it back to center
for (int positionCounter = 0; positionCounter < 16;
positionCounter++) {
// Scroll one position left
lcd.scrollDisplayLeft();
// Wait a bit
delay(150);
}
// Delay at the end of the full loop
delay(1000);
}
void setup() {
pinMode(latchPin, OUTPUT); // Output pins for controlling the shift register
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(buttonPin, INPUT); // Read switch wire state
digitalWrite(latchPin, LOW); // Display DP on 7-segment display at startup
shiftOut(dataPin, clockPin, MSBFIRST, lookup_7seg[6]);
digitalWrite(latchPin, HIGH);
randomSeed(analogRead(0)); // Generate random seed
}
void loop() {
if (digitalRead(buttonPin)) {
shake_speed = 150; // Reset die shaking speed
delay(30);
// Generate number for random speed and show shaking animation
while (digitalRead(buttonPin)) {
rand_seed++; // Generate random number
// Animate shaking die
if (shake_toggle) {
AnimateDice(0, shake_dice);
shake_toggle = 0;
} else {
AnimateDice(1, shake_dice);
shake_toggle = 1;
}
delay(80 + shake_speed); // Accelerate animation speed
if (shake_speed > 0) {
shake_speed -= 10;
}
}
// Animate rolling die
for (int rolls = 0; rolls < (rand_seed % 10 + 14); rolls++) {
AnimateDice(index, roll_dice);
delay((1 + rolls) * 20);
index++;