Skip to main content

Arduino

Arduino is an open-source electronics platform based on easy-to-use hardware and software. It's intended for anyone making interactive projects. With the Arduino UNO board and the Arduino program code, we can make a controller for our project.

In the practical session, my group and I programmed the Arduino UNO board to control the servo to make the pegasus's wing flap. Beyond the base requirement, we decide to use the push button to control the start of the flapping. To make our pegasus toy more interesting, we added a melody using the Arduino programming. The melody we chose is the State Anthem of the Soviet Union🐻.

Working Principle
We use the metal wire to connect the servo and the pegasus's wings. When we program the servo movement, the servo will be turned and apply force to the wing. Thus the wings will be flapping. 



Programming

To achieve this, we combined 3 individual codes together: the push button, the melody, and the servo. So we write the code one by one for each of them then combine them together.

Push Button

The pull-up pushbutton means that when the button is not pressed, an internal pull-up resistor will be enabled to input. Once the button is pressed, the output will change the state to HIGH. This will function as an ON/OFF switch.

we set pin2 as the input and pin 9 as the output to control the servo.

Music

First, add the 'pitches.h' into the library, it consists of all the notes.  then convert the melody to integers that represent in the 'pitches.h'

Convert the note durations to integers.

We use a "for loop" to play the tone. Since our melody has 24 tones, The tone will play 24 times. we also defined the note duration and pause between the notes in this part.

Servo

This allows the servo to move from 0 degrees to 180 degrees then back to 0 degrees. we also use the "for loop" control to achieve this. The output pin is Pin9, so we attached the serve at Pin9.

The problem is how to combine these 3 functions together? We want the music and flapping to play at the same time. In the practical. we tried many possible combinations using what we learned but all cannot work. After we did the internet research, we knew that to achieve this, the multi-thread control must be included. This is too difficult for our level😅😅  so we decided to use another approach



The new approach is to put the servo loop inside the notes loop. This means that when one note is played, the servo will move one loop. Then the next note will play. When the servo is moving quickly and the pause between the note is short. The music sounds like playing continuously. PROBLEM SOLVED😀😀

Final product display

Individual Arduino Task

1a) Interface a Potentiometer Analog Input to make UNO board and measure its signal in serial monitor Arduino IDE.

Components
  • Arduino UNO board
  • Breadboard
  • Potentiometer 
  • LED
  • Resistor
  • Multimeter
Procedure
  1. Attached LED on the breadboard. Connect the cathode to the negative charge on the board. Connect the anode to the PIN13 on the UNO board.
  2. Attached potentiometer on the breadboard. Connect terminal 1 to the negative charge and terminal 2 to the positive charge. Connect wiper to the analog input A0
  3. Connect the Negative charge on the breadboard to the GND on the UNO board and connect the positive charge on the breadboard to the 5V on the UNO board. 
  4. Connect the multimeter negative charge to the GND on the UNO board and the positive charge to the analog input A0.
It should look like this.

Programming

For this task,  I need to use a potentiometer to control the speed of the LED Blinking. When the potentiometer input a higher valve, the LED blink slower. The input is an analog input that can be adjusted by the potentiometer, and the output is the default LED put at PIN13. A resistor is needed as high voltage will affect the lifespan of the LED.

So I defined the voltage to potentiometer as an integer call SensorVal and let it be the analog reading at A0, When I adjusted the potentiometer, I'm adust the voltage from A0 to the potentiometer. The voltage value will use as the gap time between LED on and off. Therefore, a higher voltage will have a longer gap time between on and off. thus the LED blink slower.

Simulation


Simulation Video


1b) Interface a LDR to maker UNO board and measure its signal in serial monitor Arduino IDE.

Components
  • Arduino UNO board
  • Breadboard
  • LDR 
  • LED
  • Multimeter
Procedure
  1. Attached LED on the breadboard. Connect the cathode to LDR terminal 2. Connect the anode to the PIN13 on the UNO board.
  2. Attached LDR on the breadboard. Connect terminal 1 to the negative charge and terminal 2 to the LED cathode and analog input A0.
  3. Connect the Negative charge on the breadboard to the GND on the UNO board and connect the positive charge on the breadboard to the 5V on the UNO board. 
  4. Connect the multimeter negative charge to the GND on the UNO board and the positive charge to the analog input A0.
It should look like this.

Programming
For this task, I need to use the LDR to control the brightness of the LED. Since the LDR is able to change the resistivity based on the light intensity, so the resistive can be input. When the light intensity increase, the resistor increase. So the resistivity will be an input to A0 and LED brightness will change due to the output from PIN13. we need a code to connect the input and output together.

So I defined the light intensity sense by the LDR as an integer call Sensorval and let it be the analog reading at A0. When the light intensity change, the resistor value is sent to A0 and this value will use as the brightness of the LED. Thus, higher light intensity, higher resistivity, brighter the LED.

Simulation

Simulation Video


2a) Interface 3 LED to maker UNO board and program it to perform fade.

Components
  • Arduino UNO board
  • Breadboard
  • LED
  • Resistor
Procedure
  1. Attached 3 LEDs on the breadboard. Connect the cathodes to the negative charge on the breadboard. Connect the anode to the PIN11,9,6 on the UNO board respectively.
  2. Connect the Negative charge on the breadboard to the GND on the UNO board and connect the positive charge on the breadboard to the 5V on the UNO board.
It should look like this.

Programming
For this task, I need the brightness of the 3 LEDs to increase then decrease continuously
So I defined the brightness as an integer call brightness. Then I set PIN11, 9,6 as the output for the 3 LEDs respectively. Use a "for" control. For brightness increase from 0 to 255. the output of the 3 LEDs also increase, the brightness increase. For brightness decrease from 0 to 255. the output of the 3 LEDs also decrease, the brightness decrease. Add a 30millisecond delay to the increase and decrease. Set all this into a loop function.

Simulation
 
Simulation video

2b) Interface the DC motor to maker UNO board and program it to on and off using the pushbutton on the board.

Components
  • Arduino UNO board
  • Breadboard
  • DC motor
  • Pushbutton
  • Resistor

Procedure
  1. Attached the DC motor on the breadboard. Connect Terminal 1 to the negative charge on the board and Terminal 2 to PIN9 on the UNO board.
  2. Attached the pushbutton on the breadboard. Connect Terminal 1b to the positive charge on the breadboard and Terminal 2a to PIN2 on the UNO board and negative charge on the breadboard.
  3. Connect the Negative charge on the breadboard to the GND on the UNO board and connect the positive charge on the breadboard to the 5V on the UNO board.
It should look like this.
Programming
For this task, I need to use the pushbutton to on and off the DC motor. When the pushbutton is pressed, the motor turns on. When the pushbutton is released, the motor turns off.

So I defined an integer as Buttonstate. Set up the PIN2 as input attached to the pushbutton and PIN9 as output attached to the DC motor. Using the "if...else..." control. if the Buttonstate is high which means the pushbutton is pressed. The output PIN9 will be high which means the DC motor starts to spin. Else, if the Buttonstate is low which means the pushbutton is released. The output PIN9 will be low which means the DC motor stopped.

Simulation

Simulation Video

Reflection

In this practical, I faced many challenges. On the practical day, my group and I were not making out what we want. However, we are not giving up so we spent a lot of time together discussing how to solve the problem we faced. We keep rewriting our code to find another approach and eventually it works. Although it made us frustrated and it is time consuming This trial and error process enhances what we learned and deepens our understanding.

Unlike what I learned in other modules,  Arduino programming is totally new to me. It is very challenging at the start but once you understand the logic behind the complicating codes. It is fun to play around with them. Arduino programming allows me to do a simple control to my design device. It is also an important stage to be done when I want to do the CO sensor as our team's final project. I will practice more on the Tinker and I believe that our team will be programming the CO sensor in the end without any difficulty. 






Comments

Popular posts from this blog

3D Printing

3D printing is a type of rapid prototyping technology. It uses materials such as metal and plastic and prints the product layer by layer. 3D printing is very suitable to print objects that could not be easily made subtractively.  By the end of this exercise, I should be able to: Design an object on Fusion 360 that use for 3D printing.  Use the Cura slicer software to convert the stl. file to gcode that are ready to 3D print. Operated the FFF/FDM 3D printer safely and smoothly. Understand the requirements for 3D printing such as support and overhang limit. Print out the product using the 3D printer. Procedure for this exercise: Design a penholder using Fusion 360. Convert the stl. file to gcode in Cura. 3D print the penholder. Design using Fusion 360 After I searched on the internet, I decided to 3D print a penholder. Before I sketch it in Fusion 360. I sketched it on the paper with the parameters labeled. This will ease my work on Fusion 360. Sketches of the front view and sid...

HOME

  Hi, I'm Yiren Welcome to my Home page.  First, let me introduce myself. I am a DCHE student from Class 2B01, team member of F4.   Last semester, my team and I went through a wonderful time in ICPD class. In the end, We worked out a prototype using cardboard on our idea Chemical Product, the self-cooker. All this work can't achieve without a team effort. In the new semester, we improved on our team formation and hope that our team will have a better performance in the future.

Laser Cutting

Laser Cutting Laser cutting is a process in which a high-power laser is used to cut through materials. In this process, a high-density beam is created by stimulating lasing material with an electrical discharge, within an enclosed container. Optics are used to focus the created laser beam onto the workpiece, effectively cutting it by melting, vaporizing, to burning through it. The laser cutter that is used in our school FAB lab is the CO2 laser cutter. T here are two options for the laser cutter, vector and engrave.  Vector means to cut through the material and engrave is cut the patterns on the surface of the material.  In the SP fab lab, I got a chance to operate this CO2 laser cutter.  but before I start the laser cutting machine. Safety is the most important thing that needs to be considered. Thus, when we want to use the laser cutter, we need to be well prepared and develop a standard  operation procedure (SOP) EPILOG PRO LASER CUTTER  SOP Pu...