Arduino Programming

Arduino Programming

For this topic, we learned about the Arduino Uno board and how to program it. 

What is 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:

// C++ code
//
int sensorValue = 0;

void setup()
{
  pinMode(A0, INPUT);
  pinMode(13, OUTPUT);
}

void loop()
{
  // read the value from the sensor
  sensorValue = analogRead(A0);
  // turn the LED on
  digitalWrite(13, HIGH);
  // pause the program for <sensorValue> milliseconds
  delay(sensorValue); // Wait for sensorValue millisecond(s)
  // turn the LED off
  digitalWrite(13, LOW);
  // pause the program for <sensorValue> milliseconds
  delay(sensorValue); // Wait for sensorValue millisecond(s)
}

Then, I applied the visual version made on tinkercad to the physical Arduino Uno board. Below is the video:






Link to tinkercad design: https://www.tinkercad.com/things/0xHotacKVE1-cool-jaban-kup 

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.



Above is the screenshot of the lightbulb when there is no light.


Above is the screenshot of the lightbulb when there is light.

Below is the code I programmed for this task:

// 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);
  // turn the LED on
  digitalWrite(LED_BUILTIN, HIGH);
  // pause the program for <sensorValue> milliseconds
  delay(sensorValue); // Wait for sensorValue millisecond(s)
  // turn the LED off
  digitalWrite(LED_BUILTIN, LOW);
  // pause the program for <sensorValue> milliseconds
  delay(sensorValue); // Wait for sensorValue millisecond(s)
}

Then, I applied the visual version made on tinkercad to the physical Arduino Uno board. Below is the video:





Link to tinkercad design: https://www.tinkercad.com/things/5D5aZER9zPB-copy-of-cool-jaban-kup 

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. 




Below are the codes in text:

// 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:



Link to the tinkercad design: https://www.tinkercad.com/things/4a7Bb8GjE3G-copy-of-cool-jaban-kup

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 is a video of the stimulation:




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

Popular posts from this blog

Home