Blog 3 (Arduino Programming)
- yanzhen21
- Nov 30, 2022
- 8 min read
Hello everyone! In this blog, I will be sharing with you my journey in learning Arduino Programming. Although it was very challenging, it was an adventurous journey.
There are 4 tasks that will be explained in this page:
1. Input devices:
a) Interface a potentiometer analog input to maker UNO board and measure/show its signal in serial monitor Arduino IDE.
b) Interface a LDR to maker UNO board and measure/show its signal in serial monitor Arduino IDE
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) Include the pushbutton on the MakerUno board to start/stop part 2.a. above
For each of the tasks, I will describe:
The program/code that I have used and explanation of the code. The code is in writable format (not an image).
The sources/references that I used to write the code/program.
The problems I encountered and how I fixed them.
The evidence that the code/program worked in the form of video of the executed program/code.
Finally, I will describe:
My Learning reflection on the overall Arduino programming activities.
Input devices: Interface a potentiometer analog input to maker UNO board and measure/show its signal in serial monitor Arduino IDE.
1. Below are the code/program I have used and the explanation of the code.
Code/program in writeable format | Explanation of the code |
![]() | Inside void setup: pinMode(A0, INPUT) - Establishes analog A0 as an input. pinMode(LED_BUILTIN, OUTPUT) - Establishes digital pin 13 as an output. Inside void loop: sensorValue = analogRead(A0) - It reads the input of the pin and writes into an integer variable, sensorValue. digitalWrite(LED_BUILTIN, HIGH) - turns the LED on by using a digital function delay(sensorValue) - the delay function will change as the knob of the potentiometer is turned. Each time through the loop, it will read its position again. digitalWrite(LED_BUILTIN, LOW) - turns the LED off by using a digital function delay(sensorValue) - the delay function is used again. |
2. Below are the hyperlink to the sources/references that I used to write the code/program.
3. Below are the problems I have encountered and how I fixed them.
After writing the code and completing the setup on the breadboard, I started the program. However, the LED did not flash at all. Initially, I thought the connecting wires were faulty. Thus, I tried changing the wires and even the breadboard but using the same setup configurations. The LED still would not light up. Thus, I changed the LED too. The same problem arises. After a few trial and errors, I noticed when I connected the anode of the LED to the power supply with a connecting wire, the LED started to flash. This is when I found out that the sides of the LED connecting to the power supply actually matters. Since I did not pay attention to this connection, I might have coincidentally connect the cathode of the LED to the power supply in each try. In addition, although the resistor in the setup is connected to the cathode of the LED, I learnt that it did not matter which side of the LED it is connected to.
4. Below is the short video as the evidence that the code/program work.
Input devices: Interface a LDR to maker UNO board and measure/show its signal in serial monitor Arduino IDE:
1. Below are the code/program I have used and the explanation of the code.
Code/program in writeable format | Explanation of the code |
![]() | int light - defining light as an integer Inside void setup: Serial.begin(9600) - Establishes serial communication between your Arduino board and another device. The most common use of serial communication you will establish is between your Arduino and your computer via a USB cable. Inside void loop: light = analogRead(A0) - It reads the input of the pin and writes into an integer variable, light. Serial.println(light) - Print out the value of the integer variable. delay(100) - A delay of 100 milliseconds to print out the light intensity data on the serial monitor. |
2. Below are the hyperlink to the sources/references that I used to write the code/program.
3. Below are the problems I have encountered and how I fixed them.
For this activity, it was smooth-sailing with barely any hiccups during the setup on breadboard and the writing the code on Arduino IDE. However, I will say that the setup might be a bit confusing. Using the video as reference, I can successfully run the program.
4. Below is the short video as the evidence that the code/program work.
Output devices: Interface 3 LEDs (Red, Yellow, Green) to maker UNO board and program it to perform something (fade or flash etc.)
1. Below are the code/program I have used and the explanation of the code.
Code/program in writeable format | Explanation of the code |
![]() | int animationSpeed - defining animationSpeed as an integer variable Inside void setup: pinMode(LED_BUILTIN, OUTPUT) - Establishes pin 13 as an output pinMode(12, OUTPUT) - Establishes pin 12 as an output pinMode(11, OUTPUT) - Establishes pin 11 as an output Inside void loop: animationSpeed = 400 - Establishes the value of the variable to be 400 digitalWrite(LED_BUILTIN, HIGH) - turns the LED on by using a digital function delay(animationSpeed) - A delay of 400 milliseconds (0.4 seconds) before the next action takes place digitalWrite(LED_BUILTIN, LOW) - turns the LED off by using a digital function delay(animationSpeed) - A delay of 400 milliseconds (0.4 seconds) before the next action takes place digitalWrite(12, HIGH) - turns the LED on by using a digital function delay(animationSpeed) - A delay of 400 milliseconds (0.4 seconds) before the next action takes place digitalWrite(12, LOW) - turns the LED off by using a digital function delay(animationSpeed) - A delay of 400 milliseconds (0.4 seconds) before the next action takes place digitalWrite(11, HIGH) - turns the LED on by using a digital function delay(animationSpeed) - A delay of 400 milliseconds (0.4 seconds) before the next action takes place digitalWrite(11, LOW) - turns the LED off by using a digital function delay(animationSpeed) - A delay of 400 milliseconds (0.4 seconds) before the next action takes place |
2. Below are the hyperlink to the sources/references that I used to write the code/program.
3. Below are the problems I have encountered and how I fixed them.
Similar to the last activity, by following the video, I was able to successfully setup the maker UNO and the wrote the code in Arduino IDE with barely any problems. In addition, in the first activity, I had encountered problems with making the LEDs flash. Learning from my mistakes, in this activity, I knew exactly how to setup the LEDs, allowing me to be more efficient in doing this task.
4. Below is the short video as the evidence that the code/program work.
Output devices: Include pushbutton to start/stop the previous task
1. Below are the code/program I have used and the explanation of the code.
Code/program in writable format | Explanation of the code |
![]() | Inside void setup: Serial.begin(9600) - Establishes serial communication between your Arduino board and another device. The most common use of serial communication you will establish is between your Arduino and your computer via a USB cable. pinMode(2, INPUT_PULLUP) - pin 2 is an input and enables the internal pull-up resistor. pinMode(LED_BUILTIN, OUTPUT) - Establishes pin 13 as an output pinMode(12, OUTPUT) - Establishes pin 12 as an output pinMode(11, OUTPUT) - Establishes pin 11 as an output Inside void loop: int sensorVal = digitalRead(2) - It reads the input of pin 2 and writes into an integer variable, sensorVal. When the button is pressed, the status will change to low and releasing it will change the status to high Serial.println(sensorVal) - prints out the value of sensorVal when the button is pressed. If (sensorVal == LOW) - If sensorVal status is LOW, pin 13, pin 12 and pin 11 will be HIGH, else, it will be LOW. In simple English, if the button is pressed, the light will be turned ON, and if the button is not pressed, the light will be OFF.
|
2. Below are the hyperlink to the sources/references that I used to write the code/program.
3. Below are the problems I have encountered and how I fixed them.
This task took me 3 hours to configure. It was by far the most tiresome task out of the 4 tasks given. The setup on the maker UNO board and the breadboard was similar to the previous activity. It was required to integrate the function of the button into the program so that we could control the LEDs through a press of a button on the maker UNO board. My initial idea was to stop the LEDs from flashing when I pushed the button once. Then, when I pushed the button once again, the LEDs will start flashing again. This was very complicated to code. Since the references I had only taught me the action of holding the button for a function to occur. Once the button is released, another function will occur. Thus, I was very clueless on how to allow the function to continue to run after I released the button. As a result, I spent 3 hours on it without making any progress. Therefore, I stuck with a easier idea of making the LEDs to flash when I was pressing the button.
4. Below is the short video as the evidence that the code/program work.
Below is my Learning Reflection on the overall Arduino Programming activities.
To start off, during the introductory lesson on Arduino Programming, I was quite flustered as we were introduced to so many components inside of a maker-UNO kit. The main component would be the maker-UNO board which we could technically call it the "brain" of the whole programming. In my opinion, the second most important component in the kit would be the breadboard. It is where multiple other components such as LEDs and potentiometer could be connected through the breadboard. And I obviously would not forget the jumper wires which would enable the connections between the maker-UNO board and the breadboard. One component that really interests me was the resistors. There were different resistors with different resistance values. And we could actually calculate them using a resistor colour code table. Although there many components to learn and understand, I feel that it is pivotal to acquire greater knowledge to do programming more effectively.
After learning the components of the maker-UNO kit, we needed to understand which ones were the input and out devices. Some of the input devices were potentiometer and the button on the maker-UNO board. Some of the output devices were LEDs and LDRs. Following on, we downloaded a software called "Arduino IDE" which is required to do coding on. Once we booted up the software, it seems like we were on a different planet. Most of us have little to none knowledge about programming. I have only seen my friends from the school of IT do some programming on a software. However, I can confidently say that the programming they do is different from the programming we are doing right now. I kind of learnt that Arduino Programming is for engineers.
We are to complete a learning package which is also part of a pre-practical assignment for our upcoming Arduino Programming practical. There were 4 tasks that was in the learning package. It is different from the 4 tasks that I shared with you above this reflection. In the learning package, I was able to learn various ways to use Arduino Programming to create interesting results. One such task involved us creating a melody produced by the maker-UNO board. That task was actually really fun as we were able to adjust the pitches and make various kinds of melodies. Another task involved a servo motor. Later on, we would realise that understanding the programing for this would be critical for our upcoming practical. In my opinion, this learning package is a great starting point for beginners as not only can we try out different programs to produce different results, but also explained the coding in great detail for us to understand with ease.
Moving on, we attended lesson 2 for Arduino Programming. We had to accomplish the 4 tasks that I had shared with you above this reflection. In this lesson, it was slightly more advanced than the first lesson as now we were dealing with input and output devices. Such devices were the potentiometer, LEDs, the button on the maker-UNO board and LDR. Thus, it was challenging at first but progressively through the tasks, I learnt a lot more of the ways to configure the setups on the breadboard and maker-UNO board through videos from online. In addition, there is a website called Tinkercad which enables people to simulate a real life program on a web. We are able to develop and test our codes on Tinkercad before executing it on the maker-UNO board. This was really time efficient as we only have a maker-UNO kit per pair so the other person in the pair could utilise this web-based software and try it for themselves before translating it into the maker-UNO board. Ultimately, I learnt new codes and the setup configurations which will allow me to be better prepared for the upcoming practical in the following week.
Finally, we have reached practical day to showcase what we have learnt in the past 2 weeks. The agenda of the practical was to construct an aesthetically appealing pegasus and use Arduino Programming to assist in performing some functions. 5 of the main criteria that we were being assessed on were performing the main function which was flapping of the wings, compact and easily moved, reliable and durable, aesthetically pleasing and can perform other function. My partner and I decided to split the workload. I was constructing the pegasus cardboard model using a step guide while my partner was preparing the code of the servo motor. This servo motor would aid us in the movement of the wings. Constructing the pegasus model was relatively easy, however, the difficult part was thinking of a way to install the servo motor on the model. My partner and I decided to use the metal wires that were given to us to act as an extension from the servo to the wings. The metal wires were very malleable which allowed us to install the wires onto the servo by wrapping it around the holes of the turbine. Even though we could easily mould the wires into the shapes we wanted, it was a huge downside. As if we were to stick it on wings and run the program, the metal wires would easily bend and it would be a failure. Thus, I suggested that we use cardboard supports which can act as a pillar to prevent the metal wires from bending easily. When we tried running the program, it sort of worked. However, I would say there was a lot of room for improvement. Moving on, our next focus was to perform another function. We thought using a melody, similar to one we learnt in the previous lesson. However, we wanted to be more creative and use an unique melody from online. However, it was actually disastrous since we had trouble running the code. Therefore, we came up with another idea of installing a fan behind the pegasus to act as a speed boost. This ended up being a really terrible idea since we were not well-informed of the coding for motors. In addition, the setup configurations were quite complicated. And due to time constraints, we were not able to fullfil the criteria of performing another function.
This practical was a great learning experience for me as we had went to unknown territories and it had backfired on us. Even though it was not really a negative sight of exploring new things, we should have come more prepared to execute our desired plan. Truthfully, I lacked creativity and might have affected my performance. However, one important thing that I took home was to always have a positive attitude even though the situation might look grim. Hopefully, I will be able to apply my newly acquired skills in future projects.







Comments