0% found this document useful (0 votes)
29 views

INTERN Mechatronics

The document describes an internship report about working with microcontrollers and motion control. It provides an overview of the workshop and details of projects involving controlling LEDs, 7-segment displays, DC motors and servos using Arduino and other components.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

INTERN Mechatronics

The document describes an internship report about working with microcontrollers and motion control. It provides an overview of the workshop and details of projects involving controlling LEDs, 7-segment displays, DC motors and servos using Arduino and other components.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY

OFFICE FOR INTERNATIONAL STUDY PROGRAMS

REPORT FOR ENGINEERING WORKSHOP


ON MICROCONTROLLER AND MOTION CONTROL

Advisor: Electromechanical Department


Student: Tran Nguyen Bao
Student ID: 205 2880
Dear Electromechanical Department and Mr Thinh,
First of all, I would like to express my gratitude for providing me with the
chance to work as an engineering intern at Labs in Workshop C1. I've
learned a lot about my field of study in the last few month.
I got to see a lot of different parts of robotics and automation (particularly
in arm industrial robots) because you allowed me to work on a range of
projects, from motion control to actual Arduino usage. You and the other
senior interns made me feel very welcome and gave me lots of advice on
how to become a better person.

My interest in pursuing this major has undoubtedly increased as a result of


this internship.

Last but not least, I would want to express my gratitude for all the
knowledge I have gained from Mr.Thinh and the guidance I have gotten.

Sincerely,

Tran Nguyen Bao

2
Content
PART 1: OVERVIEW 4

1.1 About Workshop C1………………………………………………………………… 4

1.2 Workshop Regulation……………………………………………………………….. 4

PART 2: INTERNSHIP CONTENT 5

2.1. Arduino UNO R3……………………………………………………………………. 5

2.2. LED………………………………………………………………………………….. 7

2.3. Control 7-segment, Module 7-segment LED………………………………………. 10

2.4. LED Matrix 8x8……………………………………………………………………. 13

2.5. Control DC Motor………………………………………………………………….. 15

2.6. Learn to use AC Servo Kit…………………………………………………………. 20

PART 3: CONCLUSION 27

3
PART 1: OVERVIEW
1.1 About Labs in Workshop C1

Address: 286 Ly Thuong Kiet street, District 10, Ho Chi Minh city.

Founded since: The predecessor of the HCMUT was the National Technical Center,
established in 1957, not until 27th October that it was renamed Ho Chi Minh City
University of Technology.

Working field: Research and development (R&D) in robotics, automation with


system using robots and computer vision.

1.2 Labs in Workshop C1 Regulation

Regulation on working time and using equipments:

 Working time: 7 am to 4 pm. Lunch break: 12 pm to 1 pm. Seminar is carried


out every Saturday to report on the work done this week.
 Air conditioner:
o For the general room: Using fans only.
o For the lab rooms: Only turn on air conditioners after 9 am.
o Turn off air conditioners after work and when leaving the room for more
than 20 minutes. When leaving, shut down CB of the room. Leave the
key in Lab 3 after everytime using.

Equipments and household appliances:


Rooms Front

General Mr. Quý’s Room (Laboratory Head)


Room Robotics and Vision lab:

- 2 industrial robots

Lab 0 - Mr.Chí’s room (Lab 0’s Head)

Lab 1-3 - Intern’s room

4
PART 2: INTERNSHIP CONTENT
2.1. Arduino UNO R3

Microcontroller ATmega328 (8bit)

Working voltage 5V – DC

Working frequency 16 MHz

Current 30mA

Recommended voltage 7-12V – DC

Voltage limit 6-20V – DC

Maximum current on I/O pin 30 mA

Maximum output current (5V) 500 mA

Maximum output current (3.3V) 50 mA

Flash memory 32 KB (ATmega328) with 0.5KB used by


bootloader

SRAM 2 KB (ATmega328)

EEPROM 1 KB (ATmega328)

5
Energy pin:

 IOREF (I/0 Reference Voltage): Provide the voltage reference with which the
microcontroller operates.
 RESET: Pressing the Reset button on the board to reset the microcontroller is
similar to connecting RESET pin to GND with a 10KΩ resistor.
 GND: Ground
 5V and 3.3V: Provide regulated 5V and 3.3V
 Vin (Voltage Input): The input voltage to the Arduino while it is using an
exterior power supply

Digital pin:

 Serial Port: 0, 1:
o RXD (0): Received data
o TXD (1): Transmitted data

6
 PWM (~): 3, 5, 6, 9, 10, 11: Provide PWM (Pulse Width Modulation) with 8
bit of resolution ( value varies from 0 → 28-1 corresponding to 0V → 5V) by
using function analogWrite().
 SPI pins (Serial Peripheral Bus): 10 (SS), 11 (MOSI), 12 (MISO), 13
(SCK):
o SS: Slave Select
o MOSI: Master out – Slave in
o MISO: Master in – Slave out
o SCK: Serial Clock

Analog pin: (A0 – A5):

Provide resolution of 10 bit (0 → 210-1) to read voltage from 0 to 5V.

2.2. LED

a) Control 1 LED: basic use of Arduino Pin and IDE.

CODE Explanation

#define led = 13 Define led pin is pin 13

void setup() {

pinMode(led, OUTPUT); } Initialize digital pin “led” as an output.

void loop() {

digitalWrite(led, HIGH); Turn the LED on (HIGH is the voltage

delay(1000); level)

digitalWrite(led, LOW); Turn the LED off by making the voltage


LOW
delay(1000);
1 second delay

7
b) Control 8 LED ON and OFF in series using IC 595

PINS 1-7, 15 Q0 đến Q7 Output pins

PIN 8 GND Ground

PIN 9 Q7" Serial out

PIN 10 MR Master Reclear,


connect to Vcc to turn
IC into activation

PIN 11 SH_CP Shift register clock pin

PIN 12 ST_CP Storage register clock


pin (latch pin)

PIN 13 OE Output enable, connect


to GND to turn LED
on.

PIN 14 DS Serial data input

PIN 16 Vcc Positive supply voltage


for IC and LED.

For IC 595:

 Pin 8 is connected to GND.


 Pin 1 – 7 and 15 (Q0 – 7) of IC HC595 is connected to 8 LED.
 Pin 16 is connected to 5V pin.
 Pin 13 is connected to GND.
 Pin 10 is connect to 5V pin.

8
Arduino to IC HC595:

 Pin 11 of IC to Digital pin 12 of Arduino.


 Pin 12 of IC to Digital pin 8 of Arduino.
 Pin 14 of IC to Digital pin 11 of Arduino.

Simulation by Proteus

 By using IC HC595, minimize number of wires needed.

9
2.3. Control 7-segment, Module 7-segment LED

a) Count number of time that button is pressed by 7 – segment LED:

Using function attachInterrupt() to call out a function whenever the condition is met.
For example: attachInterrupt(0, tang, RISING);

Whenever there is a change in button state (from LOW to HIGH), function “tang” is
called, which controls the 7-segment LED to increase by 1.

b) Using Module 7 – segment LED to run 0 – 9999:

Simulation by Proteus

10
int LED1 = A1; int LED2 = A2; int LED3 = A3; int LED4 = A4;

int SHCP = 5; int DS = 6; int STCP = 7;

unsigned char Code7seg[] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8,
0x80, 0x90};

void setup() {

pinMode(LED1, OUTPUT);

pinMode(LED2, OUTPUT);

pinMode(LED3, OUTPUT);

pinMode(LED4, OUTPUT);

pinMode(SHCP, OUTPUT);

pinMode(DS, OUTPUT);

pinMode(STCP, OUTPUT);

void Ic74hc595(unsigned char a){

unsigned char i;

for(i=0; i<8; i++){

digitalWrite(DS,a & (0x80>>i));

digitalWrite(SHCP,LOW);

digitalWrite(SHCP,HIGH);

digitalWrite(STCP,LOW);

digitalWrite(STCP,HIGH);

11
void loop() {

int dem, nghin, tram, chuc, dvi;

unsigned char i;

for(dem=0; dem<1000; dem++){

nghin = dem/1000;

tram = (dem%1000)/100;

chuc = ((dem%1000)%100)/10;

dvi = ((dem%1000)%100)%10;

for(i=0; i<20; i++){


Ic74hc595(Code7seg[nghin]);
digitalWrite(LED1, HIGH);
delay(1);
digitalWrite(LED1, LOW);
Ic74hc595(Code7seg[tram]);
digitalWrite(LED2, HIGH);
delay(1);
digitalWrite(LED2, LOW);
Ic74hc595(Code7seg[chuc]);
digitalWrite(LED3, HIGH);
delay(1);
digitalWrite(LED3, LOW);
Ic74hc595(Code7seg[dvi]);
digitalWrite(LED4, HIGH);
delay(1);
digitalWrite(LED4, LOW);
}
}
}

12
2.4. LED Matrix 8x8

Continuous display letter

At first, we didn’t know which pin controls which led because there is no label on the
equipment. Therefore, we had to test each pin individually and noted. Here is the
result:

Upper
1 2 3 4 5 6 7 8
pin

Row 6 3 1 2 4

Column 5 3 2

Lower
1 2 3 4 5 6 7 8
pin

Row 8 5 7

Column 4 6 1 7 8

13
Then we continued to connect 16 pins of matrix LED 8x8 to digital pin 2 -> 13 and
analog pin A0 -> A3 of Arduino Uno R3.

Argorithm:

We define matrix LED pins corresponding to rows and column.

There is no way to turn many rows on simultaneously. Therefore, we turn on each


LED of each row progressively at high speed, then we move down to the next row.
Since our eye cannot catch up with this speed, it seems like different LEDs light at the
same time.

14
2.5. Control DC Motor

When it comes to controlling a DC motor, there are many problems to consider:


direction, position, speed, ect. We use encoder to control the position and driver
L298N to reserve direction of the motor as well as speed up or slow down motor.

a) Encoder

Definition:

Encoder is a sensor that can sense position, direction, speed or count, providing
information in digital without the need of a Analog – Digital converter. Encoders are
used as feedback component for CNC machines and robots.

Basic structure:

 Code disk
 Light source
 Light sensor

Working principle

The Code Disk has pattered blurred lines like spokes found on a bike’s wheel. With
each rotation of the encoder shaft, there’s an interruption of light beams from the LED
by opaque lines on the Code Disk before being picked by the photosensor.

Consequently, a pulse signal like light = on; no light = off. Signals are sent to the
counter or controller, that will, in turn, send signals to give the desired function.

15
Classification:

Absolute encoder Incremental encoder

Code disk Using disk in binary code, Count the number of times the
Gray code or BCD code signal on and off

Resolution Depends on the output bit Depends on number of holes


on the disk

When power is on Begin at the current Begin at 0


position by reading the
pattern on the disk

Advantages Provide the exact position Cheap

Disadvantages Expensive Can only sense the amount of


distance, but not the exact
position

b) Driver L298N
 To reverse diretion, we need a bridge circuit

When S1, S4 is closed and S2, S3 is opened, the motor rotates in 1 direction. When we
do the opposite, the motor rotates in the other direction

16
 To control speed, we need to use PWM (Pulse Width modulation)

PWM is the state HIGH – LOW of voltage repeating continuosly. Depening on the
duty cycle, which is the percentage of time ON over the period, we can produce the
desired voltage between max and min value instead of just HIGH and LOW states.
Therefore, we can control the speed by control the output voltage.

In Arduino, we can use analogWrite(), on the scale of 0 – 255, to simultate voltages in


between full on (5V) and off (0V). For example: analogWrite(127) is a 50% duty
cycle, which provides a voltage of 2.5V.

 This is why driver L298N is used. Because it can do both of the function above.

17
Input pin: IN1, IN2, IN3, IN4: Receive control signal.

Output pin: OUT1, OUT2, OUT3, OUT4: Connect to motors.

Pin EnA and EnB is used to control H Bridge inside driver:

 When EnA = 0 : Motor A don’t rotate despite any input.


 When EnA = 1 :
o INT1 = 1; INT2 = 0: Motor rotates forward.
o INT1 = 0; INT2 = 1: Motor rotates inverse.
o INT1 = INT2: Motor stops.

The same goes to EnB, IN3, IN4.

18
c) Design DC motor kit

Prepare:

 1 Arduino UNO R3
 2 Terminal
 1 driver L298N
 1 DC Servo motor
 1 motor holder

Purpose:

 Practically experience mechaniacal design.


 Apply knowledge about PID to control position and speed

Result:

 Position: Rotates exact 1 revolution by counting number of pulse (with the


error about 2 – 3 pulse per revolution).
 Speed: The maintained speed was not stable due to mechanical design error.

19
2.6. Learn to use AC Servo Kit

20
Jogging

Method 1: On the amplifier

Press MODE/SET to enter the Auxiliary Function Mode

Change to Fn002

Press and Hold DATA button

Press MODE/SET to turn Servo ON

Press up or down buttons to jog

Pn304 to change speed

Method 2: Use Arduino to control


 Position

Connect control pin from Adruino to pin no.7 of the amplifier

Encoder resolution
Delay time= × Required revolutions
Gear ratio × Arduino PIN frequency

 Speed control

Connect control pin from Arduino to pin no.5 of the amplifier

analogWrite (pin, 0-255)

21
PART 3: CONCLUSION
At Workshop C1, I was given the opportunity to conduct hands-on experiments
in my study field. Here, I was given tools and equipment to use the knowledge I had
gained to build my first projects. By conducting experiments, I learned the distinction
between theory and practice. When it comes to practice, numerous issues arise.
For example, we knew how to use Arduino, the L298N driver, and the motor
separately, but when we built the DC motor kit, we failed several times due to
mechanical design or coding errors. That is why the lab holds seminars every
Saturday. In a weekly seminar, I had the opportunity to learn about various fields
presented by other groups. Mr.Thinh provided us with hints at the end of each
presentation, which was extremely helpful in our problem-solving efforts. Aside from
major-related knowledge, I've learned a variety of skills that will be useful in the
future.
I learned how to be organized, save money, and do a lot of small things that will
complete me as a person and engineer during my time working in C1, thanks to the
Electromechanical and Mr. Thinh.

22

You might also like