Arduino Programming

Hi! Today, I will be sharing with you my Arduino documentary and my experience. Sadly, this will be my last blog of this term 😔😢😭. But I will be back in the new term!!!👍👍👍


Below, I will be mentioning and listing down the things that I will be going through today.



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 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 video of the
    executed program/code.

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.

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);

}



Specific Code

Explanation

int ledPin = 13;

Introduce a variable “ledPin” and set it to be 13

void setup()

The program will run when the Arduino Uno board is powered or when the reset button is pressed

pinMode(ledPin,OUTPUT)

Select the ledPin as the output

void loop()

Loops the code in the bracket { }

digitalWrite(ledPin, HIGH);

Set the voltage of the ledPin to be high to on the LED

digitalWrite(ledPin, LOW);

Set the voltage of the ledPin to be low to off the LED 

delay(sensorValue);

Pause for the sensorValue’s value which is in milliseconds

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

This is the link to the Youtube video that I used as a reference:

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

At first, my code could not run due to an error. But, after checking my code again, I realised that I have made a very careless mistake. I did not include the close bracket "}" for my code.😅

After editing my code, it could finally run and the LED light was blinking as it should.

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.

Code

int LDR = A0;

int ledPin = 13;

int LDRvalue = 0;

void setup()

{

pinMode(ledPin,OUTPUT);

}

void loop()

{

LDRvalue = analogRead(LDR);

if(LDRvalue > 600)

digitalWrite(ledPin, HIGH);

else

digitalWrite(ledPin, LOW);

}



Specific Code

Explanation

int ledPin = 13;

Introduce a variable “ledPin” and set it to be 13

void setup()

The program will run when the Arduino Uno board is powered or when the reset button is pressed

pinMode(ledPin,OUTPUT);

Select the ledPin as the output

void loop()

Loops the code in the bracket { }

LDRvalue = analogRead(LDR);

Reads the amount of light that LDR is exposed to

if(LDRvalue > 600)

digitalWrite(ledPin, HIGH);

else

digitalWrite(ledPin, LOW);

If LDRvalue is greater than 600, pin 13 will have high voltage to turn on the LED.


If not, pin 13 will have low voltage to turn off the LED.

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 problem I encountered was that the LDR could not sense that my finger was covering it, blocking any light source from it. Initially, I thought that my code had an error, but I could not find any error. So, I asked my friends that had done this activity and they told me that they also faced this problem. The only way to ensure the LDR could sense that there is no light, was to cover it using a fabric material.

This is why in the video below, I was using my shirt to cover the LDR.

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.

Code

Explanation

int animationSpeed = 0;

 

void setup()

{

 pinMode(13,OUTPUT)

 pinMode(12,OUTPUT)

 pinMode(11,OUTPUT)

}

 

void loop()

{

  animationSpeed = 400;

  digitalWrite(13,HIGH);

  delay(animationSpeed):

  digitalWrite(13,LOW);

  delay(animationSpeed);

  digitalWrite(12,HIGH);

  delay(animationSpeed):

  digitalWrite(12,LOW);

  delay(animationSpeed);

  digitalWrite(11,HIGH);

  delay(animationSpeed):

  digitalWrite(11,LOW);

  delay(animationSpeed);

}

Integer animationSpeed is set to 0


The program will run when the Arduino Uno board is powered or when the reset button is pressed.


pinMode() selects the respective pin number as the output





Loops the code in the bracket { }


animationSpeed is set to 400


digitalWrite() writes the pins to be on or off


delay() is used to pause the program for a certain time which is calculated in milliseconds



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

Youtube video: https://youtu.be/MojSo7OtF9w

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

The only problem I faced while doing this activity was that 2 of the LED lights I used was not bright enough to be seen on my camera.

To fix this, I replaced those 2 LED lights with new ones and thankfully it is brighter.

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.

Code

Explanation

const int greenLedVehicle = 5;

const int yellowLedVehicle = 6;

const int redLedVehicle = 7;

const int greenLedPedestrian = 3;

const int redLedPedestrian = 4;

const int pushButton = 2;

 

 

 

void setup()

{

pinMode(greenLedVehicle, OUTPUT);

pinMode(yellowLedVehicle, OUTPUT);

pinMode(redLedVehicle, OUTPUT);

pinMode(greenLedPedestrian, OUTPUT);

pinMode(redLedPedestrian, OUTPUT);

pinMode(pushButton, INPUT_PULLUP);

digitalWrite(greenLedVehicle, HIGH);

digitalWrite(redLedPedestrian, HIGH);

}

 

void loop()

{

if(digitalRead(pushButton) == LOW)

{

digitalWrite(greenLedVehicle, LOW);

digitalWrite(yellowLedVehicle, HIGH);

delay(2000);

digitalWrite(yellowLedVehicle, LOW);

digitalWrite(redLedVehicle, HIGH);

delay(1000);

digitalWrite(redLedPedestrian, LOW);

digitalWrite(greenLedPedestrian, HIGH);

delay(5000);

digitalWrite(greenLedPedestrian, LOW);

digitalWrite(redLedPedestrian, HIGH);

delay(1000);

digitalWrite(redLedVehicle, LOW);

digitalWrite(greenLedVehicle, HIGH);

}

}

Constant integers that are the primary data-type for number storage

greenLedVehicle = 5

yellowLedVehicle = 6

redLedVehicle = 7

greenLedPedestrian = 3

redLedPedestrian = 4

pushButton = 2

 

The program will run when the Arduino Uno board is powered or when the reset button is pressed.


pinMode() selects the respective pin number as the output











Loops the code in the bracket { }


digitalRead() reads whether the button is being pressed or not


digitalWrite() writes the pins to be on or off


delay() is used to pause the program for a certain time which is calculated in milliseconds


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 problem I faced while doing this activity is similar to the previous activity. One of my LED lights was too dim.

To fix it, I replaced the faulty LED light with a new one.

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.

Honestly, I did not expect that our course would teach us about coding which was quite surprising for me. Having done these Arduino Programming activities, it reminds me of my secondary school days. This is because I actually studied O level Computing back in secondary school. However, I am very bad at coding and I was not really passionate about it, which was why I got a C6 for Computing in O levels.😂😂😂

Initially, I was very lost and clueless for the first lesson on Arduino Programming. I remembered that I had to constantly ask my friends questions and even consult Mr Chua for clarification and help. But as time went back, I started to pick up the pace and I was able to understand and process how the codes work.

Through the lessons on Arduino Programming, I was able to learn new things such as learning how certain code work and the meaning behind it.
  • void setup() suggest that the program will run when the Arduino Uno board is powered or when the reset button is pressed.
  • void loop() will loops the code in the bracket { }
  • pinMode() selects the respective pin number as the output
  • digitalWrite() writes the pins to be on or off
  • delay() is used to pause the program for a certain time which is calculated in milliseconds
Aside from this, one of the more interesting thing I learned was the concept behind how traffic lights work. This is possible due to Activity 2 which is on Output Devices where we had to use LED lights.

Overall, I had a lot of fun doing the Arduino Programming activities together with my groupmates. Although I am not able to fully write out an entire code for a programme, I am still grateful and satisfied with what I have learned. I do hope that we will have the chance to use the Arduino Maker Uno kit again.

Comments

Popular Posts