Arduino Learning Guide For Beginner Using Maker UNO
Arduino Learning Guide For Beginner Using Maker UNO
2 Oct 2018
1. Remove the Maker UNO from the packaging and you will find a set
of label sticker.
2. Peel off the stickers and attach them on the pin headers
accordingly.
|
3. Connect Maker UNO to your PC with a micro USB cable.
1. Log on to https://www.arduino.cc/en/main/software.
|
3. Arduino IDE is an open source software that allows you to
download and use it for free.
However, you are encouraged to make a monetary contribution
to help them to continue to fund their development.
Anyway, you are free to click “JUST DOWNLOAD”.
|
Part 3: Download & Install Driver
3. Click “INSTALL”.
Basic Electronics
Input Devices: Switch, sensor, microphone, potentialmeter, etc.
Output devices: LED, LCD screen, buzzer, speaker, motor, etc.
4. Click “OK”.
|
5. Go to window search, seaarch for “device manager”.
6. Click to expand “Ports (COM & LPT)”. Check which port the CH340
driver is being assigned to. Remember the com number. (For this
example, the com number is com 5)
7. Launch Arduino IDE. Select the right com port. Tools >Ports >COM X
(Make sure your Maker UNO is connected to your PC)
2. Double click the zip file, open the unzip folder then double click the
pkg file.
5. After you have restarted your Mac, launch Arduino IDE again.
Choose the driver in Tools > Port > /dev/cu.wchusbserial1410
4. Click compile , wait for a few seconds until you see “Done
Compiling” appear at the bottom of the sketch.
Troubleshooting
1. If error occurs, go through your code line by line to make sure they are
correct and then compile again.
2. Don’t mixed up the normal backet ( ) and the curly bracket { }.
5. Then click upload . Wait for a few seconds and you will see
“Done Uploading” appear at the bottom of the sketch.
Troubleshooting
1. If error occurs, please check the connection between the Maker UNO and
your PC. Also make sure you have chosen the right driver.
Good To Know
Basic Electronics
Input Devices: Switch, sensor, microphone, potentiometer, etc.
Output devices: LED, LCD screen, buzzer, speaker, motor, etc.
Arduino Function
1. To set a pin as input or output:
pinMode(pin, mode);
pin: the number of the pin whose mode you wish to set
mode: INPUT, OUTPUT or INPUT_PULLUP
2. To turn a digital pin HIGH (on) or LOW (off):
digitalWrite(pin, value);
pin: the pin number
value : HIGH or LOW
2. Click compile , wait for a few seconds until you see “Done
Compiling” appear at the bottom of the sketch.
3. Then click upload . Wait for a few seconds and you will see
“Done uploading” appear at the bottom of the sketch.
6. Observe the result and compare with the previous program. Can
you tell the difference?
How it works
LED 7 is on
The program
Hold for 1000ms will continue
LED 7 is off to loop
Hold for 1000ms endlessly.
.
Good To Know
Arduino Function
1. To pause or hold the program:
delay(ms);
ms: the number of miliseconds to pause
Project 3: Blink the LEDs in Sequence
How it works
Good To Know
Arduino Function
1. To set a pin as input or output:
pin: the number of the pin whose mode you wish to set
mode: INPUT, OUTPUT or INPUT_PULLUP
To fix that problem, we need to
add a delay in between each LED.
digitalWrite(pin, value);
pin: the pin number
value: HIGH or LOW
Challenge
Q: Program LED 2 - LED 13 to execute the blinking pattern as shown
at the demo video below.
1. Open a new sketch then write these codes into the sketch.
Good To Know
Arduino Function
1. To use the on-board push button switch, we need to set it as
“internal pullup input”.
pinMode(2, INPUT_PULLUP);
if (condition 1)
{
// do thing A
}
else if (condition 2)
{
// do thing B
}
else
{
// do thing C
}
4. Modify your previous code into this, then upload to your board.
Hold
2. Don’t mixed up the normal backet for 1000ms.
( ) and the curly bracket { }.
5. Check your result.
How it works
Arduino Function
1. Switch is an input, you need to set that pin as input before you can
use it.
pinMode(pin, INPUT);
Basic Electronics
1. Breadboard internal connectivity.
10K ohm
Arduino VS Arduino
10K ohm
In this project, we are using “pull-up” circuit but both are OK to use.
Challenge
Q: Use both on-board and external switches. When both switches are
not pressed, both LED 4 and LED 5 will be on. If the on-board
switch is pressed, LED 4 goes off. If external switch is pressed, LED 5
would go off.
LED
short leg
long leg
|
3. Upload these codes to your board.
Both on-board LED and the external LED at Pin 5 will blink
after the on-board switch is pressed. Nothing can stop the
program unless the reset button is pressed.
|
How it works
Good To Know
Basic Electronics
|
example:
470 -+ 5%
2. Resistor doesn’t has + and - terminal,
you can connect the pins anyway you
like.. 1st digit 2nd digit multiplier tolerance
0 0 1
3. The color bands on a resistor can tell
1 1 10 1% brown
about its value. Please refer to the chart 2 2 100 2%red
Coding Syntax
A while loop will loop continuously, and infinitely, until the condition
inside the parenthesis, ( ) becomes false.
while (condition)
{
// statements
}
Example:
1. Do something for 200 times
var = 0;
while (var < 200)
{
//do something
var ++;
}
2. Do something endlessly
while (1)
{
// do something
}
|
Project 7: Fade An LED
4. Check your result. It should be exactly the same as the earlier result.
Good To Know
Arduino Function
1. There are 2 types of outputs, digital and analog. Digital means 0 (LOW)
or 1 (HIGH). Analog means variable from 0 to 255. You can use the
following function to control the analog output.
analogWrite(pin, value);
value: HIGH or LOW
2. However, not every pin on the
board has analog output. Only
Pin 3, 5, 6, 9, 10 and 11 has
analog output.
(the pin with ~ sign)
Coding Syntax
1. The beauty of coding is allowing the programmer to simplify a very
long instruction into a few lines of codes that executes same task.
2. Reducing the number of lines also helps to reduce the processing time,
thus it is very important to always optimize your code.
3. In this project, we need to reduce the LED brightness every 200ms. So
we define it as an integer variable at the beginning of our program.
“brightness” is just a variable name, you can name it as A or B if you
Congratulation!
want. You have completed lesson 1and
learnt
4. These arethethefollowing:
comparison commands you can use in coding.
x == y (x is equal to y)
x ! = y (x is not equal to y)
x < y (x is less than y)
x > y (x is greater than y)
x < = y (x is less than or equal to y)
x > = y (x is greater than or equal to y)
1. Open a new sketch, write these codes into the sketch then upload
to your board.
Arduino Function
1. To play a tone from the piezo buzzer.
tone(pin, frequency, duration);
pin: The pin that connected with a piezo buzzer
frequency: the frequency of the tone in hertz
duration: the duration of the tone in miliseconds (whether it is
1 beat, 2 beats or etc.)
2. There is always a delay after tone. The delay has to drag 30% longer
than the tone duration to ensure the tone is completed.
e.g.: The tone duration for 1 beat is 250ms, thus we need to allow
a 325ms delay.
Music Sheet
1. The position of a music note on the staff (i.e. the five horizontal lines)
determines its pitch (the frequency of the piezo buzzer). The higher
the note sits on the staff, the higher the pitch of the sound and vice
versa.
Note C 4 D 4 E 4 F 4 G 4 A 4 B 4 C 5 D 5 E 5 F 5 G 5
Frequency 262 294 330 349 392 440 494 523 587 659 698 784
Note G4 G4 A4 G4 C5 B4
Frequency 392 392 440 392 523 494
1. Modify your previous code into this then upload to your board.
2. Check your result.
How it works
1. Open a sample code. File > Examples > 02 Digital > toneMelody
3. Refer to the same music sheet again then key in the note and note
duration accordingly.
Note G4 G4 A4 G4 C5 B4
Frequency 392 392 440 392 523 494
The program will turn off LED 2- LED 7 all at
Duration 125ms 125msthe same
250ms
time. 250ms 250ms 500ms
Eighth Eighth Quarter Quarter Quarter Half
note (8) note (8) note (4) note (4) note (4) note (2)
4. Check your result.
Coding Syntax
1. Did you notice that the melody only play once and it doesn’t repeat
like the previous programs?
This is because the entire code is written under void setup() instead
of void loop (). You can only repeat it if you reset the program (by
pressing the reset button) .
Example:
{
analogWrite (PWMpin, 1);
delay (10);
analogWrite (PWMpin, 2);
delay (10);
analogWrite (PWMpin, 3);
delay (10);
analogWrite (PWMpin, 4);
delay (10);
}
The above codes can be shorten into 3 lines using “for” statement
shown below:
Good To Know
Arduino Function
1. Only pin A0, A1, A2, A3, A4 and A5 have analog input function. Hence
we need to connect the analog sensors to these pins if we need analog
input values.
4. Click the serial monitor to observe the analog input’s value. Move
your palm closer to the IR sensor to see the changes of the analog
value.
5. Check your result.
How it works
8cm
10cm
7cm
3cm
3. Draw a black line with 2cm thickness in the middle of the cardboard
using the black marker.
2cm
2cm
5. Write these codes into a new sketch then upload to your board.
5. Observe and record the analog values from the serial monitor when
the IR sensor is facing the white surface and black line respectively.
Analog Value
White surface
Black line
6. Write these codes into a new sketch and then upload to your board.
Note: IRvalue > 500 is the threshold for my case. You can change the
value according to the analog values shown in your serial monitor.
You can pick any value between the white surface and black line.
7. Check your result.
How it works
Challenge
Q: Utilise the analog values from a potentiometer to change the
blinking speed for LED 3.