Skip to main content

Blog Entry 3 - Arduino Programming


Welcome back everybody! Today I will be sharing my experience my journey in Arduino Programming using the maker UNO kit as well as showing some of the the tasks that I have completed.



Contents

1. Input devices:

    a. Interface a potentiometer analog input to maker UNO board and measure/show its signal         in serial monitor Arduino IDE.                                                                                       b. Interface a LDR to Maker UNO board and measure/show its signal in serial                               monitor Arduino IDE

2. Output devices:

    a. Interface 3 LEDs (Red, Yellow, Green) to maker UNO board and program it to perform            something (fade or flash etc)
    b. Include the pushbutton on the Maker Uno board to start/stop part 2.a. above

3. For each of the tasks I will describe:

    a. The code that I have used and explanation of the code.
    b. The references that I used to write the code
    c. The problems I encountered and how I fixed them.
    d. The evidence that the code worked in the form of video of the executed 
        code.

4. Finally, I will be sharing my Learning reflection in Arduino Programming.

Input devices: Interfacing a potentiometer analog input to maker UNO board and measuring its signal in serial monitor Arduino IDE

1. Below is the code I have used and the explanation of the code:

Code

Explanation of code

int sensorvalue = 0;

void setup()

{

  pinMode(A0, INPUT);

  pinMode(LED_BUILTIN, OUTPUT);

  Serial.begin(9600);

}

 

void loop()

{

  sensorvalue = analogRead(A0);

  digitalWrite(LED_BUILTIN, HIGH);

  Serial.print(",");

  Serial.println(sensorvalue);

  delay(sensorvalue);

  digitalWrite(LED_BUILTIN, LOW);

  Serial.print(",");

  Serial.println(sensorvalue);

  delay(sensorvalue);

}
-Sets sensorvalue to be 0

-Sets Pin A0 as input
-Sets Pin 13 as output
-Tells the Arduino to get ready to exchange messages with the Serial Monitor



-Sets sensorvalue to be the same as the reading for pin A0

-Prints value of sensorvalue onto the serial monitor





-Sets the delay interval to be the same as sensorvalue 

2. Below is the reference I used to write the code:


3. Below are some of the problems I have encountered and how I fixed them:

The main problem I encountered for this task is getting the serial monitor to show the effects of turning the potentiometer. This is because the video I was referencing did not have the code for this and as a result I thought the problem was with the IDE rather than the code. 

Thankfully, after searching online for help, I found out that I was missing the codes necessary for the serial monitor to work. These codes are:

Serial.println(sensorvalue);

4. Below is the video that shows the code is working:




Input devices: Interfacing a LDR To maker UNO board and measuring its signal in serial monitor Arduino IDE

1. Below is the code I have used and the explanation of the code:

Code

Explanation of code

int sensorPin = A0;

int sensorValue = 0;
void setup() {

pinMode(LED_BUILTIN, OUTPUT);

Serial.begin(9600);
}

void loop() {
sensorValue = analogRead(sensorPin);

Serial.println(sensorValue);

if(sensorValue > 600)
digitalWrite(LED_BUILTIN, HIGH);
else
digitalWrite(LED_BUILTIN, LOW);


}
-select the input of LDR
-stores variable coming from sensor
-sets pin 13 as output
-sets serial port for communication

-read value coming from sensor
-prints value coming from sensor
-if sensorValue > 600, pin 13 will light up otherwise it will not.



2. Below is the reference I used to write the code:


3. Below are some of the problems I have encountered and how I fixed them:

I wanted the code to light up when the LDR value is high but the code I was referencing did not explain how to modify the code. 

After consulting some of my friends and referring to Brightspace, I was able to realise the method to make the LED light up. This is through the use of the code:

if(sensorValue > 600)
digitalWrite(LED_BUILTIN, HIGH);
else
digitalWrite(LED_BUILTIN, LOW);


4. Below is the video that shows the code is working:



Output devices: Interface 3 LEDs (Red, Yellow, Green) to maker UNO board and program it to flash

1. Below is the code I have used and the explanation of the code:

Code

Explanation of code

int animationSpeed = 0;

void setup()                        
{          
  pinMode(9, OUTPUT);            
  pinMode(6, OUTPUT);            
  pinMode(3, OUTPUT);            
}

void loop()                        
{

 animationSpeed = 400;

      digitalWrite(9, HIGH);  
      delay(animationSpeed);
      digitalWrite(9, LOW);      
      digitalWrite(6, HIGH);
      delay(animationSpeed);
      digitalWrite(3, HIGH);
      digitalWrite(6, LOW);        
      delay(animationSpeed);
      digitalWrite(3, LOW);        
     
}
-sets animationSpeed as variable as 0

-sets pins 9,6 and 3 as output


-sets variable animationSpeed to 400

-turn on and off each pin with a delay' inbetween

2. Below is the reference I used to write the code:


3. Below are some of the problems I have encountered and how I fixed them:

The problem I encountered in this task is that the green LED I was using was relatively dim compared to the other two. I tried to figure out what the problem was by switching all the placements of the LEDs but the green LED remained as the only one that is dim. From this I was able to conclude the code was not the problem but rather the setup. 

As a result, I reassembled the entire set up and replaced each equipment at a time. It was from this that I realised the resistor I chose had too high resistance and so I changed it out and it works.

4. Below is the video that shows the code is working:



Output devices: Include pushbutton to start/stop the previous task

1. Below is the code I have used and the explanation of the code:

Code

Explanation of code

int buttonState = 0;                
void setup()                      
{
  pinMode(13, OUTPUT);            
  pinMode(9, OUTPUT);            
  pinMode(5, OUTPUT);            
  pinMode(2, INPUT_PULLUP);        
  Serial.begin(9600);
}
void loop()                        
{
  if (digitalRead(2) == LOW){
    while(digitalRead(2) == LOW){}
    if (buttonState == 1)      
    {
      digitalWrite(13, HIGH);        
      digitalWrite(9, HIGH);        
      digitalWrite(5, HIGH);  
     
      buttonState = 0;
    }
    else
    {
      digitalWrite(13, LOW);        
      digitalWrite(9, LOW);        
      digitalWrite(5, LOW);        
      buttonState = 1;
  }
 }
}
-sets the initial state of the button

-sets pin 13,9 and 5 as output
-start a serial connection


-runs the code when button is pushed
-LEDs are turned on
-sets button state back to 0


-LEDs are turned off
-button state is set to 1



2. Below are the references I used to write the code:

3. Below are some of the problems I have encountered and how I fixed them:

The main problem I encountered for this task is modifying the code to include both the code for the button and the code for the LEDs. I already knew how to code them separately but combining them together was much more difficult.

Along with my friend, we searched online for a method to include both of the codes together and finally arrived at the final product.

4. Below is the video that shows the code is working:



Below is my Learning Reflection on the overall Arduino Programming activities.

In the first lesson on Arduino programming, I was introduced to the Maker Uno kit, there were so many different parts that overwhelmed me initially. However, I vaguely remembered using a similar kit back in secondary school so it helped me to get a grasp on what is going on.

Although my teacher took his time to explain each part to my class, I still had difficulty understanding each of the parts' use and was panicking a little. Despite this I was not discouraged as I have always been better at learning through experience.

As my teacher got us to go through some of the activities in the Brightspace learning package, I was much more familiar with each of the parts. For each of the activities, there were already code that was programmed for us and all I had to do was copy and paste into the Arduino IDE, so it was quite relieving as I get to study the code for the future and not have to stress over creating the codes.

After analyzing the codes, I realised that it was actually quite similar to Python which I already had some previous knowledge on. Hence, I was able to apply my skills of analyzing and creating code from Python and use it in Arduino programming. There were still major differences between the two coding methods but I was not worried as my teacher gave us plenty of time to test the maker uno kits out.

This first lesson was pivotal in developing my understanding of Arduino programming and I am extremely grateful to my teacher, Mr Chua and friends who have helped me a lot in my journey. This had been a very useful and fun topic to learn and I feel like learning how to program in Arduino code will be a key skill for me as Arduino code is actually quite similar to C++ which is a popular coding language. 

Thank you for staying with me for so long! Please continue following me in my journey! Bye Bye!





Comments

Popular posts from this blog

Blog Entry 1: Laser Cutting

     Welcome everybody to my first blog entry for CP5070. In this blog entry I will be sharing what I have learnt as well as my experience using the laser cutter during the laser cutting competency test . BACKGROUND INFORMATION Laser cutters utilises a concentrated laser beam which hits the surface of a material and heats it strongly until it melts or vaporises. Once the laser beam has penetrated the material, the cutting process can begin. The benefits of using a laser cutter include: The laser beam is able to provide high levels of precision and accuracy which allows more complex designs to be etched on smaller designs while still having a clean cut. There are less wa ste and contamination that is pro duced The laser allows for cutting of difficult to cut materials NOTABLE SAFETY HAZARDS Laser cutting comes with inherent safety risks and hazards. It is important for users to take note and understand the the hazards associated to laser cutting and the safety control meas...

Blog Entry 2 - Gears

Welcome back everyone! 👋 Thank you for reading my blog entry again. This blog entry will be talking about gears ⚙⚙⚙ as well as sharing my experience of the gears practical. Gears Background Introduction Wheels with teeth are called gears. Gears can be used to change direction of rotation, transmit force and increase speed. Gears can be connected to form a simple gear train. In a gear train, there will be a driver and driven gear. The driver gear will often be connected to a motor shaft which allows the driver gear to turn. A driven gear has its teeth meshed with driver gear and will turn in the opposite direction of the driver gear. In a gear train there could also be an idler gear. The purpose of the idler gear is to allow for the change in rotational direction of the driven gear. It can also be used to fill in large gaps in space between driver and driven gear. Most importantly, it does not affect the speed ratio of the gear train. Another type of special gear is a compo...