Arduino Programming

 Hello.

Today I will be sharing about my experience learning more about the arduino uno board.  

HOW I PROGRAMMED THE BOARD FOR OUTPUT CONNECTIONS

I learned how to program the board using the tinkercad. Tinkercad makes it so much easier to code as it generates the code from the actions that we were to piece together.

We were tasked to connect a potentiometer to the board and measure its signal in the serial monitor in arduino IDE

I pieced together how I want the components to be connected in the space provided

Then I pieced together the actions that I wanted my product to do using the different "action bubbles"


From there, this will translate into a code which is compatible and can be used in the arduino IDE app.

To verify that this is true, I transferred the code the actual maker uno board. With the serial monitor display in arduino uno IDE opened.


the code is as follows:

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

void setup()
{
  pinMode(A0, INPUT);
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);

}

void loop()
{
  // read the value from the sensor
  sensorValue = analogRead(A0);
  // turn 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)
  // read the input on analog pin 0:
  sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.print("sensor:");
  Serial.println(sensorValue);
}

The end result should be something like this:


Next, we were tasked to connect a light dependent resistor to the maker uno board. I basically replaced the potentiometer with the LDR and used the same code.


I simulated the whole code using the real maker uno board.






Next, we were tasked to learn how to use output connections. 

First we had to connect 3 LED lights to make a traffic light. I arranged how I wanted all my components to look like :


I wanted my LED lights to blink alternately with a delay of 1 second. First, I pieced the action bubbles together, and from there it helped me translate it into a code. 


The code that came up is:

// C++ code
//
void setup()
{
  pinMode(13, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(6, OUTPUT);
}

void loop()
{
  // turn led at pin 13 on
  digitalWrite(13, HIGH);
  delay(1000); // Wait for 1000 millisecond(s)
  // turn led at pin 13 off
  digitalWrite(13, LOW);
  delay(1000); // Wait for 1000 millisecond(s)
  // turn led at pin 9 on
  digitalWrite(9, HIGH);
  delay(1000); // Wait for 1000 millisecond(s)
  // turn led at pin 9 off
  digitalWrite(9, LOW);
  delay(1000); // Wait for 1000 millisecond(s)
  // turn led at pin 6 on
  digitalWrite(6, HIGH);
  delay(1000); // Wait for 1000 millisecond(s)
  // turn led at pin 6 off
  digitalWrite(6, LOW);
  delay(1000); // Wait for 1000 millisecond(s)
}

I then tried it on the maker uno board:



We can simulate this in:


Next, I had to connect a DC motor to the board and program it such that it turns on/off with a push button. I arranged my components in order of how I want it to be:

I then pieced the action bubbles together and got the code 


The code is then generated :

// C++ code

//

int sensorValue = 0;

 

int brightness = 0;

 

int ButtonState = 0;

 

void setup()

{

  pinMode(2, INPUT);

  pinMode(9, OUTPUT);

}

 

void loop()

{

  // read the state of the pushbutton

  ButtonState = digitalRead(2);

  // check if pushbutton is pressed, if it is, HIGH

  if (ButtonState == HIGH) {

    digitalWrite(9, HIGH);

  } else {

    digitalWrite(9, LOW);

  }

  delay(10); // Delay a little bit to improve simulation performance

}

overall it will look like this !



PROBLEMS??

The only problem I had with tinkercad was having to program it such that the serial monitor can display values when the button is pushed/ the LDR is covered. When I was doing it on my own, I couldn't get the serial monitor to pop up and display any values, however I sought for help from my friends eventually got it to work


REFLECTION LOL
Throughout this experience of coding in general, it was never easy as the language that is used is very alien and complicated, but with the help of examples and ready-to-use codes, it was made easier and we just had to manipulate them so that we can solve our problems.  Nevertheless, I learn perseverance as, if we wanted our codes to work we must find what's wrong with the code until we get it right. And finding whats wrong with the code is harder than doing up the code itself. :D 

Comments