ARDUINO PROGRAMMING
Hey guys! Weclome back to my third blog entry😎In this blog, I will be documenting my Arduino programming activities and what I have learnt from them😼Sit back, relax, and read on!
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.
https://www.youtube.com/watch?v=-EDYMQ9lczA
3.
Below are the problems I have encountered and
how I fixed them.
I had trouble understanding what the codes meant and why they were placed in a certain order😓I went back to the Arduino learning package to recap on what the different commands meant.
To help me further understand what the different commands meant, I practiced changing the 'delay' values to see if I could play around with it.
Initially, when I ran the program, I realised that my LED was not blinking, and instead only pin13 was blinking. I realised later on that I had inserted my LED the wrong way. The long end of the LED (anode, positive side) should be placed beside the wire connected to pin13, and the short end (cathode, negative side) should be placed beside the resistor.
shorter leg of LED=cathode
Below is the short video as the evidence that the code/program work.
This is with a delay of 200ms with LED_BUILTIN, HIGH, and a delay of 500ms when LED_BUILTIN, LOW:
When turning the potentiometer with (sensorValue):
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.
Below are the hyperlink to the
sources/references that I used to write the code/program.
https://www.youtube.com/watch?v=99dUAe9uqSI
Below are the problems I have encountered and how I fixed them.
When I first uploaded the code, the LED did not light up. I was confused and tried checking the code to see if there was anything wrong with it. However, it seemed fine. I thought that it was due to how much light was exposed to the LDR. I tried to change my environment to a much more dim background, but nothing changed.
I later found out that it was because of the +ve and -ve sign on the breadboard. When the wire was connected to the -ve side, the LED did not light up. This was because the -ve side is connected to ground, and there is no voltage. The resistance is higher and hence the LED did not light up.
On the other hand, the LED lit up when connected to the +ve side. The +ve side is connected to 5V, meaning that its resistance is lower. With a lower resistance, the LED was able to light up.
In a background with brighter lighting, the LDR's resistance decreases. Hence, the LED will be brighter. Whereas with a dimmer lighting, the LDR's resistance increases. Hence, the LED will be dimmer.
Below is the short video as the evidence that the code/program work.
1.
Below are the code/program I have used and
the explanation of the code.
For fading with 1 LED:
2. Below are the hyperlink to the sources/references that I used to write the code/program.
https://www.youtube.com/watch?v=X8dHbdhnGKY
3.
Below are the problems I have encountered and
how I fixed them.
I did not face much problems when trying to interface the 3 LEDs. But it was quite fun to challenge myself to modify the code compared to what was provided in the video.
Below is the short video as the evidence that the code/program work.
For fading:
First, the video with 1 LED:
This is the set-up for 1 LED:
Second, I modified the set-up and code from the video to interface 3 LEDs:
This is the set-up for 3 LEDs:
1.
Below are the code/program I have used and
the explanation of the code.
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.
There were not much problems I faced when writing the code. I was able to use the code for the pushbutton (from the pre-practical exercises) and modify it so that the LEDs will light up one by one.
Video:
And this is the set up I used:
Below is my Learning Reflection on the overall Arduino Programming activities.
Despite doing coding for the past 5(?) weeks, I still do not like it😒 It is hard for me to understand how the code works, and most of the time I will tend to forget what the different commands mean. I will have to frequently go back to my notes and refer to their meaning.
Although coding has been extremely frustrating so far, I have to admit that I feel a sense of accomplishment and satisfaction whenever the code I have programmed works. Especially when I had to modify the code from the different youtube videos, I had to do some trial and error since I would miss out some symbols when I checked the code before uploading it.
Overall, most of the Arduino Programming activites were okay, but the one activity that made me really frustrated was the practical activity. During the practical, we had to program the wings of the pegasus to flap up and down, as well as play music from the Arduino board at the same time.
En Ting and I spent some time assembling the pegasus and connecting the servo to the pegasus. It was tricky when trying to imagine the orientation of the wings and how the servo should be placed. Nonetheless, we managed to figure it out, though there was room for improvement.
This is the video of our pegasus' wings flapping💨:
The pre-practical preparation came in handy as we were able to use the same code for the servo as the pre-practical. We only changed the angle and the delay of the servo to make the wings flap faster.
Next, we wanted to include music with the flapping of the wings. We could do so by using the code provided in the pre-practical package. However, I think En Ting and I can agree that we were just not cut out for coding😖We spent half the practical trying to combine the code with servo + together with the code with the music. Although I managed to write a code with all the notes in the song we wanted to play, we could not find a way to combine the 2😭
This led to us only being able to make the pegasus' wings flap using the servo. I think we could have tried better to make it work, but by then our brains were fried and we were unable to think anymore😪
I think with enough practice, I will get better at coding. I may even develop a liking towards it, but I do not see that happening soon..lol. Anyways, it was fun working with my group, we were able to share the song that Kieth managed to program as well, haha. I hope we will be able to learn more from each other in time to come 😌
Picture with my group! (and our pegasus) 🎠
And this is the code of the song we wanted to include: (its very long)
#include "pitches.h"
int const TEMPO = 1200;
int melody[] = {
N_D3, N_D3, N_D4, N_A3, 0, N_GS3, N_G3, N_F3, N_D3, N_F3, N_G3, N_C3, N_C3, N_D4, N_A3, 0, N_GS3, N_G3, N_F3, N_D3, N_F3, N_G3, N_B2, N_B2, N_D4, N_A3, 0, N_GS3, N_G3, N_F3, N_D3, N_F3, N_G3, N_AS2, N_AS2, N_D4, N_A3, 0, N_GS3, N_G3, N_F3, N_D3, N_F3, N_G3, N_D3, N_D3, N_D4, N_A3, 0, N_GS3, N_G3, N_F3, N_D3, N_F3, N_G3, N_C3, N_C3, N_D4, N_A3, 0, N_GS3, N_G3, N_F3, N_D3, N_F3, N_G3, N_B2, N_B2, N_D4, N_A3, 0, N_GS3, N_G3, N_F3, N_D3, N_F3, N_G3, N_AS2, N_AS2, N_D4, N_A3, 0, N_GS3, N_G3, N_F3, N_D3, N_F3, N_G3, N_D4, N_D4, N_D5, N_A4, 0, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, N_C4, N_C4, N_D5, N_A4, 0, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, N_B3, N_B3, N_D5, N_A4, 0, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, N_AS3, N_AS3, N_D5, N_A4, 0, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, N_D4, N_D4, N_D5, N_A4, 0, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, N_C4, N_C4, N_D5, N_A4, 0, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, N_B3, N_B3, N_D5, N_A4, 0, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, N_AS3, N_AS3, N_D5, N_A4, 0, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, N_F4, N_F4, N_F4, N_F4, N_F4, N_D4, N_D4, N_D4, N_F4, N_F4, N_F4, N_G4, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, 0, N_F4, N_F4, N_F4, N_G4, N_GS4, N_A4, N_C5, N_A4, N_D5, N_D5, N_D5, N_A4, N_D5, N_C5, N_F4, N_F4, N_F4, N_F4, N_F4, N_D4, N_D4, N_D4, N_F4, N_F4, N_F4, N_F4, N_D4, N_F4, N_E4, N_D4, N_C4, 0, N_G4, N_E4, N_D4, N_D4, N_D4, N_D4, N_F3, N_G3, N_AS3, N_C4, N_D4, N_F4, N_C5, 0, N_F4, N_D4, N_F4, N_G4, N_GS4, N_G4, N_F4, N_D4, N_GS4, N_G4, N_F4, N_D4, N_F4, N_F4, N_F4, N_GS4, N_A4, N_C5, N_A4, N_GS4, N_G4, N_F4, N_D4, N_E4, N_F4, N_G4, N_A4, N_C5, N_CS5, N_GS4, N_GS4, N_G4, N_F4, N_G4, N_F3, N_G3, N_A3, N_F4, N_E4, N_D4, N_E4, N_F4, N_G4, N_E4, N_A4, N_A4, N_G4, N_F4, N_DS4, N_CS4, N_DS4, 0, N_F4, N_D4, N_F4, N_G4, N_GS4, N_G4, N_F4, N_D4, N_GS4, N_G4, N_F4, N_D4, N_F4, N_F4, N_F4, N_GS4, N_A4, N_C5, N_A4, N_GS4, N_G4, N_F4, N_D4, N_E4, N_F4, N_G4, N_A4, N_C5, N_CS5, N_GS4, N_GS4, N_G4, N_F4, N_G4, N_F3, N_G3, N_A3, N_F4, N_E4, N_D4, N_E4, N_F4, N_G4, N_E4, N_A4, N_A4, N_G4, N_F4, N_DS4, N_CS4, N_DS4,
};
int noteDurations[] = {
16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 8, 16, 8, 8, 8, 8, 4, 16, 8, 16, 8, 8, 8, 16, 16, 16, 16, 16, 8, 8, 16, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 2, 8, 16, 8, 8, 8, 8, 4, 16, 8, 16, 8, 8, 8, 8, 8, 16, 8, 16, 8, 8, 8, 8, 8, 8, 8, 16, 8, 15, 8, 8, 2, 3, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 8, 2, 16, 8, 16, 8, 16, 16, 16, 16, 16, 16, 8, 8, 8, 8, 8, 8, 16, 16, 16, 2, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 2, 8, 8, 8, 8, 2, 2, 3, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 8, 2, 16, 8, 16, 8, 16, 16, 16, 16, 16, 16, 8, 8, 8, 8, 8, 8, 16, 16, 16, 2, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 2, 8, 8, 8, 8, 2, 1
};
//melody = 266 notes
void setup() {
int melody_len = sizeof(melody)/sizeof(melody[0]);
for (int thisNote = 0; thisNote < melody_len; thisNote++) {
int noteDuration = TEMPO / noteDurations[thisNote];
tone(8, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.45;
delay(pauseBetweenNotes);
noTone(8);
}
}
void loop() {}
And thats all for now! Hope you enjoyed reading how my experience was doing coding for the first time😌

Comments
Post a Comment