Arduino Programming
- isabelleadora
- Dec 3, 2022
- 4 min read
We started early in week 3 as Arduino programming was something new to all of us and it would take us a while for all of us to get the hang of it. We used the Maker UNO Kit to help us kickstart our Arduino journey.
In this blog, I will show the codes used for the input and output devices we were tasked to work on, explanation of said code, references used, problems encountered & how I fixed them and video evidence of the code working.
Input device - Potentiometer
Code & Explanation
Reference used for code
Problems encountered & how it was fixed
Originally, we connected the Cathode of the LED to the Ground pin and the Anode of the LED to the 5V pin. This caused the LED to not light up. We fixed it by looking online and the guide that the Cathode is the longer leg, hence should be connected to the power source (5V pin) and the Anode is the shorter leg, hence should be connected to the Ground pin.
Video evidence
Input device - LDR
Code & Explanation
Reference used for code https://youtu.be/qKku-mmwNIA
Problems encountered & how it was fixed Initially, in the code, it was written "(light<30)". But when I overed the LDR with my finger, the LED light still remained turned on. After checking the serial monitor, I realised the reading showed it being 80-90 when I covered the LDR with my finger. Hence, I changed it to (light<100), which fixed the problem.
Video evidence
Output device - 3 LEDs
Code & Explanation
Reference used for code https://youtu.be/X8dHbdhnGKY
Problems encountered & how it was fixed The LED was not fading in the correct sequence so we changed the output to match it to the correct LED. But overall, the problems encountered for this was minimal.
Video evidence
Output device - Push button to start 3 LEDs
Code & Explanation
Reference used for code
Problems encountered & how it was fixed It took us a while to figure out the code as there were many missing brackets. After adding in the missing brackets, the code managed to work.
Video evidence
Practical
For this practical, we were tasked to make the wings of a cardboard unicorn flap using a servo, and also add in a secondary function. The secondary function we chose was to play music. The code for the servo was easy as we already prepared it for our pre practical. What was hard was finding an angle that would make the wings flap.
After we decided on an angle, we decided to tape the servo inside the unicorn so that it would be compact. Though, there was a lot of laughter from others as the placement of the servo was quite funny. We also did a lot of trial and error for the speed of how fast the wings should flap. The one in the video flapped really wuickly as the delay we input was 0.
We also added music from My Little Pony, a cartoon that some of us grew up with. The code for music was made by Alvin as he is the most musically inclined in our group. We also decided that the wings should flap more slowly as it would be more majestic. We added a slot and tab as well so that it would be easier to dismantle after we finished the practical and designed our unicorn to look like Rainbow Dash from My Little Pony and ta-da! Our final product is shown below.
Overall, it was such a fun practical and the 3 hours in the lab flew by really quickly.

Reflection
I never actually thought that we would be taking programming during my time in DCHE and so, I took an elective to learn. Surprisingly, it also taught Arduino Programming, so I was not completely lost when Dr Noel introduced this to us. However, in CPDD, it challenged me more as the pre-practicals asked us to modify the code in order for a certain outcome to happen. For example, merging the push button code with the music code. Initially, I just copied codes from the resources given to me or online but I did not understand what it meant. However, after a lot of practice, I realised there was a pattern and through trial and error, we can get what we want to achieve. For example, we needed to use ';' to terminate the code and '{}' to enclose multiple lines of code. The Maker UNO kit was definitely not easy to use from the get-go and we used youtube tutorials to learn how to use them. We only had 2 for 4 members so we had to do rotations on who gets the Maker UNO kit. Fortunately, we could use an online simulator called TinkerCAD and I realised we did not have to type out the code one by one of the Arduino application itself. Instead, we could use the code blocks editor to make it easier for ourselves. It will help generate the code for us and it is downloadable.
From the practical, Dr Noel commended us on using slot & tab which is what we learnt from ICPD, and said the reliability of the main function was good. However, he said we could improve more on the aesthetics of the final design and I will keep this in mind for our prototyping.
Overall, this is a very useful skill to have not only in prototyping for CPDD and FYP but especially with the tech sector rapidly rising in terms of job opportunities.



Comments