Blog 3: Arduino Documentation Blog Entryš©āš»š»
- Valarie Goh
- Dec 3, 2022
- 5 min read
Updated: Jan 19, 2023


Yo sup everyone! š¤ I am back with another blog for CPDD woohoo!š„³ So today I will be sharingš my journey in practical 3 about Ardunio Programming with you all. So let's kick off with the tutorial lesson of the Ardunio Programming session experienceš¤ and I hope yall will learn something from it woohoo! š
There are 4ā£tasks that I will be explaining on this blog 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 an 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 a 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.š»


Below are the code/program I have used and the explanation of the codeš©āš».
āCode/program in a writeable formatš» |
|---|
![]() āvoid setup()
{
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
// turn the LED on
digitalWrite(LED_BUILTIN, HIGH);
// pause the program for <sensorValue> millseconds
delay(sensorValue); // Wait for sensorValue millisecond(s)
// turn the LED off
digitalWrite(LED_BUILTIN, LOW);
// pause the program for <sensorValue> millseconds
delay(sensorValue); // Wait for sensorValue millisecond(s)
} |
āExplanation of the codeš |
|---|
![]() To show that it can blink with the speed when we are turning the potentiometer š
|

Below are the hyperlink to the sources/references that I used to write the code/program.
https://www.instructables.com/Arduino-Potentiometer-Analog-Input-Tinkercad/ https://docs.arduino.cc/built-in-examples/basics/AnalogReadSerial

Below are the problems I have encountered and how I fixed them.

Problem 1:
I did not connect the potentiometer properly as the wire below is short therefore leads didn't blink or light up. I fixed them by using a small tweezer to turn the wire in and insert it into the board properly.

Problem 2:
In the code, I forget to insert the serial.printIn and thought it will appear in the serial monitor, therefore, it lead to nothing showing up in the serial monitor. However, using the reference from the internet I am able to make the serial monitor able to show the signal by using these codes:
Serial.begin(9600);
Serial.println(sensorValue);
int sensorValue = analogRead(A0);
delay(sensorValue);
Below is the short video as evidence that the code/program works.

Input devices: Interface a LDR to maker UNO board and measure/show its signal in serial monitor Arduino IDE.š»:


Below are the code/program I have used and the explanation of the code.
āCode/program in writeable format.š» |
|---|
![]() void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop() {
int ldr=A0;//Set A0(Analog Input) for LDR.
int value=0;
value=analogRead(ldr);//Reads the Value of LDR(light).
Serial.println("value of LDR :");//Prints the value of LDR to Serial Monitor.
Serial.println(value);
if(value<300)
{
digitalWrite(13,HIGH);//Makes the LED glow in Dark.
}
else
{
digitalWrite(13,LOW);//Turns the LED OFF in Light.
}
} |
āExplanation of the codeš |
|---|
āāTo show that the light can blink when it senses the LDRš” ![]()
|

Below are the hyperlink to the sources/references that I used to write the code/program.

Below are the problems I have encountered and how I fixed them.

Problem 1:
I did not connect the wiring correctly causing the sensor of the LDR not to work however I fixed them by taking some parts of the wiring out to see which one is in the wrong position and I try to organize my wiring in an organized method.

Problem 2:
In the codes, I tend to miss out on the semi-colon at the end of the code causing errors to occur therefore, I decided to remember to put a semi-colon by ensuring that the codes are in an organizable way in order to have a better view of the codes.

Below is the short video as evidence that the code/program works.

Output devices: Interface 3 LEDs (Red, Yellow, Green) to maker UNO board and program it to perform something (fade or flash etc)š”š»


Below are the code/program I have used and the explanation of the code.
āCode/program in writeable formatš» |
|---|
![]() int ledRed = 9;
int ledYellow = 6;
int ledGreen = 3;
const int fade = 5;
void setup() {
pinMode(ledRed, OUTPUT);
pinMode(ledYellow, OUTPUT);
pinMode(ledGreen, OUTPUT);
}
void loop() {
//ledRed
for (int i = 0; i <= 255; i++) {
analogWrite(ledRed, i);
delay (fade);
}
for (int i = 255; i >= 0; i--) {
analogWrite(ledRed, i);
delay (fade);
}
//ledYellow
for (int i = 0; i <= 255; i++) {
analogWrite(ledYellow, i);
delay (fade);
}
for (int i = 255; i >= 0; i--) {
analogWrite(ledYellow, i);
delay (fade);
}
//ledGreen
for (int i = 0; i <= 255; i++) {
analogWrite(ledGreen, i);
delay (fade);
}
for (int i = 255; i >= 0; i--) {
analogWrite(ledGreen, i);
delay (fade);
}
//ledYellow
for (int i = 0; i <= 255; i++) {
analogWrite(ledYellow, i);
delay (fade);
}
for (int i = 255; i >= 0; i--) {
analogWrite(ledYellow, i);
delay (fade);
}
}
|
āExplanation of the codeš |
|---|
āāTo show that the light can fade after 5 milliseconds.š” ![]()
|

Below are the hyperlink to the sources/references that I used to write the code/program.
https://www.youtube.com/watch?v=GdNg7rK9GCk&t=4s&ab_channel=PhuongVo

Below are the problems I have encountered and how I fixed them.
Problem 1:

The green and yellow LED blinked instead of fading therefore after many checks by looking at each part of the wiring to see where I go wrong and I found out that I put the wiring in the wrong PIN number I change it immediately and it works instantly.
Problem 2:

In the codes, I did not have any problems however one slight problem is that I tend to add extra stuff like full stop or colon, and how I fixed this will be by checking the codes first before sending them out to the Arduino Board.

Below is the short video as the evidence that the code/program work

Output devices: Include a pushbutton to start/stop the previous task


Below are the code/program I have used and the explanation of the code.
āCode/program in writeable formatš» |
|---|
![]() āint ledRed = 9;
int ledYellow = 6;
int ledGreen = 3;
int button = 7;
const int fade = 10;
void setup() {
pinMode(ledRed, OUTPUT);
pinMode(ledYellow, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(button, INPUT);
}
void loop() {
if(digitalRead(button) == HIGH) {
delay(15);
if(digitalRead(button) == HIGH){
fadeLights();
}
} else {
digitalWrite(ledRed, LOW);
digitalWrite(ledYellow, LOW);
digitalWrite(ledGreen, HIGH);
}
}
void fadeLights(){
for( int i=255; i>=0; i--) {
analogWrite(ledGreen, i);
for( int y = 0; y < 1000; y++){
// if button is released
if (digitalRead(button) == LOW) {
return;
}
}
}
//ledYellow
for( int i=0; i<=255; i++) {
analogWrite(ledYellow, i);
for( int y = 0; y < 400; y++){
// if button is released
if (digitalRead(button) == LOW) {
return;
}
}
}
for( int i=255; i>=0; i--) {
analogWrite(ledYellow, i);
for( int y = 0; y < 400; y++){
// if button is released
if (digitalRead(button) == LOW) {
return;
}
}
}
//ledRed
for( int i=0; i<=255; i++) {
analogWrite(ledRed, i);
for( int y = 0; y < 1000; y++){
// if button is released
if (digitalRead(button) == LOW) {
return;
}
}
}
for( int i=255; i>=0; i--) {
analogWrite(ledRed, i);
for( int y = 0; y < 1000; y++){
// if button is released
if (digitalRead(button) == LOW) {
return;
}
}
}
//ledYellow
for( int i=0; i<=255; i++) {
analogWrite(ledYellow, i);
for( int y = 0; y < 400; y++){
// if button is released
if (digitalRead(button) == LOW) {
return;
}
}
}
for( int i=255; i>=0; i--) {
analogWrite(ledYellow, i);
for( int y = 0; y < 400; y++){
// if button is released
if (digitalRead(button) == LOW) {
return;
}
}
}
//ledGreen
for( int i=0; i<=255; i++) {
analogWrite(ledGreen, i);
for( int y = 0; y < 1000; y++){
// if button is released
if (digitalRead(button) == LOW) {
return;
}
}
}
} |
āExplanation of the codeš |
|---|
āTo show the pushbutton able to utilize to on and off the switch.šš” ![]()
|

Below are the hyperlink to the sources/references that I used to write the code/program.

Below are the problems I have encountered and how I fixed them.
Problem 1:

I have a problem pressing the button in the Arduino Uno as my hand is a bit big however I am able to do it once I get the hang of it or use a tweezer to press the button and see whether it can start and stop the system.
Problem 2:

In the codes, I did not have any problems however one slight problem is that I tend to add extra stuff like full stop or colon, and how I fixed this will be by checking the codes first before sending them out to the Arduino Board.

Below is the short video as the evidence that the code/program work.

Below is my Learning Reflection on the overall Arduino Programming activities.

I feel that the overall experiencešāāļø with Arduino Programmingš» activities was greatš and challengingšŖ like the ones we did in the labš©āš¬ by using different types of codesš» to make the horseš¦ able to flap its wingsš¦ and ensure no lossen parts inside this horseš¦. Even though we struggle a bit for the wingsš¦ to flap it was still manageableš¤ as me and Asraf able to complete it within the time frameā. Other than that we struggleš« trying out the millisš», however, it didn't turn out wellš, therefore, we decided to stopš¤ and continue what we haveš. This is what I and Asraf build for the horseš¦ and below are the codesš» on how to operate thisš©āš§:
āāCode/program in writeable formatš» |
|---|
![]() ā#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
// initialize digital pin 13 and 12 as an output.
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(2); // waits 15 ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees]
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(1); // waits 15 ms for the servo to reach the position
}
// the loop function runs over and over again forever
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(12, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
} |

Finalize the Design of the horsešš¦:
In the previous tutorial class, taught by Mr. TingšØāš« he let us have funš with Arduino Programmingš©āš», and not to lie I grew interested 𤩠in doing programming stuffš©āš» but overall it has been a wonderfulš and fruitful journeyš for this Arduino Programme activities. I feel that these activities can help me through my CA1 prototypingš¤ as one of the requirements is using Arduino Programmingš©āš» and in the future used like in my FYP and many more.š§
As you can see I have come to the end of my blog𤣠I hope you enjoy my blogš and remember to likeā¤ļøļø, shareš¤ and subscribeš¤³. Watchš my other cool blogsš± in my cpdd blog categories𤩠have a great weekend aheadš and all the best for your MST to my SP classmates and friendsš¤š¤. I will be back next year strongeršŖ and better blog š¤see yaš!!!





















Comments