Arduino Programming
Arduino Programming
For this topic, we learned about the Arduino Uno board and how to program it.
Arduino Uno is a microcontroller board based on the ATmega328P (datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic resonator (CSTCE16M0V53-R0), a USB connection, a power jack, an ICSP header, and a reset button.
Components of Arduino Uno Kit:
Components of the Maker-Uno Board:
Tinkercad challenge 👊
For this task we were told to complete the following tasks:
1. Input devices:
a. Interface a Potentiometer Analog Input to maker UNO board and measure its signal in serial monitor Arduino IDE.
Below is the formation of the Potentiometer Analog Input to maker UNO board on tinkercad.
The blocks at the side of the picture above are the codes for this task. Below are the codes in text:
b. Interface a LDR to maker UNO board and measure its signal in serial monitor Arduino IDE.
Below is the formation of the Potentiometer Analog Input to maker UNO board on tinkercad. As seen below, the light bulb lights up when there is light.
2. Output devices:
a. Interface 3 LEDs (Red, Yellow, Green) to maker UNO board and program it to perform something (fade or flash etc).
Below is the formation of the interface 3 LEDs (Red, Yellow, Green) to maker UNO board on tinkercad.
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(10, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
digitalWrite(9, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(9, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
digitalWrite(8, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(8, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Then, I applied the visual version made on tinkercad to the physical Arduino Uno board. Below is the video:
b. Interface the DC motor to maker UNO board and program it to on and off using push button on the board.
Below is the formation of the DC motor to maker UNO board on tinkercad.
Below are the codes in text:
void setup() {
//start serial connection
Serial.begin(9600);
//configure pin 2 as an input and enable the internal pull-up resistor
pinMode(2, INPUT_PULLUP);
pinMode(12, OUTPUT);
}
void loop() {
//read the pushbutton value into a variable
int sensorVal = digitalRead(2);
//print out the value of the pushbutton
Serial.println(sensorVal);
// Keep in mind the pull-up means the pushbutton's logic is inverted. It goes
// HIGH when it's open, and LOW when it's pressed. Turn on pin 13 when the
// button's pressed, and off when it's not:
if (sensorVal == HIGH) {
digitalWrite(12, LOW);
} else {
digitalWrite(12, HIGH);
}
Then, I applied the visual version made on tinkercad to the physical Arduino Uno board. Below is the video:
Link to the tinkercad design: https://www.tinkercad.com/things/dRNjHIXduFI-copy-of-push-button-motor-final
Reflection 📜
The Arduino programming was a very challenging task. We learned what the Arduino board is and how to operate and program it all in 1 week. This was strenuous as there was a lot of information to take in. For the practical, we had to program a servo to the Arduino board to automate the wings of a cardboard unicorn. Whilst we were completing that, we were also called one by one to get tested for the arduino programming. The practical itself was very fun but I found the test challenging. In fact, I failed the first time which was quite sad 😕 but I eventually got there after revising the codes. Then I was assigned to use tinkercad to program different kinds of tasks. This was the most difficult part. I struggled a lot and was very frustrated. It took me 2 to 3 days to complete as I was stuck most of the time. But I persevered. I went through the videos on blackboard and researched how to complete the tasks. Overall this was a very difficult but informational topic. I definitely know that Arduino programming will be beneficial for my future and fyp as I need to automate my chemical product.
Comments
Post a Comment