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

ABOUT ME

 Hello everybody!  I am Chang Ji Hinn, in this blog I will be documenting my journey through CP5070, Chemical Product Design & Development. My goal for this module is to hone my skills on creating a chemical product and developing a prototype. I am also looking forward to learning about Arduino programming as this will be my first time being exposed to it. In order to accomplish my goals, I will have to use the available resources on Brightspace to learn about Arduino programming as well as exploring the program and gadgets at my own time. To improve my skills in developing a prototype, I will need to work closely with my team to come up with great ideas on how to improve our product while at the same time cultivating my own skills using 3D printers and laser cutter. I will know that I have accomplished my goals for this module if I am able to fully utilise and understand the coding and uno maker kit for the Arduino programming and having created a design that I am proud o...

Blog Entry 4 - Design Of Experiment

Welcome back everyone! In this blog entry I will be solving a case study using Design Of Experiments as well as sharing my reflections for DOE and the practical I did. What is Design Of Experiment?  It is a statistics-based approach to designing experiments A methodology used to obtain knowledge of a multi-variable process in fewest trials possible It is the backbone of product design Types of data analysis Full factorial data analysis Using data gathered from all possible runs  More accurate due to larger sample size Fractional factorial data analysis Uses data gathered from selected possible runs More efficient and resource-effective Case study In this case study, I will be investigating the cause of the loss in popcorn yield. Three factors have been identified as the possible cause. They are: Diameter of bowls to contain the corn Microwaving time Power setting of microwave In order to determine the impact of each factor, experiments will be conducted with each of ...

Blog Entry 6: Project Development

Welcome back everybody to my final blog! For this blog I will be documenting my group's semester long journey in creating a chemical product. My group consists of Brice, Devin, Yuhan and myself! Our group will be creating a door handle steriliser. 1)  Our team's Chemical Device             Chemical Device: Door handle steriliser Project Background:  Door handles are a significant culprit in the spreading of viruses and bacteria. This is because everyone must touch them to open the door, and they rarely get cleaned since they do not look dirty to the naked eye. Also, most door handles are made of stainless steel, which is a perfect material for bacteria to cultivate on. Some examples of viruses that can spread are the coronavirus (COVID-19), norovirus, hand foot and mouth disease, and influenza.           To emphasise, ever since COVID-19 started, the need for sterilisation tools/equipment/media to minimise its s...