Arduino Programming

 ARDUINO PROGRAMMING

For this entry, I will be sharing my experiences with interfacing different components in Arduino using TinkerCad.

INPUT DEVICES:

Potentiometer Analog Input:

To help me set up my circuit, I used the Starter setups provided by TinkerCad. Under the drop-down menu on the right-hand side, select Arduino and for this scenario, select Analog Input. The Arduino Analog Digital Converter (ADC) will convert the signal of 0-5V to 0-1023ms. analogRead(A0) reads the value at Pin A0 and gives it a sensorValue. Based on the value, a delay of 0-1023ms and that determines how fast the LED flashes.


Figure 1: Potentiometer code simulation


Light Dependent Resistor:

Now, I will interface a Light Dependent Resistor (LDR) onto the UNO board and measure its signal. To aid me, I used this video to help me set up the circuit.

Figure 2: Video on LDR

After following the video, this is the circuit I created. The code works similar to the potentiometer where it reads the signal from pin A0. As more light is shone on the resistor, the resistance decreases, which allows the LED to light up brighter.

Figure 3: LDR Circuit


OUTPUT DEVICES:

3 LED to UNO (Fade):

Now I will be interfacing output devices in TinkerCad. I will interface 3 LEDs onto the UNO board and make it fade one by one. To help me set up the fade circuit, I used the help of the video below.

Figure 4: Tutorial on Fade

After following the video, I managed to create the fade effect for 1 LED. Since we were tasked to interface 3 LEDs, I duplicated the circuit and added 2 more LEDs beside the first. For the code, under void setup, I added 2 more pinModes. While for the void loop section, I just duplicated the code for the first fade and changed the respective pin.


Figure 5: Section of code duplicated

Figure 6: Video of LED Fade


DC Motor:

For this task, we were tasked to start/stop a DC Motor using the push button. To guide me along, I used the Arduino website for a button toggle. However, the example provided on the website is for LED, thus I had to replace the LED for the DC Motor. Button Toggle LED

Firstly, select the given "breadboard" under the Arduino section. Then connect a pushbutton to pin7 as shown. 


Next, connect the DC Motor to pin9 to the positive terminal and the negative terminal to a resistor that is connected to the ground.


Figure 7: DC Motor simulation


When button is pressed, currentButtonState = HIGH, when button is not pressed, currentButtonState = LOW. When it fulfills the condition of lastButtonState == HIGH & currentButtonState == LOW. motorstate = !motorstate, which means that it will inverse the motorstate. This allows the DC Motor to be able to turn on and off.



Reflection:

From this activity, I learned how to interface both input and output devices. Input devices receive a signal from Arduino and sends the signal for the output device to react accordingly. For example, the potentiometer, based on how much voltage it receives, it sends a signal to the output device, etc. how long the delay should be, and thus we can manipulate how fast the LED blinks. As I had no prior knowledge of coding, without video resources, it can be quite difficult for me to properly set up the circuit and code. I feel that with time and lots of practice, I will be more proficient in coding and be able to do the circuits much for efficiently and without having to copy from a video.

 Arduino is definitely not easy for me and I always forget where and when punctuations are needed. Although punctuations seem very minor, without it, the whole code cannot work and it makes me very frustrated and I don't know why the code is wrong.

Overall, from this activity, it has definitely deepened my knowledge on Arduino and I am able to code much better than when I just started. Despite I am still very inexperienced in Arduino, I feel that it can greatly benefit me in the future for various relevant projects 









Comments