CP5070-2022-2B05-Group 3-Asraf-Blog 4 (Arduino Programming)

 





Hiii, welcome back to my new blog, ARDUINO PROGRAMMING, in which I'll explain the 4 exercise and the practical we did during our lesson. 


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

int sensorValue = 0;

void setup()

{

  pinMode(A0, INPUT);

  pinMode(12, OUTPUT);

}

void loop()

{

  // read the value from the sensor

  sensorValue = analogRead(A0);

   // turn the LED on

  digitalWrite(12, HIGH);

  // pause the program for <sensorValue> millseconds

  delay(sensorValue); // Wait for sensorValue millisecond(s)

  // turn the LED off

  digitalWrite(12, LOW);

  // pause the program for <sensorValue> millseconds

  delay(sensorValue); // Wait for sensorValue millisecond(s)

}

Pins are configured to be outputs than inputs by using the pinMode() function


Using digitalWrite() to set the pins HIGH and LOW, on and off, and pausing in between for a number of milliseconds


By adjusting using the potentiometer, it will increase or decrease the speed of the LED blinking. As shown in the video 


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

 The 1st problem I have faced is trying to figure out how to install the potentiometer, I followed the steps accordingly and still get it wrong. Took me 3 attempt to do it correctly. The problem is that I didn't bend the wire enough that were at the bottom of the potentiometer which in a result didn't have a proper connection

The 2nd problem I have faced is trying to do the code itself, I myself not really good with coding so I'm learning as times goes by and each day I'm getting better at it. Is always the small error where I miss out to put a colon or slash sign in the code. I solve it by re-redoing the code and seeing it closely to ensure everything is there. 

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

  // set variables

int sensorValue = 0;

void setup()

{

  // pin for ldr

  pinMode(A0, INPUT);

  // pin for LED

  pinMode(13, OUTPUT);

  // starts the serial monitor

  Serial.begin(9600);

}

void loop()

{

  //54-974

  // read the value from the sensor

  sensorValue = analogRead(A0);

  // print the sensor reading so you know its range

  Serial.println(sensorValue);

  // map the sensor reading to a range for the LED

  int fade = map(sensorValue, 54, 974, 255, 0);

  Serial.println(fade);

  //

  analogWrite(13, fade);

  delay(100); // Wait for 100 millisecond(s)

}

Lorem Pins are configured to be outputs than inputs by using the pinMode() function


Using digitalWrite() to set the pins HIGH and LOW, on and off, and pausing in between for a number of milliseconds


If the Light Dependent Resistor (LDR) sense light it will send a signal to the maker uno board which is then send a signal to the LED to light up. Vice-versa for when it doesn't sense light.

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

YouTube Tutorial: https://www.youtube.com/watch?v=XjKYYLK8D1Y

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

 There isn't much problem that I occur doing this part of the process. I understand the mistake I did during the first exercise and I learn from my mistakes. I guess the only problem is cable management. The wiring and diode is everywhere and is unpleasant to look at it. 

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

int animationSpeed = 0;

void setup()

{

  pinMode(13, OUTPUT);

  pinMode(12, OUTPUT);

  pinMode(11, OUTPUT);

}

void loop()

{

  animationSpeed = 400;

  digitalWrite(13, HIGH);

  delay(animationSpeed); // Wait for animationSpeed millisecond(s)

  digitalWrite(13, LOW);

  delay(animationSpeed); // Wait for animationSpeed millisecond(s)

  digitalWrite(12, HIGH);

  delay(animationSpeed); // Wait for animationSpeed millisecond(s)

  digitalWrite(12, LOW);

  delay(animationSpeed); // Wait for animationSpeed millisecond(s)

  digitalWrite(11, HIGH);

  delay(animationSpeed); // Wait for animationSpeed millisecond(s)

  digitalWrite(11, LOW);

  delay(animationSpeed); // Wait for animationSpeed millisecond(s)

}

Pins are configured to be outputs than inputs by using the pinMode() function

 

Using digitalWrite() to set the pins HIGH and LOW, on and off, and pausing in between for a number of milliseconds

 

Using animationSpeed to change that number once at the start of the program. Changing the variable will control the pauses and thus the overall speed of the animation.

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

YouTube Tutorial: https://www.youtube.com/watch?v=MojSo7OtF9w

AutoDesk Instructable: https://www.instructables.com/Multiple-LEDs-Breadboards-With-Arduino-in-Tinkerca/

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

 There little to no problem here as the more exercise I did, the more I get used to the Arduino. At this exercise I manage it do the code and set up very quickly. Yet again the only problem is the cable management. 

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

int animationSpeed = 0;

void setup() {

  //start serial connection

  Serial.begin(9600);

  //configure pin 2 as an input and enable the internal pull-up resistor

  pinMode(2, INPUT_PULLUP);

  pinMode(13, OUTPUT); pinMode(12, OUTPUT); pinMode(11, OUTPUT);

}

void loop() {

  //read the pushbutton value into a variable

  int sensorVal = digitalRead(2);

  //print out the value of the pushbutton

  Serial.println(sensorVal);

  // Keep in mind the pull-up means the pushbutton's logic is inverted. It goes

  // HIGH when it's open, and LOW when it's pressed. Turn on pin 13 when the

  // button's pressed, and off when it's not:

  if (sensorVal == HIGH) {

     animationSpeed = 100;

    digitalWrite(13, LOW);

    delay(animationSpeed); // Wait for animationSpeed millisecond(s)

    digitalWrite(12, LOW);

    delay(animationSpeed); // Wait for animationSpeed millisecond(s)

    digitalWrite(11, LOW);

    delay(animationSpeed); // Wait for animationSpeed millisecond(s)

  } else {

       digitalWrite(13, HIGH);

    delay(animationSpeed); // Wait for animationSpeed millisecond(s)

    digitalWrite(12, HIGH);

    delay(animationSpeed); // Wait for animationSpeed millisecond(s)

    digitalWrite(11, HIGH);

    delay(animationSpeed); // Wait for animationSpeed millisecond(s)

  }

}

Pins are configured to be outputs than inputs by using the pinMode() function

 

Using digitalWrite() to set the pins HIGH and LOW, on and off, and pausing in between for a number of milliseconds


Once the button on the marker uno will then send the signal to the marker uno which is then send to the LED. The 3 LED is lit up first once the code is send to the marker uno, once the button is press the 3 LED will be turn off.

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

https://www.youtube.com/watch?v=MojSo7OtF9w

https://www.instructables.com/Multiple-LEDs-Breadboards-With-Arduino-in-Tinkerca/

Is from the File à Example à 02.Digital à DigitalnputPullup

I add the code from the previous exercise which can be seen from the previous question or the link above into DigitalnputPullup. I did some modifications to it as well. 

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

 The hardest part of this exercise is actually finding the button. Based on the video that was on YouTube, they have a physical button that is separated from the maker uno board itself. I have to link the code to the button that was build in the maker uno. I have no clue at first on how to do it. But after like 30 minutes of trying different code and watching YouTube I finally solve it. Which took longer than I expected. 

4.    Below is the short video as the evidence that the code/program work.



Arduino Practical
In this practical our goal is to create pegasus and ensure that there is 2 activities that it is doing. So, what me and my partner did was movement of the wings and the LED light blinking at the eye. There were a lot challenges along the way such as how to make the wing flaps, how to secure everything together but  the hardest part of this practical is combining 2 code to perform simultaneously. Our lecturer suggest to use millis but it was harder than we thought. So in the end we head for a easier approach  which is delay. And it turn out better than I expected. Nonetheless, there still improvement that could be made such as the design of the pegasus, how to use millis. 

Code/program in writable format

#include <Servo.h>

 

Servo myservo;  // create servo object to control a servo

// twelve servo objects can be created on most boards

 

int pos = 0;    // variable to store the servo position

 

void setup() {

myservo.attach(9);  // attaches the servo on pin 9 to the servo object

// initialize digital pin 13 and 12 as an output.

pinMode(13, OUTPUT);

pinMode(12, OUTPUT);

}

 

void loop() {

for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees

// in steps of 1 degree

myservo.write(pos);              // tell servo to go to position in variable 'pos'

delay(2);                       // waits 15 ms for the servo to reach the position

}

for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees]

 

myservo.write(pos);              // tell servo to go to position in variable 'pos'

delay(1);                       // waits 15 ms for the servo to reach the position

}

// the loop function runs over and over again forever

digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)

delay(100);                       // wait for a second

digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW

delay(100);                       // wait for a second

digitalWrite(12, HIGH);   // turn the LED on (HIGH is the voltage level)

delay(100);                       // wait for a second

digitalWrite(12, LOW);    // turn the LED off by making the voltage LOW

delay(100);                       // wait for a second

}






My Learning reflection on the overall Arduino programming activities

Overall, I think my experience using Arduino isn't as bad as I thought it will be. There are improvement to be made for future practical if Arduino is involved. The main challenge that I want to tackle as soon as possible is cable management, it may not be a big thing about it now but it shows a lot about the way you work. The messier the cable management are, it meant that your work is sloppy. Having a good cable management shows that your a well-organized person. 
Yes, there are many challenge I face throughout the whole process but nonetheless I make it out alive. I won't say I'm the best person to do Arduino programming in my class but as time move on my skills will be better than the past. 


That's all for my blog, Stay tune to the next one. 
Signing Out

Comments

Popular posts from this blog

CP5070-2022-2B05-Group 3-Asraf-Blog 7 (Project Development)