Blog 3 (Arduino Documentation)

 Hello Everyone!🙌😶 Welcome back to my 3rd blog!👀 In this blog, I will be sharing my experience with you about my Arduino Programming Journey.👬So just sit back, relax and enjoy your day.

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 make UNO board and measure/show its signal in serial monitor Arduino IDE.

2. Output devices:
   a. Interface 3 LEDs (Red, Yellow, Green) to make UNO board and program it to perform something (fade or flash etc)
   b. Include the pushbutton on the MarkerUno 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 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.
Finally, I will describe:
      5. My learning reflection on the overall Arduino programming activities.

Input devices: Interface a potentiometer analog input to make 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 writable 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);

}


Before void setup:
int sensorPin = A0; - The potentiometer is connected to analog pin 0.
int ledPin = 13; - The LED is connected to digital pin 13.
int sensorValue = 0; - 

Inside void setup:
pinMode(ledPin, OUTPUT) - Digital pin 13 is the output.

Inside void loop:
sensorValue = analogRead(sensorPin); - reads the value from the sensor and writes an integer variable, sensorValue.
digitalWrite(ledPin, HIGH); - Turns the LED on
delay (sensorValue); - Pause the sensorvValue in milliseconds.
digitalWrite(ledPin, LOW); - Turns the LED off.


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.

I remember the first time trying to do this activity, I followed the Youtube video link shown above and tried to replicate the placements of the potentiometer, wires, LED and resistor in the video onto my Arduino UNO board. However, I realized that my wires do not have any space to fit as shown in the video as the potentiometer is too big. After trying and failing for a few times, I realized that the potentiometer do not need to be fully pushed into the Arduino UNO board. Then, I pull out the potentiometer slightly and inserted the wires into the Arduino UNO board. It finally worked.

 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/program in writable 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 > 600)

digitalWrite(ledPin, HIGH);

else

digitalWrite(ledPin, LOW);

}

 


Before void setup:
int LDR = A0; - LDR is connected to analog pin 0.
int ledPin = 13; - ledPin is connected to digital pin 13.
int LDRvalue = 0; The LDR inital value is 0.

Inside void setup:
pinMode(ledPin, OUTPUT); - Pin 13 is the output.

Inside void loop:
LDRvalue = analogRead(LDR); - reads the value from the sensor and writes an integer variable, light.
if(LDRvalue > 600)
digitalWrite(ledPin, HIGH); - If LDRvalue > 600, the Pin 13 will light up.
else
digitalWrite(ledPin, LOW); - If LDRvalue < 600, the Pin 13 will turn off/not light up.


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


Lesson 9: LED AS ANALOG INPUT, pg 38

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

For LDR as an analog input, I used the lesson package to help me as the Youtube video shows a different set up from what we want. When I finish replicating the Arduino UNO board shown in the slides and connected the USB port to my laptop, I use my hand to cover the LDR but it did not work. After checking through my Arduino UNO board with the picture shown in the slides, I still could not find the mistake. It was until I asked my friend Joel to help me check my Arduino UNO board and quickly after 2 minute of checking, he realized the my resistor was placed in the negative side of the UNO board instead of the positive. This silly mistake costed my 15 minutes and I am appreciative of my friends helping me when I am in need.

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/program in writable format

Explanation of the code

int animationSpeed = 0;
void setup() {
pinMode (9, OUTPUT);
pinMode (6, OUTPUT);
pinMode (3, OUTPUT);
}

void loop() {
animationSpeed = 400;
digitalWrite(9, HIGH);
delay (animationSpeed);
digitalWrite(9, LOW);
delay (animationSpeed);
digitalWrite(6, HIGH);
delay (animationSpeed);
digitalWrite(6, LOW);
delay (animationSpeed);
digitalWrite(3, HIGH);
delay (animationSpeed);
digitalWrite(3, LOW);
delay (animationSpeed);
}

 


Before void setup:
int animationSpeed = 0; - animationSpeed as an integer variable

Inside void setup:
pinMode(9, OUTPUT); - Pin 9 is the output
pinMode(6 OUTPUT); - Pin 6 is the output
pinMode(3, OUTPUT); - Pin 3 is the output

Inside void loop
animationSpeed = 400; - value of the variable is 400
digitalWrite(9, HIGH); - Turns on LED
delay (animationSpeed); - 400ms of delay before next action.
digitalWrite(9, LOW); - Turns off LED
digitalWrite(6, HIGH); - Turns on LED
digitalWrite(6, LOW); - Turns off LED
digitalWrite(3 HIGH); - Turns on LED
digitalWrite(3, LOW); - Turns off 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.

For this activity, I referred to the Youtube video shown above and tried to replicate the Arduino UNO board shown in the video. As I have more practice on Arduino programming from the first and second activities, I ensure that I followed closely on the resistor placement and did not find any issues with this activity as the video clearly explains the steps. 

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/program in writable format

Explanation of the code

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

}

}

 


Before void setup:
const int greenLedVehicle = 5; - the green light for the vehicle is connected to Pin 5.
const int yellowLedVehicle = 6; - the yellow light for the vehicle is connected to Pin 6.
const int redLedVehicle = 7; - the red light for the vehicle is connected to Pin 7.
const int greenLedPedestrian = 3; - the green light for the pedestrian is connected to Pin 3.
const int redLedPedestrian = 4; - the green light for the pedestrian is connected to Pin 4.
const int pushButton = 2; - the pushbutton is connected to Pin 2.

Inside void setup:
pinMode(greenLedVehicle, OUTPUT); - Pin 5 is the output.
pinMode(yellowLedVehicle, OUTPUT); - Pin 6 is the output.
pinMode(redLedVehicle, OUTPUT); - Pin 7 is the output.
pinMode(greenLedPedestrian, OUTPUT); - Pin 3 is the output.
pinMode(redLedPedestrian, OUTPUT); - Pin 4 is the output.
digitalWrite(greenLedVehicle, HIGH); - green vehicle LED to be set high at the initial state.
digitalWrite(redLedPedestrian, HIGH); - red Pedestrian LED to be set high at the initial state.

Inside void loop:
digitalWrite(); - commands the LED to be on or off, HIGH for on and LOW for off.
delay (); - the amount of time delay in ms after previous command.


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.

For this activity, I used the slides provided in the Brightspace and managed to finish it in around 5 minutes. Therefore, I did not encounter any problems for this activity.

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 still can remember that when we first had the Arduino Lesson, it was a makeup lesson as the previous Monday was a public holiday. Therefore, we had to stay back on a Thursday afternoon to make up for the lesson. When I entered the class, our lecturer Mr Chua asked us to sit in our groups and passed us 2 Arduino Uno Kits. When I opened the Kit, I had completely no idea what each items is and for. Mr Chua then took some time to explain to use some items in the kit and its purpose. As we are in a Chemical Engineering course, I had no idea why are we learning this and felt like this will be a waste of time. However, I told myself not to be so pessimistic and thus, I carried on listening to Mr Chua's lecture about Arduino. 

During that lesson, we were also given some activities to complete and there is a guide on brightspace for us. When I opened the Arduino software, I realized that we had to code to program the system. This made me excited as I had never code before and I saw some Youtube videos about coding and wanted to try them out. This is the time... After following the guides, me and my partner managed to finish the first activity. However, we did not know that we are able to copy and paste the codes given on Brightspace to the Arduino software. Instead we typed them line by line and hope we make no mistake as a single mistake could mess the whole thing up and the code will not work. For the second activity, we tried copy pasting and it worked so we realized that we wasted a long time for the first activity. 

However, I did not understand the codes that we used as we were just copy pasting them and since the code is relatively long, I thought that understanding them would take a long time so I did not try and understand the codes we used. After some lessons about Arduino Programming, I realized that the codes used in the program are long because they are repetitive. For example, I used several pinMode(), digitalWrite() and delay () for the last activity in this blog so that is why it looked like the code is very long. In fact, it is relatively short and easy to understand as they all mean the same thing. 

In conclusion, Arduino Programming is a very fun activity and I am glad that Mr Chua introduced it to us as I managed to learn the basic codes and its meaning behind it. In addition, after placing all the LED, wires and resistors etcs on the Arduino UNO board and start the program, it is very satisfying to see it work as my hardwork had paid off. When I make a mistake, I will try to find it and ensure that I would not repeat again. 

That is it for my 3rd blog!! Thanks for reading and have a great day ahead!👋👋👋

Comments

Popular posts from this blog

Blog 4 Design of Experiment (DOE)

Blog 5 (Hypothesis Testing)

Blog 6 (Project Development)