This week I will be showing how to input and output devices using an online website called tinkercad. This website acts as a simulation to the arduino board given to us. It allows me to develop and test a code to see what will happen to the arduino board virtually so that I can finalise the code and execute it onto the actual arduino board once instead of repeatedly trying to input it as it waste more time waiting for the arduino board to receive the information I have coded in. Here is the task that I am assigned with.
The blank page below is what you will see after creating a new circuit.
Input devices
Firstly, I have to interface a potentiometer analog input and thereafter, measure its signal. We can start by dragging our “Arduino Uno R3” to our workspace.
Secondly, find the potentiometer and drag it to the workspace. After which, connect the potentiometer to the arduino board using wires. You can see that there are three connection points on the potentiometer. Connect the left point to 5V, the middle point to A0 and the right point to GND.
As you can see, it is rather difficult to identify which wire connects to which points of the arduino board. As such, I decided to change the colour of each wire.
Next, we can start with the programming of the input device by clicking on “Code” and “ Create variable”. Type in “SensorValue” and click ok.
After that, discard whatever is on the right side and drag the “Set SensorValue to 0” to the right.
Replace 0 with “Read analog pin A0” which can be found from the input tab. From the output tab, add “Print to serial monitor hello world with newline” below the variable row. Then replace “Hello world” with “SensorValue” from the variable tab.
Lastly, open serial monitor and click start simulation. Potentiometer is a variable resistor or voltage dividers where they can be used to change the current in the circuit or decrease the output voltage to some fraction of the input voltage. The video below shows how the voltage shown on the serial monitor decreases as I adjust the potentiometer in the clockwise direction and increases when I adjust it in the anti-clockwise direction.
For the next task, I have to interface the light dependent resistor (LDR) and then measure its signal. This is similar to the task above. Again, we drag the “Arduino Uno R3” to our workspace. However, for this task, we also need a breadboard, photoresistor (LDR) and resistor.
I know you must be wondering what the breadboard does. It is definitely not for eating :) Let me explain briefly how the breadboard is used. From the picture below, you can see that there are 2 rows at both sides of the breadboard with one row being the positive pole and the other the negative pole. Those are known as power rails to give power to your circuit.
The other majority of the holes are known as terminal strips where we can add our components to our circuit.
Now, we can assemble everything together.
You can choose to change the colour of the wires if you find it very difficult to see which wire connects to which point.
Now that the circuit is complete, we can simulate the program. You can use the code from the activity above and paste it in the code tab.
Now we can start the simulation. You will notice from the video that as I increase the brightness, the larger the voltage generated and as I decrease the brightness, the lower the voltage generated.
Output devices
So now I will show how I interface the 3 LEDs (red, yellow and green) and to allow the lights to fade and flash. Here are the components that we need. Drag the arduino uno R3, breadboard, 3 resistors and 3 LEDs (red, yellow, green) into the workspace and connect them together.
So how to connect the wires from the component to the arduino board? Let me show you how. There must be a wire connecting from the cathode of each of the 3 LEDs to the negative pole of the breadboard and another wire from the negative pole to Gnd on the arduino board. This is to connect the 3 LEDs together. Next, the anode of each of the 3 LEDs must be connected to the digital pin of the arduino board in order to complete the circuit.
Next, we are going to make a code to light up the 3 LED lights like a traffic light. Change blocks to text. First, I will identify the different colour LED lights to the different number pins I have connected to using “const int”.
Next, I will edit the void setup consisting of 3 pinMode since I have 3 LEDs I want to light up. I can just type in the different pin numbers since I have already identify them above the void setup.
Lastly, I will edit how long I want each LED to light up and the time interval to light up from one LED to another under void loop.
And there you go! We can run the simulation.
For the last task, I have to interface the DC motor and to turn it on and off using a push button. Add the arduino uno R3, 1 resistor, 1 breadboard, 1 push button and 1 DC motor to the workspace and connect everything together.
Now I will create the code for the operation of the DC motor. Firstly, I will let the arduino board identify the pin number of the button and the motor.
Secondly, I will type button and motor in void setup.
Lastly, I will set up the button such that when someone presses the button, the motor will on and if the button is not pressed, the motor does not work.
After creating the code, we can start the simulation.
Links to code
https://docs.google.com/document/d/1wPemcpz3y67xhapXSwRAOUi2UeoVW2Ce48sYsF5sqZo/edit?usp=sharing
Reflection
In general, I feel this arduino practical and the task required to complete were tough for me. Personally, I am not a tech savvy person and is not interested in coding at all, so this practical and tutorial was a tough and less fun one for me. It started with understanding the different uses of components in the arduino kit which was rather manageable to me still. However, I started to struggle a lot when I had to learn the meaning and apply the different codes and how to structure my codes properly in arduino IDE. Completing the 4 tasks in the tutorial session was a confusing journey for me and it took me many days or even weeks to understand what I am doing. However, I manage to cope with it thanks to my helpful friends and the number of question marks in my head decreases. In the practical session, me and my teammates also faced some minor problems such as having to cope with one servo to flap both wings of the unicorn. Nevertheless, we still manage to overcome the issue and meet the practical requirement.
I think this topic is important because it allows us to control the performance of the chemical product to whatever we desire. It also allows us to edit whatever errors in the coding and to make improvements so that the chemical product can be more useful to human society and the environment. I feel what made this task interesting is that it is something I have never tried in my life before. As a person who feels that coding is something troublesome and boring, arduino made me open my mind a little and see that I could do something fun with it like making music which I enjoy. This project is useful for CP5070 because it allows me to design and program my own chemical product. It allows me to trial many codes so that I have the perfect final code to allow my product to perform a desired action. It also helps with the capstone project next year where I can use arduino for my simulation and to visualize how I want my product to perform better.
I used to think that arduino is a very dry topic and is not very useful in chemical engineering. Now I can see why arduino is crucial to programming the final chemical product and how I can apply it for upcoming projects. So next I will continue to explore arduino and watch more videos which can help me better in my understanding of the topic so that I can design my own chemical product in future.
No comments:
Post a Comment