Arduino Uno Programming
- shaira214
- Oct 29, 2022
- 3 min read
Updated: Nov 26, 2022
Arduino Documentation Blog Entry
There are 4 tasks that will be explained in this page:
Input devices:
Interface a potentiometer analog input to maker UNO board and measure/show its signal in serial monitor Arduino IDE.
Interface a LDR to maker UNO board and measure/show its signal in serial monitor Arduino IDE
Output devices:
Interface 3 LEDs (Red, Yellow, Green) to maker UNO board and program it to perform something (fade or flash etc)
Include the pushbutton on the MakerUno board to start/stop part 2.a. above
For each of the tasks, I will describe:
The program/code that I have used and explanation of the code. The code is in writable format (not an image).
The sources/references that I used to write the code/program.
The problems I encountered and how I fixed them.
The evidence that the code/program worked in the form of video of the executed program/code.
Finally, I will describe:
My Learning reflection on the overall Arduino programming activities.
Input devices: Interface a potentiometer analog input to maker UNO board and measure/show its signal in serial monitor Arduino IDE.
Code/program I have used and the explanation of the code.
Code/program in writeable format | Explanation of the 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); // helpful single-line comment here digitalWrite(LED_BUILTIN, HIGH); // pause the program for <sensorValue> milleseconds delay(sensorValue); // Wait for sensorValue millisecond(s) // turn the LED off digitalWrite(LED_BUILTIN, LOW); // pause the program for <sensorValue> milleseconds delay(sensorValue); // Wait for sensorValue millisecond(s) } |
|
hyperlink to the sources/references that I used to write the code/program.
problems I have encountered and how I fixed them
Initially, the LED light bulb was not turning on, even though I rechecked the wires and connections multiple times. I then recalled that LED has a positive and negative side, and it could be a reversed-biased circuit. Hence, I swapped the direction of the LED and the LED lit up!
short video as the evidence that the code/program work.
Input devices: Interface a LDR to maker UNO board and measure/show its signal in serial monitor Arduino IDE:
Code/program I have used and the explanation of the code.
Code/program in writeable format | Explanation of the code |
//set pin numbers //const won't change const int ledPin = 13; //the number of the LED pin const int ldrPin = A0; //the number of the LDR pin void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); //initialize the LED pin as an output pinMode(ldrPin, INPUT); //initialize the LDR pin as an input } void loop() { int ldrStatus = analogRead(ldrPin); //read the status of the LDR value //check if the LDR status is <= 300 //if it is, the LED is HIGH if (ldrStatus <=300) { digitalWrite(ledPin, HIGH); //turn LED on Serial.println("LDR is DARK, LED is ON"); } else { digitalWrite(ledPin, LOW); //turn LED off Serial.println("---------------"); } } |
|
Below are the hyperlink to the sources/references that I used to write the code/program.
Below are the problems I have encountered and how I fixed them.
After running the code, I realised that the LED light was not lighting up. I then saw that at the bottom corner of the Arduino UNO page, "no board selected" was shown.
I explored Arduino more, and I found out that I needed to select a board for our code to run. I clicked on "select board", clicked on "Arduino UNO" as that was the board I was using. Lastly, I clicked on the port I was using. After running the code again, the LED lit up!
Below is the short video as the evidence that the code/program work.
Output devices: Interface 3 LEDs (Red, Yellow, Green) to maker UNO board and program it to perform something (fade or flash etc.)
Below are the code/program I have used and the explanation of the code.
Code/program in writeable format | Explanation of the code |
// C++ code // int animationSpeed = 0;
void setup() { pinMode(LED_BUILTIN, OUTPUT); pinMode(12, OUTPUT); pinMode(11, OUTPUT); }
void loop() { animationSpeed = 400; digitalWrite(LED_BUILTIN, HIGH); delay(animationSpeed); // Wait for animationSpeed millisecond(s) digitalWrite(LED_BUILTIN, LOW); delay(animationSpeed); // Wait for animationSpeed millisecond(s) digitalWrite(12, HIGH); delay(animationSpeed); // Wait for animationSpeed millisecond(s) digitalWrite(12, LOW); delay(animationSpeed); // Wait for animationSpeed millisecond(s) digitalWrite(11, HIGH); delay(animationSpeed); // Wait for animationSpeed millisecond(s) digitalWrite(11, LOW); } |
|
Below are the hyperlink to the sources/references that I used to write the code/program.
Below are the problems I have encountered and how I fixed them.
After I uploaded the code, I realized that the red and yellow LEDS were blinking, except the green. I checked through the code and replaced the green LED several times, but the outcome was still the same.
I realized that the green LED was significantly dimmer than the rest, and it may be due to the resistance being higher for the green LED, causing brightness to be lower.
Below is the short video as the evidence that the code/program work.
Output devices: Include pushbutton to start/stop the previous task
Below are the code/program I have used and the explanation of the code.
Code/program in writeable format | Explanation of the code |
// C++ code // int animationSpeed = 0;
int buttoninput = 0;
void setup() { pinMode(2, INPUT); pinMode(13, OUTPUT); pinMode(LED_BUILTIN, OUTPUT); pinMode(12, OUTPUT); pinMode(11, OUTPUT); }
void loop() { buttoninput = digitalRead(2); if (buttoninput == HIGH) { digitalWrite(13, HIGH); } else { digitalWrite(13, LOW); } animationSpeed = 400; digitalWrite(LED_BUILTIN, HIGH); delay(animationSpeed); // Wait for animationSpeed millisecond(s) digitalWrite(LED_BUILTIN, LOW); delay(animationSpeed); // Wait for animationSpeed millisecond(s) digitalWrite(12, HIGH); delay(animationSpeed); // Wait for animationSpeed millisecond(s) digitalWrite(12, LOW); delay(animationSpeed); // Wait for animationSpeed millisecond(s) digitalWrite(11, HIGH); delay(animationSpeed); // Wait for animationSpeed millisecond(s) digitalWrite(11, LOW); } |
|
Below are the hyperlink to the sources/references that I used to write the code/program.
Below are the problems I have encountered and how I fixed them.
Below is the short video as the evidence that the code/program work.
Below is my Learning Reflection on the overall Arduino Programming activities.
I didn't expect myself to be learning more about Arduino, especially in Chemical Engineering. But, it is an important skill to have.
My group had 4 members, but we were only given 2 uno kits, causing us to split into 2 groups and work on the activities. The YouTube videos and tutorials provided allowed me to properly understand how to operate Arduino.
I felt that is was relatively easy plugging in the wires, resistors and LED into the breadboard. Tinker cad was also pretty straightforward as I was able to understand how to decipher the code so that it can run, and that our set-up would work.
Although there were some complications, I was able to run the codes myself successfully.
Comments