0% found this document useful (0 votes)
24 views

SD12 Q2 Assignments - Week 1-2 - Introduction To Arduino

The document provides instructions for 8 assignments to learn about controlling LEDs and reacting to buttons using an Arduino. Students are asked to recreate code examples, build circuits, and write programs to make LEDs blink, toggle with buttons, chase in sequences, and respond to potentiometers.

Uploaded by

martinhhh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

SD12 Q2 Assignments - Week 1-2 - Introduction To Arduino

The document provides instructions for 8 assignments to learn about controlling LEDs and reacting to buttons using an Arduino. Students are asked to recreate code examples, build circuits, and write programs to make LEDs blink, toggle with buttons, chase in sequences, and respond to potentiometers.

Uploaded by

martinhhh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Practicum assignments SD12 Q2

Week 1-2
Starting with Arduino

Assignments must be finished before week 3 practicum!

Nico van der Aa & Marcel Peeters, November 2018


Required components for this practicum
For building the circuits for this practicum, you prepared an Arduino shield during the
General Engineering Skills (GES) course in the previous semester. The shield consists of:
 RGB led (1x, common cathode) to PWM pins 9, 10, 11 (in the order R, G, B)
 2 x Green LEDs to pins 12 and 13
 2 x Yellow / orange LEDs to pins 7 and 8
 2 x Red LEDs to pins 5 and 6
 3 x pushbuttons (pull-down) at pins 2, 3, 4 and
 2 x POT meters to PIN A0 and A1.
The layout picture below describes the components and pin numbers in even more
detail. All practicum exercises in this course can be carried out using this shield as long
as the correct pin numbers of the Arduino are assigned in the software.

Alternatively, you can build the circuits for this week using a plain breadboard with the
following components: 1 x push button, 1 x 10 kΩ resistor, 4 x LED, 4 x 1 kΩ resistor and
wires for making the connections. Note that all these components are also available on
your myDAQ add-on PCB, so you can use this board instead as well. Make sure you use
the 1 kΩ resistors (brown – black – black – brown – brown) for the LEDs and the 10 kΩ
resistors (brown – black – black – red - brown) for the inputs. Using the wrong resistors
may damage your Arduino or LED!
Please use the pins for the components as mentioned in the picture above such that
the teacher can easily verify your assignment when signing off the assignments!
Assignment 1: Installing the development environment
Before you can start with the practicum assignments, you’ll need a development
environment which allows you to create programs for your Arduino. We’ll be using the
Microsoft Visual Studio environment with the Visual Micro plugin.

Microsoft Visual Studio should already be on your PC from the earlier Software Design
practicums. An installation manual for the Arduino software and the Visual Micro plugin
can be found on N@Tschool.

More information about Arduino and many examples / tutorials can be found on the
Arduino website: http://www.arduino.cc
Make sure to look in the tutorials and language reference on this website for solutions
to the problems you run into. Much of what you need can be found there.

Assignment 2: Controlling an LED


In this assignment you’ll learn how to digitally control an LED using the Arduino.

Go to: http://arduino.cc/en/Tutorial/Blink, carefully read the page, and recreate this


example in Visual Studio. You can use any one of the LEDs on your Arduino shield, or
you can build the circuit below using the components on your myDAQ add-on PCB
(make sure you use a 1 kΩ resistor, and check the polarity of your LED):

Does the LED blink?


Can you also change the program in such a way that the LED blinks faster or slower?
After that, you can continue with the next assignment.
Assignment 3: Reacting to buttons
Next to showing information (e.g. using the LED from the last example), we also want to
be able to input information into our system. A simple form of input is a push button. In
this assignment you’ll learn how a button can be used for (digital) input.

Before you create a new Arduino project in Visual Studio, make sure you
close your current solution by clicking “File”  “Close Solution”!!!

Go to: http://arduino.cc/en/Tutorial/Button. Carefully read the page and recreate the


example using a pushbutton and an LED on the Arduino shield or using the components
on your myDAQ add-on PCB (with a 1 kΩ resistor for the LED, and a 10 kΩ resistor for
the push button).

If all went well, the LED should now be on if the button is pushed, and turned off again
when the button is released. Can you change the program in such a way that the LED is
on if the button is not pushed, and turns off when the button is pushed?

Now change your code again, to make the pushbutton work as a toggle switch: when
the button is pressed once, the LED should turn on (and stay on after you release the
button), and when the button is pressed again the LED is turned off.

Does this work reliably? Does the LED indeed toggle each time you push the button?

Probably, the LED will sometimes toggle correctly, but sometimes not. We’ll get back to
push buttons and how to solve this in Assignment 5.
Assignment 4: Controlling an array of LEDs
Now that you figured out how to control a single LED, let’s setup an array of LEDs. Use
at least 4 LEDs of the two traffic lights on your Arduino shield or just repeat the
hardware setup of Assignment 2, but now four times as shown in the figure below.

Change the blinking program of Assignment 2 in such a way, that you get a running LED
array. Turn the first LED on for 0.1 s. Next, turn this LED off and turn the second LED on
(again for 0.1 s). Again, turn this LED off and turn the third LED on, and so on. When the
last LED is turned off, turn the first LED on again. Keep repeating this.

Now change your program in such a way that you can change the speed of the chase
lights by changing just one constant in your program.

After you finished this assignment, you can continue with the next assignment, where
you will reuse the hardware of this assignment.

Assignment 5: LED array reacting to button clicks


In this assignment, we will extend Assignment 4 by adding a pushbutton to have the LED
array advance each time the pushbutton is pressed. So, if the first LED is on, the switch
to the second LED occurs when the pushbutton is pressed. Similarly, the switch from the
second LED to the third LED occurs when the pushbutton is pressed once more, and so
on.

For the Arduino shield, use one of the three push buttons available on the shield to
extend the functionality of Assignment 4. If you use the myDAQ add-on PCB, the first
thing you have to do is to extend the hardware configuration of Assignment 4 by adding
a pushbutton as can be seen in the figure below.

Adapt your program, such that you can control the LED array by using the pushbutton.
Each time the button is pressed, the array advances to the next LED. You are allowed to
continue in the same project from Assignment 4 (so you do not need to create a new
project).

Does your program work reliably? The effect you notice is called the bouncing effect,
which is present in every button or switch. On http://arduino.cc/en/Tutorial/Debounce
you can find a tutorial which shows how to solve this problem (debouncing an input).

Implement this solution in your program!

Hint: first just run the debounce example from the Arduino website and try to figure out
how this works. Then combine your previous code with this code to make your LED
array react to button presses reliably.
Assignment 6: Arduino shield
To validate the complete functionality of the Arduino shield you created in GES during
the last quarter, we prepared some code. On N@tschool, you can find an ino-file named
“sketch_SD12_Arduino_shield.ino”. Like many programs for Arduino, this ino-file has
been created with the Arduino SDK.

We are going to convert this Arduino sketch (as ino-files are normally called) to a Visual
Studio project, which we’ll regularly use throughout this quarter.

Step 1: Create a Visual Studio project from existing code


Create a folder named “sketch_SD12_Arduino_shield” inside the Arduino folder in your
Documents folder. Make sure the folder is named exactly as shown! Now copy the
“sketch_SD12_Arduino_shield.ino” file you downloaded from N@Tschool into this
folder.

Start Visual Studio 2017, and click “vMicro”  “Open Existing Arduino Project” and
select the ino-file you just downloaded. If you get a question about Inconsistent Line
Endings, just click “Yes”. You have now created a Visual Studio project containing the
downloaded Arduino code.

Build and upload your project to make sure the code runs on your Arduino!

Step 2: Describe the functionality of this code


By reading through the code, and playing with the buttons and potentiometers on your
Arduino shield, try to understand what this program does. Describe the functionality of
this program using a flowchart.

Note that we often start with a high-level flowchart, only describing the structure and
functionality of the code in big blocks. This does not yet contain the details of how each
block works; we’ll fill those in later. For now, this high-level flowchart is sufficient.

Do make sure that the loop of the Arduino program is clearly visible in your flowchart!

Step 3: Linking the code to your flowchart


For each block in your flowchart, indicate which lines of code correspond to that block.

Step 4: Debugging the code


Although the current code is working fine, we would like you to get some practice with
debugging. Use serial communication to display events like “LED X on/off”, “button X
pressed”, and “potentiometer X changed” to the serial monitor in such a way that, even
without the shield, it would be possible to see what the program is doing.
Assignment 7: LED array with variable speed (optional)
In your hardware configuration from Assignment 5, replace the pushbutton with a
potentiometer from the Arduino Shield or use the 10 kΩ potentiometer from your
myDAQ add-on board. Now change your code such that you can control the speed of
the chase lights with the potentiometer.

Assignment 8: Slowly fading LED (optional)


Again, use your hardware from the previous assignment (Assignment 4, 5 or 7).

a) Create a program that makes one LED slowly fade in and out.

b) Extend your program such that it makes each LED of the chase lights slowly fade
in and out in sequence. Make sure you first think about how to solve this before
you start writing code!

References
Need help? These websites contain helpful information for working with Arduino:
 The Arduino homepage: http://www.arduino.cc.
 Need help programming the Arduino?
o For program structures, types and functions, go to:
http://arduino.cc/en/Reference/
o Tutorials with e.g. the use of buttons and LEDs can be found on:
http://arduino.cc/en/Tutorial/
 Arduino foundations: http://arduino.cc/en/Tutorial/Foundations
 Drawing your own breadboard circuits? Have a look at: http://fritzing.org
 More practice with Arduino? Many tutorials and examples can be found on the
internet, for example on: http://www.ladyada.net/learn/arduino

You might also like