Professional Documents
Culture Documents
2018.04.01 - TN - KTDKTD01 - Arduino - Led - Photoelectric Sensor - Encoder
2018.04.01 - TN - KTDKTD01 - Arduino - Led - Photoelectric Sensor - Encoder
1. INTRODUCTION
Arduino (shown in Figure 1) is an open source computer hardware and software
company. It is designed to facilitate interaction with the physical world via sensors while
being able to perform calculations and various functions. Nowadays, Arduino is fast
becoming one of the most popular microcontrollers on the market. Its ease of use, extensive
software library and most importantly, its low cost have come to make it as popular as it is
today.
Many projects using the Arduino can be found on http://www.hackaday.com. In order to
start having fun with the Arduino, free software can be found at
http://arduino.cc/en/Main/Software for Macs, Windows and Linux operating systems. This
website also provides tons of easy tutorials for you to start. Tutorials can be found at
http://arduino.cc/en/Tutorial/HomePage.
In this lab, you will become familiar with the Arduino, interact with the other
hardware, e.g. led, Photoelectric Sensor, incremental rotary encoder and some of their
applications. You will learn how to use the Arduino to interface between hardware on the
control system Kit 01 board (shown in Figure 2) and software (the code). You will also
learn how to use a led module to display number, detect an object by using Photoelectric
Sensor and measure an angle with an incremental rotary encoder.
2. LAB DEVICES
2.1 Arduino Uno Board
3. PROCEDURE
3.1 Set up your Arduino Programming Environment
The Arduino programming environment needs to be set up on a machine that you have access
to. It can be a Windows PC, Mac or Linux machine and it can be a laptop or desktop. Get the
latest version free software from the website ( http://arduino.cc/en/Main/Software). You
should choose the Installer (.exe) that installs directly everything you need to use the Arduino
Software (IDE), including the drivers.
When the download finishes, proceed with the installation and please allow the driver
installation process when you get a warning from the operating system. Follow instructions to
finish the installation as shown in Figure 6
Choose the icon Arduino on your computer to start a new Arduino program ( Sketch)
and Write a simple program name as Blink as shown in Figure 10. Press Verify button to
check your code.
Figure 12. Select your serial port, Tools>Serial Port>COM 7 (COM # depending what
COM port is free during setup)
Click upload button to upload the code to Arduino. Wait until “Done Uploading”
message status appear. The LED should blink and you have successfully installed your
Arduino.
4. REFERENCE
[4] Howtomechatronics.com, How Rotary Encoder Works and How To Use It with
Arduino, 2016. Available: https://howtomechatronics.com/tutorials/arduino/rotary-
encoder-works-use-arduino/ [Accessed: 1- May- 2018].
5. APPENDIX
5.1 Arduino Help
You will find other Arduino functions use them in your sketches at the path Help >
Reference. The structure and use of functions is fully explained.
24. }
25. void loop()
26. {
27. a = 0;
28. so(a);
29. digitalWrite(latchPin, LOW);
30. digitalWrite(latchPin, HIGH);
31. }
32. void so(int num)
33. {
34. switch (num) {
35. case 0:
36. digitalWrite(dataPin, HIGH); digitalWrite(clockPin, LOW);
digitalWrite(clockPin, HIGH); // dau cham
37. digitalWrite(dataPin, HIGH); digitalWrite(clockPin, LOW);
digitalWrite(clockPin, HIGH); // canh g
38. digitalWrite(dataPin, LOW); digitalWrite(clockPin, LOW);
digitalWrite(clockPin, HIGH); // canh f
39. digitalWrite(dataPin, LOW); digitalWrite(clockPin, LOW);
digitalWrite(clockPin, HIGH); // canh e
40. digitalWrite(dataPin, LOW); digitalWrite(clockPin, LOW);
digitalWrite(clockPin, HIGH); // canh d
41. digitalWrite(dataPin, LOW); digitalWrite(clockPin, LOW);
digitalWrite(clockPin, HIGH); // canh c
42. digitalWrite(dataPin, LOW); digitalWrite(clockPin, LOW);
digitalWrite(clockPin, HIGH); // canh b
43. digitalWrite(dataPin, LOW); digitalWrite(clockPin, LOW);
digitalWrite(clockPin, HIGH); // canh a
44. break;
45. }
46. }
Specification:
• Power supply: 5V • Working Current: <100mA
• Adjustable detection range: 3cm - 80cm
Arduino pin and use 'analogWrite' to control the Figure 18. Pin of 74HC595
brightness of the LEDs. This pin is active low, so
we tie it to GND.
A seven-segment display is a LED module
composed of 8 LEDs. 7 of the LEDs are for
segments of one digit (shown as A to G below) and
the other LED is for the decimal point (shown
Figure 19. Seven- segment Led
as DP below). Display module
The schematic diagram to use one 74HC595 control one digit 7 segments Led Display
module shown in Figure 20
e Q3
f Q2
g Q1
DP Q0
VCC 5V
CE, GND GND
SHCP (Clock) 4
STCP (Latch) 5
DS (Data) 6
MR 5V
Figure 20. Connect 74HC595 with one digit 7 segments Led Display and Uno board
indicates the current position of the shaft, making them angle transducers. The output of
incremental encoders provides information about the motion of the shaft, which is typically
further processed elsewhere into information such as speed, distance, and position. Rotary
encoders are used in many applications that require precise shaft unlimited rotation—
including industrial controls, robotics, rotating radar platforms.
There are many different types of rotary encoders which are classified by either Output
Signal or Sensing Technology. The particular rotary encoder that we will use in the lab
assignment is an incremental rotary encoder and it’s the simplest position sensor to measure
rotation. This rotary encoder is also known as quadrature encoder or relative rotary encoder
and its output is a series of square wave pulses.
Any of the two outputs can be used for determining the rotated position if we just
count the pulses of the signal. However, if we want to determine the rotation direction as
well, we need to consider both signals at the same time.
We can notice that the two output signals are displaced at 90 degrees out of phase
from each other. If the encoder is rotating clockwise the output A will be ahead of output B.
So if we count the steps each time the signal changes, from High to Low or from Low
to High, we can notice at that time the two output signals have opposite values. Vice versa, if
the encoder is rotating counterclockwise, the output signals have equal values. So considering
this, we can easily program our controller to read the encoder position and the rotation
direction.
REPORT
Date:………………… Group:……………… Duration: 5 class
hours
Full Name Student ID Signature Grade
Task 2. Modify the Blink program to make the LED flash 5 times (0.5 seconds/time),
pause 2 seconds then flash again.
…………………………………………… ………………………………………………..
…………………………………………… ………………………………………………..
…………………………………………… ………………………………………………..
…………………………………………… ………………………………………………..
…………………………………………… ………………………………………………..
…………………………………………… ………………………………………………..
…………………………………………… ………………………………………………..
Task 7. Use Encoder library to get the pulse input of rotary encoder and show the value
on the led module
0% 25% 50% 75% 100%
Task 8. The resolution of the rotary encoder is: ……… pulse/ revolution (PPR)
Task 9. Write a program to display the integer angle (degree) of the rotary encoder. If
Photoelectric Sensor signal is “LOW”, the value will be reset to “00”
Task 10. Write a program to display the real angle (degree) of the rotary encoder. If
Photoelectric Sensor signal is “LOW”, the value will be reset to “00”