Arduino Programming
Arduino Documentation Blog Entry
There are 4 tasks that will be explained in this page:
1. Input devices:
a. Interface a potentiometer analog input to maker UNO board and measure/show its signal in serial monitor Arduino IDE.
b. Interface a LDR to maker UNO board and measure/show its signal in serial monitor Arduino IDE
2. Output devices:
a. Interface 3 LEDs (Red, Yellow, Green) to maker UNO board and program it to perform something (fade or flash etc)
b. Include the pushbutton on the MakerUno board to start/stop part 2.a. above
For each of the tasks, I will describe:
1. The program/code that I have used and an explanation of the code. The code is in writable format (not an image).
2. The sources/references that I used to write the code/program.
3. The problems I encountered and how I fixed them.
4. The evidence that the code/program worked in the form of a video of the executed program/code.
Finally, I will describe:
5. 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.
1. Below are the code/program I have used and the explanation of the code.
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.
When I was trying to show whether the potentiometer works, i realised when I turned the potentiometer, the TempValue that was measured shown in the serial monitor did not change. Initially, I thought that something was wrong with the code that's why there are no changes observed in TempValue when the potentiometer was turned.
But after a long time of navigating the codes around, the potentiometer still did not work. So I went to check the physical components and realised that the potentiometer was quite loose. I tried to straighten the connectors of the potentiometer and push it in further. Finally, there were changes in readings when I turn the potentiometer. So all in all, it was just the connectors of the potentiometer weren’t connected to the breadboard causing no differences in readings when turned.
4. Below is the short video as the evidence that the code/program work.
Input devices: 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.
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 of the biggest problem that I faced was that my LED did not react to the different intensities of light. For example, when I cover LDR with my finger, the LED should light up because the purpose of the LDR is to measure the light intensity and change the resistance when the light level changes allowing the LED to light up when the surrounding light level is low. However, when finished setting up the LED, LDR, and the code, the LED remains lit up when I cover the LDR. Hence, I thought that my arrangement of the components on the breadboard are wrong. So I went on to youtube to watch the different arrangements of the components and changed the code many times, but I still didn’t get the result that I want.
After navigating the code and my arrangement of the components for a long time, I realised that the value of analogRead for the LED to light up when the surrounding light intensity is low was wrongly keyed in. eg. {if (LDR<600); digitalWrite (13, HIGH); } this means that when the light intensity measured is less than 600, the LED will light up.
So one thing I realised is that I copied the code blindly from youtube without realising that my room light intensity was at 30+. Even if I shine extra light onto the LDR, the MAXIMUM light intensity will only reach 160. So no matter how much light I shine or off my room light, the light intensity will still be less than 600. This means that my LED will remain lit up even if I shine light onto it and that is why there are no changes to the LED even when there is a change in the light level.
So after realising that, I look at the serial monitor and adjust the analogRead value according to my room light intensity (which is at 30+). Therefore the new code will be [if (LDR<30); {digitalWrite (13,HIGH);} else {digitalWrite(13,LOW)} ].
Overall, it was just the analogRead value was written wrongly.
4. Below is the short video as the evidence that the code/program work.
Output devices: 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.
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 that I’ve faced was when I was trying to make the LED fade individually,, the first LED did light up slowly, but it didn't fade away. Instead, it blinks off and straight up lights up the next LED.
After that, I realised that I have included the wrong code. Instead of this, [for (brightness = 255; brightness >= 0; brightness -= 5)] i wrote [digitalWrite(11,LOW);]. By doing so, it actually only allows the LED to blink off instead of fading away gradually.
So after knowing my mistake, I've added this code [for (brightness = 255; brightness >= 0; brightness -= 5)] to every LED pin instead of [digitalWrite(11,LOW);].
4. Below is the short video as the evidence that the code/program work.
Output devices: Include pushbutton to start/stop the previous task
1. Below are the code/program I have used and the explanation of the code.
2. Below are the hyperlink to the sources/references that I used to write the code/program.
https://www.youtube.com/watch?v=PC15jBx2UxI&t=160s
3. Below are the problems I have encountered and how I fixed them.
One problem that I’ve faced is that I forgot to keyed in this sentence [int sensorVal = digitalRead(2);] even though i wrote [pinMode(2, INPUT_PULLUP);] in my setup. If this sentence [int sensorVal = digitalRead(2);] wasn’t written even though this [pinMode(2, INPUT_PULLUP);] was written, the button would not work as it comes as a set. It took me quite a while to realise that I missed out on that step. How I realised was I went back to the brightspace and relook back at the resources on the ‘programmable button’ challenge that was given to us and realised that that step was missing. So I went to make the adjustments and the button worked.
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.
Overall, the Arduino programming activities that I went through were quite fun after getting the hang of how to code something to make the Arduino react according.
Initially, I didn't really like coding as I have no idea how the whole arduino listens to the code and reacts to it. Honestly saying, coding seems like a foreign language to me and I have to learn and understand it from scratch. Which is something I really hate as I don't really have the patience and time to learn a new language. I agree that coding really needs more practice and as you practice, you will learn from the mistakes and try to find ways to navigate the code to make it right. This is actually how I learned and get a hang of it.
So I actually took a very long time to complete the arduino pre-practical activity that we have to do before our practical. I didn’t enjoy it.
However, the practical was surprisingly fun and engaging. I didn’t hate it but instead, I enjoyed making the pegasus’ wings flap, adding music to the Arduino, and decorating the pegasus to make it aesthetically pleasing. Isabella and I got an idea to add ‘my little pony’ theme song 👻 to it. We have also designed our pegasus according to one of the characters, twilight sparkle in ‘my little pony’. We didn't design exactly to how it looks, but instead, the color we used was inspired from there.
I realised one of the biggest problem that Isabella and I faced was that we couldn't make our wings flap vigorously. The flapping was not very obvious. We tried different ways to position our servo but still, the wings weren't flapping very vigorously 🙄.
Another problem that we faced was that when we include LED on 2 sides as the eyes of the pegasus, only one side of the LED blinks. The other side wasn't blinking at all. We check the codes that we wrote, and it was all correct, and nothing was missing. We also thought that the LED blow up so we went to change it to a different LED and yet it still didn't blink. we have also checked the connection between the wire to make sure that they are connected. Everything was connected properly and yet our LED still didn't light up. So at one point in time, we just say that we are making the pegusus wink 😉. Suddenly, when we were assembling our pegasus together, the LED that we gave up on started blinking. Till today, I still have no answers to how it suddenly blinked 😕.
So here is a video of how our pegasus work 🤡:
After presenting our pegasus to Dr Noel, he taught us how to present our model in an appropriate manner which is to hide all the cables that are visible. To hide the cable, we can make a box underneath the pegasus and hide our Arduino, breadboard, and wires into that box and cut some holes to allow the connected wires to pass through.
Overall, I enjoyed this practical a lot and it was indeed an enjoyable and enriching session that I had.
Comments
Post a Comment