Sunday, November 21, 2021

Arduino programming task

Week 5 Blog - Arduino Programming

For this week, after learning about the Arduino board and some components that can be used with Arduino board, we were tasked with 4 tasks.
  • Interface a Potentiometer Analog Input to maker UNO board and measure its signal in serial monitor Arduino IDE.
  • Interface a LDR to maker UNO board and measure its signal in serial monitor Arduino IDE.
  • Interface 3 LEDs (Red, Yellow, Green) to maker UNO board and program it to perform something (fade or flash etc)
  • Interface the DC motor to maker UNO board and program it to on and off using push button on the board
First, I will start off with using tinkercad to form the codes and the board. Here is also my link to  my tinkercad profile where you can check out all my boards. Click on codes to check out my codes too!


Potentiometer Analog Input

With the reference of the video provided on Potentiometer analog input, I was able to design the board and find the code needed to measure its signal.



After replicating the board physically, the LED started blinking. By turning potentiometer, the frequency of LED will change. As I turn the potentiometer clockwise, the frequency of blinks decreases while the frequency of blinks increases when turn anti-clockwise. This is because potentiometer increases the resistance when turn clockwise. At a higher resistance, the sensorValue will increase so the LED will blink less frequently and vice versa.
In order to measure its signal in the serial monitor, I added Serial.begin(9600); under voidsetup and Serial.println(sensorValue); under voidloop so that the serial monitor will monitor the sensor value which is the potentiometer. Whenever I turn the potentiometer, the serial number will change.

A: At lowest point (Left side of the meter)
B: Turning to the middle point 
C: Turing to the end point (Right side of the meter)


LDR

For the LDR, I know that the LDR has to be in series with the LED so that the LED will be affected by the LDR. So this is how it looks like in tinkercad.

I also wanted the LED to be blink constantly and make it so that the LDR will affect the brightness of the LED when there is a change in light intensity. From my past knowledge, I knew that as the light intensity increase, the resistance of the LDR will decrease and vice versa so the LED will shine the brightest in a bright room and dimmest in a dark room. The code for the blink LED will be the same as activity 1. After replicating it with an actual board, my hypothesis is right. Here is a picture of the LED in a dark room:

And here is one in a well-lit room:


Despite no having a wonderful camera, there is still a distinct difference between the two, with the one that is in the well-lit room bring brighter than the other.


3 LEDs

From what I learnt in the first activity, I was able to connect the 3 LEDs (Red, Green, Yellow) to L13, L11, L9 respectively in the board in tinkercad. I also have to code it so that all the 3 LED will blink in sequence in a loop. This can be done so by duplicating one LED blinking code 3 times and change the L(value). Here is the my tinkercad. The delay is 1 second and can be change by changing the value in delay().


And this is how it looks like with an actual board.



DC Motor

This activity was the most difficult for me by far. The whole time I was only able to make the DC move whenever I hold the button but I decided to challenge myself by using the button as a on/off switch. First, I Google on how to do this but I realized that most of the tutorials needed extra components that I do not have. Instead of that, I went to search up on a toggle system by using the button because I was confident in connecting the pin to the DC Motor. After a while I finally found this video.


I also found out that transistor (MPS2222A) is needed to amplify the current so that the DC motor will be able to spin. The transistor contains 3 pins:


  • Collector - This goes to ground
  • Base - This goes to PIN13
  • Emitter - This goes to the one end of the motor




A resistor is also needed between the transistor and Pin13 so that the Arduino board will not burn out. This is because too much current will pass through the board which can spoil it. The tinkercad is also different from the ones we have because we have a built-in button in the board.

And this is how it looks like in real life:

This is by far the most challenging out of all 4 of them but I had a lot of fun with experimenting with it. I also learn many things from these 4 activities like interfacing different types of inlet and outlet into the board and the codes for them to work.

Reflection:
I found this Arduino programming task a good exercise to strengthen the foundation we built from the past 4 programming tasks. Even though the resources given to us to do these tasks were not given, I was able to use the knowledge and available resources to do all these 4 tasks. I also learnt from this activity that there are a lot of resources online from YouTube or Google or Tinkercad that can help me with my tasks. There are others who have a better understanding of Arduino who can help me. This was my first time using the breadboard so it was quite a pleasant experience. 
After this activity, I feel that I am one step closer to my goal of being competent with Arduino programming and I will definitely use this knowledge for my capstone project. 

No comments:

Post a Comment