Arduino Programming 🤖⌨
Beep Boop Beep Boop. This entry is focused on Arduino programming on the Arduino Maker Uno and I will share with you the activities I have done. Links to all Arduino simulation are found at the bottom of this blog.
Figure 1: Activities |
Interfacing Input Devices to Arduino:
Potentiometer Analog Input
The first activity was to interface a potentiometer Analog Input to maker UNO board and measure its signal in serial monitor Arduino IDE. To do this I used TinkerCad to wire the circuit for the board with the help of the video below.
Figure 2: Potentiometer example video
Then I followed the code to program the Arduino board, as the potentiometer knob turn to the right the slower the frequency of the LED will flash. This is demonstrated in the video below with the link to the TinkerCad simulation.
Figure 3: My potentiometer analog input
Light Dependent Resistor (LDR)
This activity requires the Arduino board to be connected to a LDR and measure the signal in serial monitor Arduino IDE. For this activity I have also referred to a Youtube video.
Figure 4: LDR reference video
Following the set up and using the code in the video I was able to accomplish making the LED dim or brighten when the light on the LDR goes from dim to bright shown in the video below :)
This is similar to the potentiometer activity just that resistance of LDR depends on lighting condition whereas potentiometer depends on the knob being turned to adjust the resistance of the circuit.
Figure 5: My LDR simulation
Interfacing Output Devices to Arduino:
3 LED to UNO board (Fade)
The goal of this activity is to make 3 LEDs light up and fade or flash. To start of the activity I referred to a video demonstrating for to set up and code to fade a LED on and off.
Figure 6: 1 LED fade example
Here is a video of what I came up with from reference to the Youtube video
Figure 7: My 1 LED Fade simulation
Once I understood the code and circuitry for the set up I began setting up my own circuit and code to programme 3 LEDs to fade on and off, one after another like a traffic light. It was tedious to do the code as I kept missing out on the variables in the code to set but after a short troubleshooting session it was completed. This is the final product.
Figure 8: My 3 LEDs Fade simulation
DC Motor with Push Button
The last activity was to interface a DC motor to maker UNO board and program it to switch on and off with the push button on the board. I had no idea how to do this but after a few minutes of web browsing I came across this useful example on Tinkercad (DC Motor and button Example). After understanding how the set up worked, I then proceeded to make my own version of this set up. This is the final product.
Figure 9: My DC Motor toggle switch simulation
Something new that I had used for the code was '!'.
Example: ledState = !ledState
This code is the same as using 'if' and 'else' in the code.
Example: if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
Using '!' helped to shorted down the length of code used and made it more efficient as it performed the same function. Using this code allows the button toggling to work as the Arduino can read the position of the button and change the motor state when the button is pressed. Things to note for this code is that pin for button and pin for motor must be defined first before proceeding with the rest of the code.
Link for the website referred: Button Toggle LED code
Learning Points:
Input and Output devices for Arduino Board:
This activities showed how to code Arduino boards so that they can send data from an input device used such as a potentiometer and LDR. This would be useful as the Arduino board can be programmed to output an action if data received reaches a certain threshold. Such as an automatic door opener using an ultrasonic sensor. An ultrasonic sensor can detect a person walking towards it as and when the person gets close enough to the sensor, a trigger point for an output to a motor to open the door can be performed as the data received from the ultrasonic sensor meets a set value to open the door.
Problems
Writing the code in text function was annoying as sometimes I would accidently leave out a semicolon or bracket and the code could not run. Luckily, Tinkercad had a function where they would spot my mistake and give suggestions like a missing semicolon or bracket which made it easy to spot and correct. I also felt my inexperience using function like 'if and else' also caused me to take a much longer time to understand codes on the internet that could possible helped me to code the Arduino. Thankfully after this activity I am understand how to use this function better and made me more interested in learning more efficient codes for the Arduino.
Reflection:
The Arduino programming activity allowed me to takeaway some things. Firstly, I learnt that tinkercad can help me with the programming of Arduino board as it has a blocks function which is a more simplistic form to input my desired program in and then convert it tot text which can be copied and used on the real Arduino board. This gives me an easier method to code and made this new skill easier to understand.
Secondly, there are many Arduino resources in the internet that can cater to many use cases that I would need like for the DC motor activity where I managed to find codes and examples to help me with the set up of the circuit and coding. This makes it easier to understand coding and maybe find better alternatives or more efficient ways to an action I want the Arduino to perform.
This activity has made me more interested in learning more efficient ways to perform Arduino functions and I am excited to apply it in future projects.
Next entry will be on 3D printing, so stay tuned ;)
Link to Arduino simulations:
Comments
Post a Comment