ARDUINO PROGRAMMING

 Hello! For this week’s blog, we will be focusing on ARDUINO PROGRAMMING!🎮🖥 I had so much fun doing this lesson and this blog will be documenting the different codes we learnt. Along with the Arduino Programming, we will also be using the Maker UNO board, I will be documenting the experience with videos and photos too. Let’s begin!

This is a link to the Arduino 4 challenges documentation: https://docs.google.com/document/d/1ACngzrPfGAoOpsvWMa6rMBsNS5O0Ha_4di-aPHfa4Xw/edit 

INDIVIDUAL ASSIGNMENT

In this individual assessment, we were tasked to complete multiple tasks using the TINKERCAD software. It is basically a simulation software that allows us to build the our Arduino Uno board and run the codes. We were tasked with 4 challenges and I will be documenting them below.

  1. INPUT DEVICES
  • Interface a Potentiometer Analog Input to the Maker Uno board and measure its signal in serial monitor Arduino IDE
To start off, a potentiometer is a variable resistor with an adjustable third terminal. By adjusting the terminal, you can control the amount of potential going through at the end of the resistor. The task is to make a board where you can adjust the blinking of an LED using the potentiometer.
Below is the image of the TINKERCAD set-up:









Description of set-up:

Red Wires - Connected to ‘5V’ pin and and the anode of the breadboard, followed by connecting it to the potentiometer. Another set of red wires are connected to the two other anodes of the breadboard.

Black Wires - Connected to the ‘GND; pin and the cathode of the breadboard, followed by connecting it to the potentiometer. Another set are then connected to the two other cathodes of the breadboard.

Green Wires - Connected to ‘A0’ pin followed by connecting it to the potentiometer.

Yellow Wires - Connected to pin ‘13’ followed by the anode side of the LED beside the resistor.

Coding set-up:

Below is an image of the block code:










Description of set-up:

This is the base code in order for the LED to blink and be controlled by the potentiometer. However, this code does not include measuring its signal in the serial monitor Arduino IDE. Hence, I have modified the code to change the setting.

Original Code:


// C++ code

//

int sensorValue = 0;


void setup()

{

  pinMode(A0, INPUT);

  pinMode(LED_BUILTIN, OUTPUT);

}


void loop()

{

  // read the value from the sensor

  sensorValue = analogRead(A0);

  // turn the LED on

  digitalWrite(LED_BUILTIN, HIGH);

  // pause the program for <sensorValue> milliseconds

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

  // turn the LED off

  digitalWrite(LED_BUILTIN, LOW);

  // pause the program for <sensorValue> milliseconds

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

}

Modified (Highlighted parts):


// C++ code

//

int sensorValue = 0;


void setup()

{

  pinMode(A0, INPUT);

  pinMode(LED_BUILTIN, OUTPUT);

  Serial.begin(9600);

}


void loop()

{

  // read the value from the sensor

  sensorValue = analogRead(A0);

  Serial.println(sensorValue);

  // reading sensorValue

  // turn the LED on

  digitalWrite(LED_BUILTIN, HIGH);

  // pause the program for <sensorValue> millseconds

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

  // turn the LED off

  digitalWrite(LED_BUILTIN, LOW);

  // pause the program for <sensorValue> millseconds

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

}


Final Outcome:

Below will be a video of running a simulation of the above set-up with serial monitor:



Here is a video of using the software on the Maker Uno Board:

  • Interface a LDR to Maker Uno board and measure its signal in serial monitor Arduino IDE
LDR stands for Light Dependent Resistor (aka Photoresistor), it is a resistor that decreases its resistance in regards to the amount of luminosity/light it receives. We are tasked to control the brightness of a LED using a LDR.
Below is an image of the TINKERCAD set-up:











Description of set-up:

Red Wires - Connected to ‘5V’ pin to the cathode of the breadboard. Followed by another wire connected from the cathode of the motherboard to the LDR.

Black Wires - Connected to the ‘GND’ pin to the anode of the breadboard.

Yellow Wires - Connected from pin ‘9’ to the anode side of the LED beside the resistor.

Green Wires - Connected from ‘A0’ pin to the LDR, the same side of the LDR as the other resistor.

Coding set-up:

Below is an image of the text code in TINKERCAD:











Description of set-up:

This code fulfills the requirement of having a LDR able to control the brightness of the light and also monitor the signal value using the serial monitor.

Original Code:

int sensorValue = 0;


void setup()

{

  pinMode(A0, INPUT);

  Serial.begin(9600);

  

  pinMode(9, OUTPUT);

}

  

  void loop()

  // 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

  analogWrite(9, map(sensorValue, 0, 1023, 0, 255));

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

}  


Final Outcome:

Below will be a video of running a simulation of the above set-up:



Here is a video of using the software on the Maker Uno Board:


      2. OUTPUT DEVICES

  • Interface 3 LEDs (Red, Yellow, Green) to maker Uno and program it to perform something.
To basically explained what I did was that I program the lights to blink/flash in a certain order to create a traffic light
Below is an image of the TINKERCAD set-up:
















Description of set-up:
I set up the LEDs according to their colour so it is Red, Yellow, Green. To each LED, I added a resistor and connect each one to a pin and the cathode side of the breadboard.

Code set-up:
Below is an image of the block code:




















Original Code:

// C++ code

//

void setup()

{

  pinMode(8, OUTPUT);

  pinMode(3, OUTPUT);

  pinMode(2, OUTPUT);

}


void loop()

{

  digitalWrite(8, HIGH);

  digitalWrite(3, LOW);

  digitalWrite(2, LOW);

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

  digitalWrite(8, LOW);

  digitalWrite(3, HIGH);

  digitalWrite(2, LOW);

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

  digitalWrite(8, LOW);

  digitalWrite(3, LOW);

  digitalWrite(2, HIGH);

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

}


Final Outcome:

Below will be a video of running a simulation of the above set-up:


Link to simulation: https://www.tinkercad.com/things/9zYbUwHSv2p-funky-blorr/editel?sharecode=_2iZ_IRPw5arZTX3RfCAfk-0cbc89TZlwbM3LaF2CiY 


Here is a video of using the software on the Maker Uno Board:




  • Interface the DC motor to the maker Uno board and program it to on and off using push button on board.
Making a DC motor to move/turn when pushing a button, and when the button is not pushed, the motor will turn on.
Below is an image of the TINKERCAD set-up:














Description of set-up:
For this task, I followed a tutorial and this set-up is able to use 2 push buttons. The button on the right, when pushed, the DC motor will turn anti-clockwise. While when the button on the left is pushed, the DC motor will turn clockwise.

Coding set-up:
Original Code:
int md1Pin = 6;
int md2Pin = 7; 
int lButton = 9; 
int rButton = 8; 
int lButtonState=0;
int rButtonState=0;
void setup()
{
   pinMode(md1Pin, OUTPUT); 
   pinMode(md2Pin, OUTPUT); 
   pinMode(lButton, INPUT_PULLUP); 
   pinMode(rButton, INPUT_PULLUP);
}

void loop()
{
  lButtonState = digitalRead(lButton); 
   rButtonState = digitalRead(rButton); 
   if (rButtonState == LOW) {  
      digitalWrite(md1Pin, HIGH); 
      digitalWrite(md2Pin, LOW); 
   }
   else if (lButtonState == LOW) { 
      digitalWrite(md1Pin, LOW); 
      digitalWrite(md2Pin, HIGH); 
   }
   else { 
      digitalWrite(md1Pin, LOW); 
      digitalWrite(md2Pin, LOW); 
   } 

}

Final Outcome:
Below will be a video of running a simulation of the above set-up:

Moving on……


PRACTICAL SESSION🦄
In this session, we are tasked to make a unicorn wings flap automatically with the use of a DC motor to and Maker UNO board. 
Process:
We first assembled the unicorn. At first it looked like this…..

















And it became something like this…..

















What my team and I did was that we attached one single servo arm to the servo motor and attached two metal wires to the holes. We then attach each of the metal wire to the back of the flap of the wings. After programming the servo motor to rotate at a certain angle, we then positioned it to find the most ideal place for it have the flappiest wings. Once we confirmed our ideal position of where the servo motor should be. We attach the servo to the unicorn like the image shown below:





















And finally, we decorated our unicorn to present to your the final outcome!


REFLECTION:
At first, I found Arduino super hard especially the coding part. It was hard to learn what the different symbols mean and what sequence numbers or words must be put together to achieve the result I want. I especially struggle in identifying errors. In the tonemelody challenge, there was an error that kept on popping up whenever we check our coding. It showed us the same error message but I have no way of identifying it. In the end, I had to seek help and was able to resolve it but that made me less enthusiastic about the coding part of this lesson. However, as I do more and more of coding and messing with the Maker UNO board, I found myself engrossed in it and able to continue for hours. I spent hours doing the individual assessment, trying out different ways and modifying the codes bit by bit. Using TINKERCAD is really fun cause I can easily see my work come to life and once I accomplish it on TINKERCAD, I also can do it in real life. It takes off the stress of having errors in my codes when I can simulate and trial and error.
One major aspects to me improving in Arduino and fuelling my curiosity to learn more is the internet. When searching for codes or programmed set-ups to help me with my work and the practical, I was able to explore so many possibilities in coding and how to understand Arduino better. Many of the tutorials are simple and easy to understand, they also provide visuals which works greatly for me when using TINKERCAD. For example, when searching on how to connect a DC motor and push button on the maker UNO board, I saw so many possibilities to achieve the same results. Some of the set-ups are much simplified while others are really complicated, I enjoy the diversity in the ways of programming.
All in all, I still have a lot to improve in Arduino as I am not near as good to identifying my own errors but this really was an enjoyable activity/lesson.









Comments

Popular posts from this blog

Project Development

HOME

COMPUTER AIDED DESIGN (CAD)