Arduino Programming
- Ruba Sulaiman
- Nov 23, 2022
- 4 min read
Updated: Nov 30, 2022
There are 4 tasks that will be explained in this page:
Input devices:
Interface a potentiometer analog input to maker UNO board and measure/show its signal in serial monitor Arduino IDE.
Interface a LDR to maker UNO board and measure/show its signal in serial monitor Arduino IDE
Output devices:
Interface 3 LEDs (Red, Yellow, Green) to maker UNO board and program it to perform something (fade or flash etc)
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 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.
INPUT DEVICES: POTENTIOMETER
CODE & EXPLANATION
SOURCES & REFERNCES
PROBLEMS ENCOUNTERED & HOW I FIXED THEM Previous codes that did not accomplish the challenge consisted of the led turning on and its brightness not being affected by the turning of the potentiometer, and the led not turning on no matter how much i turn the potentiometer. The problem was I did not include a program line that scaled brightness to the analog value. After adding it in, the code worked.
VIDEO EVIDENCE


INPUT DEVICES: LDR
CODE & EXPLANATION
SOURCES & REFERNCES
PROBLEMS ENCOUNTERED & HOW I FIXED THEM
The main problem I faced was that the values of analog and brightness were scaled wrongly at first. It is supposed to be that when analog increases, brightness decreases as analog is the resistance of the LDR. However, when I tried to fix it by switching the numbers around in the scaling of brightness code, the relationship between analog and brightness was still wrong with analog decreasing and brightness decreasing. Turns out the pins were placed at incorrect positions, as well as the negative and positive connection being switched from the LDR pins. From this I learnt that even though the board is working and the LED is lighting up, the connections may still be wrong.
VIDEO EVIDENCE

OUTPUT DEVICES: 3 LEDs
CODE & EXPLANATION
SOURCES & REFERENCES
PROBLEMS ENCOUNTERED & HOW I FIXED THEM
The main problem I encountered was not with the code, but with my setup. I often had the positve and negative pins of each led in the wrong position, as well as the jumper cables connecting to the wrong places. This was due to using so many wires and being confused. Fixing this was simple as I just had to attach each wire correclty before adding a new wire.
VIDEO EVIDENCE

OUTPUT DEVICES: PUSHBUTTON FOR 3 LEDs
CODE & EXPLANATION
SOURCES & REFERENCES
This code is taken and modified from my code for the pre-practical, for the button. Which was also downloaded and modified from the learning package for Arduino.
PROBLEMS ENCOUNTERED & HOW I FIXED THEM
The main issue I had was just the connections once again, and trying to choose the best delay for the flashing of the LEDs. I was hoping to find a way to make the flashing more smooth and connected to each other, but I did not figure it out. For the connections, I just redid them and worked the jumper wires slowly from each pin.
VIDEO EVIDENCE

PRACTICAL
Code that we used to flap the wings and light up the LED:
To connect the wings of the pegasus/pony, we just used the metal wire instead of the rubberband as it was more durable. We wrapped it around the connections of the wings, and attached the wire to the servo. We did trial and error with the angle of the servo to get the perfect flap, as well as trial and error with the delay to get a majestic flap of the wings.
Metal wire connection

As our extra component, we added a yellow LED light that acts as warm lighting for our pegasus/pony. For aesthetics, we added a flag and a cutiemark :)
To make the whole setup more compact, we cut a hole where the servo would slip in, and added a fence around the servo using icecream sticks.
We also thought of leaving the pegasus/pony unattached to the board, to make it a walking pony, but this compromised the flapping of the wings. So we just attached it to the board :(.
Even though we struggled with the code for the led, where only 1 out of 2 LED would light up, it was the most fun practical by far.
Hero shot



REFLECTION
This topic was definitely the most challening one yet and took a significant amount of time for me to grasp the concept of this kind of coding. Nonetheless, I did enjoy arduino coding immensely and the satisfaction from getting a code right and working on my own somewhat was great. TinkerCAD helped greatly in setting up the arduino board and checking if the code works when I couldn't get my hands on the arduino board, as well as helping me check whether the code works with the setup before I build the setup myself as it saves me time and is faster on TinkerCAD.
For the practical, it was enjoyable and quite stressful as we had a time limit and were very independent in creating our own codes. It was overall a frutiful practical.
Arduino has taught me greatly about coding, and that different codes can work to accomplish the same action.



Comments