Arduino Programming
- Mabelle Chan
- Dec 2, 2023
- 4 min read
Updated: Dec 3, 2023
Hi guys! Welcome back to my blog! Today I will be documenting a little about some tasks I have to work on for Arduinos Programming... I hope you guys enjoy my learning journey and find some things relatable when you are figuring out the perfect codes and functions too!
Input devices: (1a)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 |
void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } - - void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // print out the value you read: Serial.println(sensorValue); delay(1000); // delay in between reads for stability } | analogRead(A0) is defined as the analog pin for potentiometer - Serial.begin(9600); is to allow numbers to be print out on the computer screen -
Serial monitor continuous analog print reading. - By turning potentiometer, value of 0 to 1023 can be seen. This number is actually converted from 0-5V to digital numbers that the computer can work with.
|
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.
I had some difficulty inserting the potentiometer pins in 3 different rows on the breadboard so my first attempt did not work. I later noticed the problem and quickly changed at to prevent any short circuit. MORE IMPORTANTLY, I wasted about 15 MINUTES OF MY LIFE trying to solve an error which I later figured out was just a typing error from Sensorvalue to SensorValue... It was the most painful 15mins of my life.
4. Below is the short video as the evidence that the code/program work.
Input devices: (1b)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 ldr; void setup() { // put your setup code here, to run once: pinMode(A0, INPUT); Serial.begin(9600); } void loop() { ldr = analogRead(A0); Serial.println(ldr); delay(300); } | ldr = analogRead(A0); defines the analog pin for LDR Serial.println(ldr); delay(300); Reading is sent to serial monitor at a delay of 300ms for stability - This cycle repeats continuously and changes according to the intensity of light shone at LDR |
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 section, there weren't any issues since it was mostly copied from part 1a with a slight change.
4. Below is the short video as the evidence that the code/program work.
Output devices:(2a)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 LED1 = 13; int LED2 = 12; int LED3 = 11; void setup() { pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); } void loop() { digitalWrite(LED1, HIGH); delay(200); digitalWrite(LED2, HIGH); delay(200); digitalWrite(LED3, HIGH); delay(200); digitalWrite(LED1, LOW); delay(300); digitalWrite(LED2, LOW); delay(300); digitalWrite(LED3, LOW); delay(300); }
| LED 1: Red bulb connected to pin13 LED 2: Yellow bulb connected to pin12 LED 3: Green bulb connected to pin11 - The cycle works where the RED lights up first for 200ms followed by the Yellow and finally the green. - All LEDs light up for 200ms for one round, followed by 300ms for another round and generally repeat continuously over and over 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.
The main problem I faced in this part was finding out I had a faulty red LED... I spent soooooo long figuring out what's wrong with my code only to find out I just had to replace the RED LED with another... This experience gave me something to blame and helped me realise that sometimes the problem is not me HAHAH...
4. Below is the short video as the evidence that the code/program work.
Output devices:(2b)Include the pushbutton on the MakerUno board to start part 2.a. above
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 LED1 = 13; int LED2 = 12; int LED3 = 11; void setup() { Serial.begin(9600);
pinMode(2, INPUT_PULLUP); pinMode(13, OUTPUT); pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); } void loop() { int sensorVal = digitalRead(2); Serial.println(sensorVal); if (sensorVal == HIGH) { digitalWrite(13, LOW); } else { digitalWrite(LED1, HIGH); delay(200); digitalWrite(LED2, HIGH); delay(200); digitalWrite(LED3, HIGH); delay(200); digitalWrite(LED1, LOW); delay(300); digitalWrite(LED2, LOW); delay(300); digitalWrite(LED3, LOW); delay(500); } } | In addition to the first code, a start button has been coded - pinMode(2, INPUT_PULLUP); as Start button under void setup allows for int sensorVal = digitalRead(2); Serial.println(sensorVal); to read start button when pressed. }else{ is just a repetition of part 2a. |
2. Below are the hyperlink to the sources/references that I used to write the code/program.
Name of AI tool | Chatgpt |
Input prompt | An arduino code for a start button function to be added. |
Date generated | 1st December 2023 |
Output generated | int LED1 = 13; int LED2 = 12; int LED3 = 11; void setup() { //start serial connection Serial.begin(9600); //configure pin 2 as an input and enable the internal pull-up resistor pinMode(2, INPUT_PULLUP); pinMode(13, OUTPUT); pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); } void loop() { //read the pushbutton value into a variable int sensorVal = digitalRead(2); //print out the value of the pushbutton Serial.println(sensorVal); // Keep in mind the pull-up means the pushbutton's logic is inverted. It goes // HIGH when it's open, and LOW when it's pressed. Turn on pin 13 when the // button's pressed, and off when it's not: if (sensorVal == HIGH) { digitalWrite(13, LOW); } else { digitalWrite(LED1, HIGH); // turn on LED1 delay(200); // wait for 100ms digitalWrite(LED2, HIGH); // turn on LED2 delay(200); // wait for 100ms digitalWrite(LED3, HIGH); // turn on LED3 delay(200); // wait for 100ms digitalWrite(LED1, LOW); // turn off LED1 delay(300); // wait for 300ms digitalWrite(LED2, LOW); // turn off LED2 delay(300); // wait for 300ms digitalWrite(LED3, LOW); // turn off LED3 delay(300); // wait for 300ms before running program all over again } } |
Impact on submission | Helped me find the code I needed to successfully add a start button function to my code |
3. Below are the problems I have encountered and how I fixed them.
Some problems I encountered was trying to fit in the code i got from chatgpt. I had difficulties adding my original code from part 2a into the final code in part 2b. An error kept coming up when I used for{ but after a few google searches I found out that I should have been using }else{ instead.
4. Below is the short video as the evidence that the code/program work.
My Learning reflection on the overall Arduino programming activities.
In the past 4 weeks, learning Arduino programming has really tested my patience. I’ve never had to try
so many methods again and again before. Doing the Pre Practical 2 task was supposed to be “Easy” since there were many example codes and references given to us.
However, I still faced some problems identifying the errors that popped up when I uploaded the code! Even so, I am still here and I haven’t given up… and I hope I never do too. Learning about programming is a very essential skill! Especially for our final-year project and the prototypes we will be creating soon!
From my experience in Practical 2, I think it is safe to say there is still a lot I need to learn before I can safely say I am a competent user of the Arduino Uno board.
There was a part where my group and I were trying to code the start and stop buttons for the pegasus wings to flap, and it took us close to an hour to figure it out… In the end, I couldn’t even get it to stop. Only the start button was working… Here are some photos and videos of our final product!!

I was still pretty proud of my group for figuring out most of the codes. Next time if time permits, I want to experiment with LED lights! After completing the tasks for this blog, I noticed that there were also many tutorials on YouTube where many kind souls are helping us, newbies, out. The iterative process of trial and error not only solidified my grasp of programming concepts but also instilled a sense of resilience in the face of technical hurdles. Beyond the technical aspects, it also sparked a passion for exploring the limitless possibilities of combining hardware and software to bring ideas to life. This journey has been not just about mastering a programming language but about cultivating a mindset that embraces curiosity and continuous learning. I can’t wait to do more research and will be updating you guys on my progress with Arduino Programming!!
Thanks for reading!!






Comments