Wednesday, 24 November 2021

Arduino Programming

Arduino Programming

Today, we are tasked to complete activities on interfacing input and output devices.

These are the activities that we need to complete:

1. Input devices:

        a. Interface a Potentiometer Analog Input to maker UNO

            board and measure its signal in serial monitor Arduino IDE

        b. Interface an LDR to maker UNO board and measure 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. Interface the DC motor to maker UNO board and

             program it to on and off using push button on the board


Potentiometer Analog Input

TinkerCAD

As I rotate the knob on the potentiometer clockwise, the frequency of blinks on the LED bulb decreases. This is because the resistance of the potentiometer will increase as the knob is rotated. clockwise. A resister is needed when interfacing with an LED to prevent the LED from exploding. By adding "Serial.begin(9600);" under "voidsetup()" and "Serial.println(sensorValue);" under "voidloop()", we can monitor the sensor value in the serial monitor. In the serial monitor, the sensor value will change whenever the knob is rotated.


The serial monitor shows a increase in the sensor value as the knob on the potentiometer is turned clockwise, with the lowest point being a senservalue of 0 and the highest point having a sensorValue of 1023.

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



How The Code Works
void setup()
{
  pinMode(A0, INPUT);
  pinMode(13, OUTPUT);
}
Pin A0 is configured as an input and Pin 13 is configured as an output to control the LED.

void loop()
{
  // read the value from the sensor
  sensorValue = analogRead(A0);
Within the main loop, a function called "analogRead();" checks the state of pin A0  and stores that value in the variable "sensorValue".

 // turn the LED on
  digitalWrite(13, HIGH);
  // pause the program for <sensorValue> millseconds
  delay(sensorValue); // Wait for sensorValue millisecond(s)
  // turn the LED off
  digitalWrite(13, LOW);
  // pause the program for <sensorValue> millseconds
  delay(sensorValue); // Wait for sensorValue millisecond(s)
}
This string of code controls the flashing of the LED. The "digitalwrite" cause the LED to be "HIGH" or "LOW" which turns the LED on or off respectively. As the potentiometer is rotated and the sensor value changes, which will result in a corresponding change in the duration of each flash of the LED.


LDR

TinkerCAD

LED is dim when LDR is covered (low light intensity)

LED is bright when LDR is exposed to high light intensity

When the LDR detects a high light intensity, the LDR's resistance will decrease causing the LED to be brighter. When the LDR detects a low light intensity, the LDR's resistance will increase causing the LED to be dimmer. The LDR is interfaced with the LED in series.


Code:

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

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

void loop()
{
  digitalWrite(13, HIGH);
  delay(1000); // Wait for 1000 millisecond(s)
  digitalWrite(13, LOW);
  delay(1000); // Wait for 1000 millisecond(s)
}

How The Code Works

int sensorVal = 0;

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

"int sensorVal = 0;" creates a variable for the sensor. Under void setup, we declare PIN 13 as the output.

void loop()
{
  digitalWrite(13, HIGH);
  delay(1000); // Wait for 1000 millisecond(s)
  digitalWrite(13, LOW);
  delay(1000); // Wait for 1000 millisecond(s)
}

When PIN 13 is HIGH, LED will turn on, When PIN 13 is LOW, LED will turn off. There is a 1000ms delay between each action

Flashing LED

TinkerCAD




The 3 LEDs are consecutively light up for 1 second in a sequence with a 1 second pause in between. This is similar to what we did in the competency test during our Arduino practical. I used PINs 12, 10 and 8 as the output. The red LED is connected to PIN 12, green LED is connected to PIN 10 and the yellow LED is connected to PIN 8.


Code:

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

void setup()
{
  pinMode(12, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(8, OUTPUT);
}

void loop()
{
  digitalWrite(12, HIGH);
  delay(1000); // Wait for 1000 millisecond(s)
  digitalWrite(12, LOW);
  delay(1000); // Wait for 1000 millisecond(s)
  digitalWrite(10, HIGH);
  delay(1000); // Wait for 1000 millisecond(s)
  digitalWrite(10, LOW);
  delay(1000); // Wait for 1000 millisecond(s)
  digitalWrite(8, HIGH);
  delay(1000); // Wait for 1000 millisecond(s)
  digitalWrite(8, LOW);
  delay(1000); // Wait for 1000 millisecond(s)
}

How The Code Works

int i = 0;

void setup()
{
  pinMode(12, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(8, OUTPUT);
}

Under void setup, we declare PINs 12, 10, 8, as the output.

void loop()
{
  digitalWrite(12, HIGH);
  delay(1000); // Wait for 1000 millisecond(s)
  digitalWrite(12, LOW);
  delay(1000); // Wait for 1000 millisecond(s)
  digitalWrite(10, HIGH);
  delay(1000); // Wait for 1000 millisecond(s)
  digitalWrite(10, LOW);
  delay(1000); // Wait for 1000 millisecond(s)
  digitalWrite(8, HIGH);
  delay(1000); // Wait for 1000 millisecond(s)
  digitalWrite(8, LOW);
  delay(1000); // Wait for 1000 millisecond(s)
}

This string of code causes the LED to flash in sequence consecutively. The "digitalwrite" cause the LED to be "HIGH" or "LOW" which turns the LED on or off respectively. The PIN 12 output is set to HIGH which causes an LED to light up. The LED lights up for 1 second as the delay is 1000ms. The PIN 12 output is then set to LOW for 1 second which causes the LED on pin 12 to turn off for 1 second. The same thing repeats for the LED connected to PIN 10 and 8 in sequence. Since the code is in a voidloop, it will repeat infinitely.


DC Motor

TinkerCAD




When the button is pushed, the DC motor will turn on. The DC motor is turned off when the button is pushed once more. Initially, when interfacing the DC motor, I had trouble getting it to work. After some inspection and research, I realised that I have interfaced the transistor in the opposite direction. I was previously not aware that the transistor had different pins, the emitter (e), base(b) and collector(c) pins. After interfacing the transistor in the correct direction, the DC motor finally turned on. I also had to interface on the Arduino Uno board slightly different as I would on TinkerCAD as on TinkerCAD we had to add in a button whereas the Arduino Uno board already has a build-in button.
 
Code:
int buttonState = 0;
int status = true;

void setup(){
  pinMode(2, INPUT_PULLUP);
  pinMode(13, OUTPUT);
}

void loop()
{
  // read the state of the pushbutton value
  buttonState = digitalRead(2);
  // check if pushbutton is pressed.  if it is, the
  // buttonState is HIGH
  if (digitalRead(2) == true) 
  {
    status = !status;
    digitalWrite(13, status);
  }
  while(digitalRead(2) == true);
  delay(50);
}

How The Code Works

int buttonState = 0;
int status = true;

void setup(){
  pinMode(2, INPUT_PULLUP);
  pinMode(13, OUTPUT);
}
Within the void setup, PIN 2 is declared as the input and enable the internal pull up resistor. So, by default, PIN2 status will always be HIGH. PIN 13 is declared as the output.
void loop()
{
  // read the state of the pushbutton value
  buttonState = digitalRead(2);
  // check if pushbutton is pressed.  if it is, the
  // buttonState is HIGH
  if (digitalRead(2) == true) 
  {
    status = !status;
    digitalWrite(13, status);
  }
  while(digitalRead(2) == true);
  delay(50);
}
Within the void loop, "buttonState = digitalRead(2);" check if pushbutton is pressed.  if it is, the buttonState is HIGH and the output PIN 13 will be HIGH, causing the DC motor to turn on. When the button is pressed again, the buttonState will be LOW and the DC motor will turn off.




Reflection
For the activities, I had to interface some input and output devices on TinkerCAD and use the breadboard and Arduino UNO board. Since this was my first time using TinkerCAD, I was initially unfamiliar with using it. But with the help of the videos provided, I quickly got accustomed to using it. I also had to program Arduino code to be uploaded to the Arduino board to complete each task. I used certain codes which were publicly available online and modified them to suit my objective. Interfacing the input and output devices were quite challenging for me and required many trial and error for it to work. I believe that what I learnt from doing these activities is important as my group plan to use Arduino programming and interfacing in our chemical product. Learning how to interface input and output devices on an Arduino board as most of the Arduino project will likely include both input and output devices.

Initially, I used to think that Arduino interfacing was very complicated and difficult to learn. However, how that I learnt the function and how to interface each component, I feel more confident in interfacing devices on the Arduino.  I hope to be able to create far more complicated projects with the use of Arduino in the future, either for the CP5070 module or for personal interest.

Wednesday, 3 November 2021

Laser Cutting

 Laser Cutting Practical

In this practical, we learnt how to perform laser cutting on either the FusionM2 or Fusion PRO laser cutter. We had to create a Standard Operating Procedure (SOP) for operating the laser cutter which was later improved upon after completing the practical. This is the improved version of the SOP.


Starting Up Operation

  1. Turn on the air compressor (not required for Fusion PRO)
  2. Turn on the fume extractor
  3. Turn on laser cutter machine
  4. Turn on the computer and pc.
Cordeldraw Operation
  1. Open CorelDraw on computer
  2. On the top left side of the screen, click the 'file' icon and import design file.
  3. Use the select tool and click on the part you would like to vector cut.
  4. Click the brush icon on the bottom right of the screen 

  5. Set stroke to 'hairline' and colour to red. (input colour components as R:255, G:0, B:0) Red is for vector cutting while green is for engraving.



  6. Use the select tool and click on the part you would like to engrave. Select brush icon (Stroke) and set the stroke to none. Select bucket icon (fill) and set the colour to green (input colour component components as R:0, G:255, B:0) 
  7. Click print icon at the top to send file to Epilog Dashboard

Epilog Dashboard Operation
  1. Turn on autofocus 
  2. Click on the folder icon to import material and change material thickness. Set power to 30%  for engraving. Check with personnel in charge if uncertain. (For both machines, position the object to cut at the top left corner so that the laser need not move too far to start cutting)
  3. Press print button


Laser Cutter Operation
  1. Check screen to see whether the filename is correct
  2. Open the lid of the laser cutter and place material inside laser cutter.
  3. Switch mode to jog more and use the joystick to position the laser to where you want to start laser cutting

  4. Press GO/START button to start cutting.
  5. Once laser cutting has been completed, wait 60 seconds before removing product from laser cutter to. This is to let the fumes be removed and let the material cool down.
Shut Down Operation
  1. Clear materials from laser cutter.
  2. Close lid of laser cutter.
  3. Switch off computer.
  4. Switch off laser cutter.
  5. Switch off Fume extractor
  6. Switch off air compressor
  7. Perform housekeeping



Theses are the pieces we printed!!




Reflection

During this practical, we learnt how to perform laser cutting with either the Fusion Pro or Fusion M2. We were first tested on the competency assessment and we realised that our SOP was not detailed, but thanks to the demonstrations from Mr Chan and supervisors, we were able to operate the machine. Next, when we were going to do all the pieces, we realised that all the pieces were not a perfect fit as we underestimated the kerf length, so we went back and redrew all the pieces on Fusion360. Unfortunately, we had to postpone the cutting due to some technical difficulties with our laptops. When we returned back to FabLab the following week, the wood we used was of a different thickness from what we had the previous week. We then change the parametric measures to change all respective gaps. Within a few minutes, we were able to change all 3 designs to their respective dimensions. We also had to decrease the gap more to take kerf into account. In the end, with the wood thickness of 4mm, we changed the size of the gap from the original 4.5mm to 3.5mm. The pieces fit perfectly into each other. 

I found today's practical really interesting as I got to see the laser cutter at work. The precision levels and edge quality achieved with laser cutting machines are better than traditional cutting methods. Furthermore, the process of using the laser cutting machine was straightforward and easy to use. I believe that what we learnt in this practical will benefit us in the future project in this module. The chemical product that we are planning to construct will be using parts that require laser cutting. 

Initially, we thought that adding parameters was just an extra redundant step, but after needing to make quick changes to the slot width, we realised that it was extremely useful and that it should be incorporated into all of our future designs using auto fusion360 especially for CADs with many repeating components. Instead of redesigning all the 3 pieces which will take around 20 mins, we just had to change the parameters for all the designs which took 4 times faster. As we were doing this, we were appreciative of and realized the importance of this function. Furthermore, we had firsthand experience with the importance of kerfs since our first attempt did not stick together, as did all the other groups. After reviewing other groups' attempts, we discussed and decided on a gap length that will work. As a result, our second attempt resulted in a perfect fit.

With the pieces we made using the laser cutter, we constructed a simple yet effective IPad stand.