SD12 Q2 Assignments - Week 1-2 - Introduction To Arduino
SD12 Q2 Assignments - Week 1-2 - Introduction To Arduino
Week 1-2
Starting with Arduino
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.
Before you create a new Arduino project in Visual Studio, make sure you
close your current solution by clicking “File” “Close Solution”!!!
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.
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).
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.
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!
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!
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