Blog 2
- Yujie Lin
- Nov 30, 2023
- 3 min read
Hi again, welcome to my second blog on Arduino Programming. In this blog, I will be documenting about Arduino so join me as we complete 4 tasks together!
For the first task, I will be doing Input Devices
Input devices:
a) 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 |
int sensorPin = A0;
int ledPin = 13;
int sensorValue = 0;
void setup(){
pinMode(ledPin,OUTPUT);
}
void loop(){
sensorValue = analogRead(sensorPin);
digitalWrite(ledPin, HIGH);
delay(sensorValue);
digitalWrite(ledPin, LOW);
delay(sensorValue);
} | The code creates a blinking effect on the LED when the potentiometer is turned. LED 13 blinks faster when potentiometer is turned clockwise. And LED 13 blinks slower when potentiometer is turned anti-clockwise. |
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. One problem i faced is setting up the Arduino and the potentiometer. Initially, my male to male jumper wire configuration were wrong. After uploading the code, I realised that my wiring were in the wrong arrangement. I fixed it by referring to the image and copying the same arrangement.
4. Below is the short video as the evidence that the code/program work.
b) 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 = A0;
int ledPin = 13;
int LDRvalue = 0;
void setup()
{
pinMode(ledPin,OUTPUT);
}
void loop()
{
LDRvalue = analogRead(LDR);
if(LDRvalue > 1000)
digitalWrite(ledPin, HIGH);
else
digitalWrite(ledPin, LOW);
} | LED 13 will light up when it is dark, and LED 13 will be off when there is light |
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.
Initially after i uploaded the code given in the Maker UNO Edu Kit Module, LED 13 was still on. At first i thought that my LDR was broken, but after trial and error of changing the if(LDRvalue > 600) to different values. I finally got it to work when i switched it (LDRvalue > 1000)
4. Below is the short video as the evidence that the code/program work.
That is all for input devices... Now I will be moving on to output devices,
Output Devices:
a) 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 |
void setup() {
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
}
void loop() {
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
delay(200);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
delay(200);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
delay(200);
} | controls three LEDs red yellow and green connected to digital pins 7, 8, and 9 respectively. The LEDs will light up one at a time in a sequence with a delay of 200 milliseconds between each step. |
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.
No major problems encountered, there were only careless mistakes when typing in the code e.g. I typed delay(200) as Delay(200) which caused a compilation error. Fixed it by typing it the correct way.
4. Below is the short video as the evidence that the code/program work.
b) 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 writeable format | Explanation of the code |
const int buttonPin = 2;
bool isRunning = false;
void setup() {
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
if (digitalRead(buttonPin) == LOW) {
isRunning = !isRunning;
while (digitalRead(buttonPin) == LOW) {
delay(10);
}
}
if (isRunning) {
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
delay(200);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
delay(200);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
delay(200);
} else {
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
} | a push button is connected to pin 2. Pressing the button starts/stops a sequence where the LEDs light up one by one. The sequence pauses for 200 milliseconds between each step. Each button press toggles the sequence's state. If the sequence is running, the LEDs light up in order; otherwise, all LEDs are turned off. |
2. Below are the hyperlink to the sources/references that I used to write the code/program
YouTube video:
3. Below are the problems I have encountered and how I fixed them.
Had problems typing in the code for the button press, how i fixed the problem is by watching YouTube tutorials and also using chatgpt.
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
I'm truly grateful for the opportunity to learn coding in my chemical engineering program. Initially, delving into the world of programming, especially with the asynchronous package, felt like deciphering a new language. As I progressed, Arduino introduced another layer of discovery.
While working on the documentation for Challenge 4, I faced particular challenges with completing tasks 3 and 4, which involved making noise and using a servo. Despite having access to provided codes, the implementation proved to be a learning curve.
During a practical session where we were tasked with coding our Pegasus using Arduino, my partner (Jing Yue) and I successfully coded two functions – one for movable wings and the other for playing music. However, when we were assessed, our code seemed to betray us, resulting in the Pegasus only being able to play music. This experience was frustrating as it led to a markdown in our assessment. Nevertheless, it was reassuring to recognize that we possessed the programming skills required for the task. The practical not only challenged us to code independently, without guidance, but also encouraged us to tap into our creativity.
In my opinion, completing these four tasks in the blog was more manageable compared to the initial four challenges, primarily because I had already mastered the fundamentals of Arduino. Additionally, the provided codes really helped out a lot. The novel aspect I gained from these tasks was a deeper understanding of using the breadboard and ensuring the correct connection of male-to-male wires.
In conclusion, I do hope that I can use this learning experience for my teamaker in my CPDD module and maybe in my Final Year Project.
That is all for this Blog on Arduino Programming, I do hope you guys enjoy and see you soon in the next blog.





Comments