top of page

Arduino documentaion blog

  • Writer: nsyirah04
    nsyirah04
  • Dec 3, 2022
  • 4 min read

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.

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

Code/program in writeable format

Explanation of the code

void setup()

{

// initialize serial communication at 9600 bits per second:

Serial.begin(9600);

pinMode(A0, INPUT);

pinMode(LED_BUILTIN, OUTPUT);

}


void loop()

{

// read the input on analog pin 0:

int sensorValue = analogRead(A0);

Serial.println(sensorValue);

digitalWrite(LED_BUILTIN, HIGH);

delay(sensorValue);

// turn the LED off

digitalWrite(LED_BUILTIN, LOW);

delay(sensorValue); }

​In void setup() : Serial.begin(9600) : passes the value 9600 to the speed parameter. This tells the Arduino to get ready to exchange messages with the Serial Monitor at a data rate of 9600 bits per second. pinMode(A0,input) pinMode(LED_BUILTIN, OUTPUT); establish A0 as the input and LED_bultin as the output In void loop(): read the input on analog pin 0, sensorValue equivalent to value from A0. Serial.println(sensorValue) : print out value you read digitalWrite (LED_BUILTIN,HIGH) : turn the LED on delay(sensorValue): wait for sensoeValue milliseconds digitalWrite(LED_BUILTIN,LOW): Turn the LED off delay(sensorValued) :Wait for sensorValue milliseconds

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

code/program

Lesson 8, POTENTIOMETER AS ANALOG INPUT - Page 34


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

During my first try, i wondered why my potentiometer wont change anything even after turning it, after looking at the breadboard carefully, i realised that i did not connect my wires properly therefore, it wsnt connected to the potentiometer. I proceed to change accordingly and managed to get it working.


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 writeable format

Explanation of the code

int ldr; void setup() { pinMode(A0,INPUT); Serial.begin(9600); } void loop() { ldr= analogRead(A0); Serial.println(ldr); delay(10); }

​In void setup() pinMode(A0, INPUT) : establishes A0 as the input In void loop(): ldr=analogRead(A0) : reads the value of A0 and writes into and integer variable, light. Serial.println(ldr) : Prints value of LDR to the serial port Delay(10): wait for 10milliseconds

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

code/program

Lesson 9, LDR AS ANALOG INPUT - Page 38



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

Interfacing LDR to maker UNO was quite easy as i follwed the instructions given in the lesson package and i did not encouter any problems


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 writeable format

Explanation of the code

/* Fade This example shows how to fade an LED on pin 9 using the analogWrite() function. The analogWrite() function uses PWM, so if you want to change the pin you're using, be sure to use another PWM capable pin. On most Arduino, the PWM pins are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11. */ int brightness = 0; void setup() { pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); } void loop() { for (brightness = 0; brightness <= 255; brightness += 5) { analogWrite(9, brightness); delay(30); // Wait for 30 millisecond(s) analogWrite(10, brightness); delay(30); // Wait for 30 millisecond(s) analogWrite(11, brightness); delay(30); // Wait for 30 millisecond(s) } for (brightness = 255; brightness >= 0; brightness -= 5) { analogWrite(9, brightness); delay(30); // Wait for 30 millisecond(s) analogWrite(10, brightness); delay(30); analogWrite(11, brightness); delay(30); } }

​int brightness = 0 : brightness is equals to zero in Void setup() pinMode(9, OUTPUT) pinMode(10, OUTPUT) pinMode (11, OUTPUT) establishes PINs 9,10,11 as output In Void loop() : for(brightness = 0; brightness <= 255; brightness += 5) : for brightness less than 255 but equals to 0, brightness will increase by 5 analogWrite(9, brightness); delay(30); analogWrite(10, brightness); delay(30); analogWrite(11, brightness); delay(30) -light LED connected to PIN 9, 10, 11 -wait for 30 milliseconds for(brightness = 0; brightness <= 255; brightness += 5): For brightness more than zero, but equals to 255, brightness will decrease by 5 . analogWrite(9, brightness); delay(30); analogWrite(10, brightness); delay(30); analogWrite(11, brightness); delay(30) -light LED connected to PIN 9, 10, 11 -wait for 30 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 during this was trying to figure out how to make it fade. My first try i did but it did not fade it just changes from red to yellow to green slowly. How i resolved this issue was that i went to youtube to search how to make the LED fade and came across a ThinkerCad website as per the link above. Even thought the instructions only showed me how to fade 1 LED , i managed to configure the code on my own and finally able to fade all 3 LEDs.


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 writeable format

Explanation of the code

#define LED_1_PIN 5 #define LED_2_PIN 4 #define LED_3_PIN 3 #define BUTTON_PIN 2 void setup() { pinMode(LED_1_PIN, OUTPUT); pinMode(LED_2_PIN, OUTPUT); pinMode(LED_3_PIN, OUTPUT); pinMode(BUTTON_PIN,INPUT_PULLUP); } void loop() { byte buttonState = digitalRead(BUTTON_PIN); if (buttonSate == LOW) { digitalWrite(LED_1_PIN, HIGH); digitalWrite(LED_2_PIN, HIGH); digitalWrite(LED_3_PIN,HIGH); } else { digitalWrite(LED_1_PIN, LOW); digitalWrite(LED_2_PIN, LOW); digitalWrite (LED_3_PIN, LOW); } }

​Make LED_1_PIN as value 5 Make LED_2_PIN as value 4 Make LED_3_PIN as value 3 Set PIN5 to be output Set Pin4 to be output Set PIN3 to be output Set PIN2 to be button input Loop this : Reading the button state, If the button is pressed, Light up PIN5 Light up PIN4 Light up PIN3 If the button is not pressed, Turn off PIN5 Turn off PIN4 Turn off PIN3

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.

At first, i had no idea how to include the pushbutton to start or stop the previous tasks, since in the package given in brightspace, they only state how to use the button but did not show how to use it to start/stop the given tasks. So, i went online and came across the link above where i followed their instructions and managed to complete it. However, i did not managed to code it in a way that it will light up one LED at time instead, all 3 LED light up at the same time.


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

This practical was definately difficult one as i really hate coding and all these tasks related to this practical for example, pre-practical and this blog was very time consuming. Even though i hate coding, i am glad that i learned something new and it was really a challenge for me as i did not understand anything at first but after completing this practical, i have now understand the basics of coding and learned that it is really amazing what coding can do. Even with just a small arduino kit, we can create alot of things. During the practical, we were tasked to create a unicorn that was able to perform 2 or more functions using the arduino. SInce had to do it in pairs, me and eshvin paired up and to make things faster, we split the tasks. I was tasked to do the coding while eshvin does the decoration of the unicorn as points were given for the aesthetics. The 2 function we chose to do was flapping of the wings using servo and blinking of LED light as the unicorn horn. After i finished the coding, i helped her with decorating it, since it is the world cup season, and we are a fan of football, we decided to colour it with out favourite teams. My favourite team is brazil while eshvin was england hence we decided to colour the left side of the unicorn with england flag while the other with brazil flag. All in all, this practical was really fun and i was happy with at our end product. You can see our end product in the video below.



Thats all for this week's blog! Hoped u enjoyed it and stay tuned for the next one byebye

Comments


Post: Blog2_Post
  • Facebook
  • Twitter
  • LinkedIn

©2022 by Insyirah's blog. Proudly created with Wix.com

bottom of page