Arduino Programming

What is Arduino Programming?

Arduino is an open-source electronic platform based on easy-to-use hardware and software used to build electronics projects.
Arduino is designed to make electronics more accessible to artists, designers, hobbyists, and anyone interest in creating interactive objects or environments.

Before starting into programming, there are some common symbols that are required to understand.

MAKER UNO Edu Kit

I will be using this kit for this activity. This MAKER UNO Edu kit consists of the followings.

Maker uno board

Light Emitting Diode (LED)

- output electronic component that emits visible light when current passes through
- must use alongside with a resistor to prevent burning
- polarity, + must be connected to power source, - must be connected to the ground

Breadboard

- allow building of circuit

Jumper/dupont wire

- connect component
- check continuity using multimeter

Resistor

- limit electrical energy in a circuit
- make voltage and current changes
- resistor indicated by color of the stripes

LDR (Light Dependent Resistor)

- resistance decreases with increasing incident light intensity

Transistor

- semi-conductors when electrical conditions is met
- can be used as amplifiers (non-saturation) or switches (saturation)

Potentiometer

- variable resistor

DC motor

- 3V to 6V
- reverse the terminal polarity to rotates in opposite direction


Thinkercad

Thinkercad is a free, easy-to-use wed-based simulation that help to develop and test Arduino code before we execute the code on the Arduino board.

There are four different tasks for this activity.

1. Input devices

a. Interface a Potentiometer Analog Input to maker UNO board and measure its signal in serial monitor Arduino IDE.
b. Interface a LDR to Maker Uno board and measure its signal in serial monitor Arduino IDC.

2. Output devices

a. Interface 3 LEDs (Red, Yellow, Green) to maker UNO board and program it to perform something (fade or flash etc).
b. Interface the DC motor to maker UNO board and program it to on and off using push button on the board.

Before we begin the activities, we are going to learn how to control multiple LEDs using Arduino's digital outputs and breadboard.

Here is a short video on how it is done.
1. Set variable to "animationSpeed"
2. Input speed as "400"
3. Add output and control
4. Change output to corresponding pin number
5. Change control settings to "milliseconds"
6. Change speed to 100 to blink faster.
7. This reduces the delay timing, hence resulting in faster blink.
Now we know how thinkercad works and we can proceed to our activities.

The four activities require the same set-up and modified to the requirement. This set up allow a close circuit for electricity to flow.

1. Drag and place the Arduino Uno R3 and breadboard side-by-side.

2. Connect the positive terminal to the positive terminal (red wire) and the negative terminal to the negative terminal (black wire) on the breadboard. 
3. Connect the negative terminal to GND (black wire) and positive terminal to 5V (red wire). 
The GND (ground) provides a common connection point which is mostly used as reference to all the other electronic parts, soldering is not required. The 5V provides electricity to the breadboard.
 The breadboard is now connected to the Arduino board and is ready to use.

Activity 1a: Interface a Potentiometer Analog Input to maker UNO board and measure its signal in serial monitor Arduino IDE

This activity allow us to read a potentiometer with LED flashing using Arduino's analog input.

1. Add a LED on the breadboard (do not have to be specific).
2. Attach a resistor on the same column as the cathode of the LED.
3. Attach a wire on the same column as the anode of the LED to Pin 13.
4. Add a potentiometer on the same row as the LED.
5. Connect the anode of the potentiometer to the negative terminal of the breadboard.
6. Connect the cathode of the potentiometer to the positive terminal of the breadboard.
7. Connect the center pin to the Arduino pin A0.
A0 is the analog input which senses the gradually changing electrical signals from turning the knobs of the potentiometer.
8. Connect the positive terminal of the multimeter to pin A0.
9. Connect the negative terminal to GND.
Multimeter is used to display analog signal of the voltage.
Input: a new variable is created, sensorValue. This sensorValue is read from the sensor. Variable is set to read analog pin A0. This convert the electrical signals to analog signals shown in the multimeter. 
Output: built-in LED to HIGH which allow the LED to on. There is a delay() in milliseconds for this code. This command will set how long the LED will turn on.
Built-in LED to LOW which off the LED. There is a delay() in milliseconds for this code. This command will set how long the LED will turn off.
Delay() in milliseconds depends on how much the knob of the potentiometer is turned.



Activity 1b: Interface a LDR to maker UNO board and measure its signal in serial monitor Arduino IDE

1. Add a LED on the breadboard (do not have to be specific).
2. Attach a resistor on the same column as the cathode of the LED.
3. Attach a wire on the same column as the anode of the LED to Pin 9.
4. Add a photoresistor on the same row as the LED.
5. Connect the terminal 1 of the photoresistor to the positive terminal of the breadboard.
6. Connect the terminal 2 of the photoresistor to A0 on the Arduino board
A0 is the analog input which senses the gradually changing electrical signals from dimming and brightening of the photoresistor.
7. Connect a resistor horizontally to the same column as terminal 2 of the photoresistor. Connect the other wire at the same column of the resistor (end) to the negative terminal of the breadboard.
8. Connect the positive terminal of the multimeter to pin A0.
9. Connect the negative terminal to GND.
Multimeter is used to display analog signal of the voltage.


Input: a new variable is created, photosensor. Variable is set to read analog pin A0. This convert the electrical signals to analog signals shown in the multimeter. 
Output: print to serial monitor photosensor with newline. This enables the circuit to be able to send messages by providing a communication channel from the photoresistor to the LED.



Activity 2a: Interface 3 LEDs to maker UNO board and program it to perform something

1. Add a red LED on the breadboard (do not have to be specific).
2. Attach a resistor on the same column as the cathode of the red LED.
3. Attach a wire on the same column as the anode of the red LED to Pin 11.
4. Repeat 1-3 with yellow and green LEDs. Connect yellow LED to Pin 10 and green LED to Pin 9.
Input: the control will count up by 15 for brightness from 0 to 255. 0 is the minimum while 255 is the maximum analog output value to fade the LED.
Output: Set pin 11 to brightness and added a control for delay(30) milliseconds. This allow the red LED to fade in and wait for 30 milliseconds to proceed to the next code.

Input: the control will count down by 15 for brightness from 255 to 0.
Output: Set pin 11 to brightness and added a control for delay(30) milliseconds.
This allow the red LED to fade out and wait for 30 milliseconds to proceed to the next code.

With the 2 inputs and outputs, this allow the red LED to fade in and out.
Repeat the loop for yellow and green LEDs with their respective pin 10 and 9.



Activity 2b: Interface the DC motor to maker UNO board and program it to on and off using push button on the board

1. Add a DC motor on the breadboard (do not have to be specific).
2. Attach a resistor on the same column as the cathode of the DC motor.
3. Attach a wire on the same column as the anode of the DC motor to Pin 13.
4. Add a pushbutton on the center divide of the breadboard.
5. Connect two legs of the pushbutton diagonally.
6. Connect terminal 1b to the positive terminal on the breadboard.
7. Connect terminal 2a to the Arduino board Pin 2.
8. Add a 10 kilo-ohms resistor between the Arduino pin and ground. This is called a pulldown resistor which gives the Arduino pin a weak ground connection, so the pin is never floating.
When the button is pushed, the circuit will close. Electricity will be able to flow.
Input: a new variable is created, buttonState. This buttonState is to read the state of the pushbutton. Variable is set to read digital pin 2. A math comparator block was used to evaluate whether the button stat is equal to HIGH. When button is HIGH, it means that it was pressed.
Output: Set built-in LED to HIGH. When the button is pressed, LED will be turned on. Else, set built-in LED to LOW. When the button is released, LED will be offed.



Tips for coding


4 challenges

To test my understanding about Arduino programming, I was assigned to 4 different challenges.


Practical

This project shows how to make an Arduino based programmable button to enable the die cut cardboard unicorn’s wings to simulate the motion of a bird’s wings. It uses an Arduino microcontroller. The microcontroller we will be using is the MAKER UNO Edu Kit with a servo.


Reflection

This is my first time learning programming. Initially I thought programming is very hard as I have seen my friends struggling learning programming from their course. Arduino programming is very straight forward and easy to use. Arduino IDE have examples codes and for us to modify, I do not have to create the whole coding from scratch.
. 
Through the two input activities, I learnt the difference between digital and analog signals. For an analog pin, it can read signals from 0-1023 while digital pin can read signals that is HIGH or LOW (which stands for ON and OFF). These activities also allow me to visualise how a potentiometer and photoresistor works without having the Arduino kit physically. For the next two output activities, I learnt about why some connections has to be made with the number with tilde on them. Eg. ~11, ~10, ~9 and so on. These pins function the same as the other pins but they are special as they can be used for Pulsed-Width Modulation (PWM). This is an output used for analog input which acts as a digital-to-analog converter. This helps to simulate analog output like fading an LED.

While doing the four activities, I have faced challenged like unable to get my LED to light and my DC motor was not working. I found out that I am able to view the source code instead of the flow chart. Many people will feel that the flow chart will be easier to understand and build the code from there, but I find it easier looking at the code. The reason for this is because I have been taught on how to read the code for the html view. I have tried to understand the flow chart code to the html view by comparing both side-by-side. Since I do pure science back in secondary school, I am exposed to what are those and how connecting a circuit works but I was never taught the functions and having hands on activities. Thinkercad allowed me to have a virtual experience to have hands on conducting "experiment" of my learning with the four activities.

Through the four challenges for the pre-practical tasks, I had faced some setbacks and was unable to get the coding right. Arduino IDE was able to highlight my source of error and was easily fixed. During the competency test, I had some difficulties and have resolved the problem. The test and the practical session really helped me to understand how coding works better. 

Learning programming can be useful in the capstone project when I am required to build my chemical product and needed some mechanical work to function. Thinkercad and Arduino programming will come in handy.


References

Tinkercad (2019). Tinkercad. [online] Available at: https://www.tinkercad.com/ [Accessed 27 Nov 2021]. 
‌
youtube (n.d.). LEDs & Breadboards With Arduino in Tinkercad. [online] Available at: https://youtu.be/MojSo7OtF9w [Accessed 27 Nov 2021].

youtube (n.d.). Blink an LED With Arduino in Tinkercad. [online] Available at: https://youtu.be/yyG0koj9nNY [Accessed 27 Nov 2021].

youtube (n.d.). Potentiometer Analog Input With Arduino in Tinkercad. [online] Available at: https://youtu.be/-EDYMQ9lczA [Accessed 27 Nov 2021].

youtube (n.d.). Fading LED With Arduino in Tinkercad. [online] Available at: https://youtu.be/X8dHbdhnGKY [Accessed 27 Nov 2021].