Professional Documents
Culture Documents
through mechatronics:
From high school
to college
Abstract
For many years, educators at all levels have been trying to revamp their teaching styles
to optimize the learning process. The availability of new virtual and technical instruc-
tional tools has led to significant increase in research in teaching methodologies whose
outcome can be split into three categories: (1) lecture delivery, e.g. flipped classroom;
(2) interactivity, e.g. instantaneous gathering of students’ feedback; and (3) technology
in the classroom, e.g. using clickers and other gadgets. The focus of this article is on the
latter; particularly, the use of technology in teaching concepts that are hard to grasp by
mechanical engineering students. These include electromagnetism, semiconductors,
design, controls, and system dynamics. The work presented here is based on data
collected from activities with 10th and 11th graders, college sophomores, and seniors.
The activities include two-week long Science, Technology, Engineering and Mathematics
course and a regular semester long mechanical engineering technical elective.
A remarkable level of engagement and participation was observed from the students
which led to the successful design and construction of interesting devices and systems
which earned them recognition by their colleagues, administrators, and industry
visitors. In addition, the student enrollment in the mechanical engineering program
has increased by 44% since the start of the Science, Technology, Engineering and
Mathematics event for high school students in 2013.
1
Mechanical Engineering Program, Texas A&M University at Qatar, Doha, Qatar
Corresponding author:
Mansour Karkoub, Mechanical Engineering Program, Texas A&M University at Qatar, Doha 23874, Qatar.
Email: mansour.karkoub@tamu.edu
2 International Journal of Mechanical Engineering Education 0(0)
Keywords
Instructional technology, Science, Technology, Engineering and Mathematics, mecha-
tronics, Arduino
Introduction
It has become clear that there is an aggressive movement from schools to
“transform” the educational experience of students driven by technological and
financial reasons.1–3 The financial pressure is due to tuition costs which have been
rising for many years. Consequently, administrators are constantly on the defen-
sive to justify the exorbitant cost of education. This makes potential students look
for cheaper alternatives, e.g. online education. Despite the fact that the community
has yet to accept this method as an equal to the traditional degrees, online
education is making strides to improve the quality of their subject offering and
authenticity of the offered degrees. However, the “brick-and-mortar” schools have
gone about their businesses the same way they always have and tuition has more
than doubled in the last two decades or so. The shopping mall versus online
shopping syndrome is a wake-up call for administrators to creatively add value
to the traditional degree offering and keep up with the technological advances
which made online education gain ground. Therefore, efforts are being made
by a vast majority of US schools to revamp engineering education, specifically
the teaching methodologies, to provide experiences only “brick-and-mortar”
schools can offer.
For many years, engineering schools around the world have been trying to
change the way we teach the new generation of students.2–5 The traditional
“blackboard-and-guru” instructional style is worn out, has reached its limits,
and alienated some potential customers; therefore, one can no longer rely on
it to produce the right number and quality of engineers needed to advance the
state of the art. Concerns have been raised about using the same archaic techniques
to teach difficult engineering subjects which led to a genuine disinterest of our
students in the engineering field despite the recent unbelievable technological
advances. Often, traditional information delivery methods do not take advantage
of available knowledge and virtual tools, such as apps to simulate circuits and
motors or controlling a simple mechanical system using a smart phone, which
could be easily ingested by technology savvy students. It also ignores the fact
that there are live bodies in the classroom with lots of latent energy that can be
exploited to liven up the learning experience.6–8 Consequently, there appear to be a
disconnection between the instructor and the students resulting in serious boredom
with the subject. To avoid the aforementioned problems, many schools have been
tinkering with different teaching formats: flipped classroom at the University of
Texas and Texas A&M University, I-Series at the University of Maryland,
iFoundry at the University of Illinois, iDesign at Rice University, Engineering
Karkoub and Abduallah 3
meant for mechatronics-based courses, they can be easily integrated to teach other
subjects such as heat transfer, mechanics, and dynamics.
Mechatronics is a multidisciplinary field of engineering which combines
knowledge from systems engineering, mechanical engineering, electrical
engineering, telecommunications engineering, control engineering, and computer
engineering. It makes use of principles and laws from the aforementioned fields in
a synergetic way to make smart “machines.” In late 1980s, a trend to make
machines more intelligent led to the birth of affordable electronic components
which can be easily embedded in mechanical systems to make them “smarter.”
By the early 1990s, advances in computational intelligence were integrated with
mechatronics which revolutionized the field.
Realizing how important mechatronics education is in the age of smart infra-
structure and Internet of Things, many companies have surfaced in the market
selling mechatronic educational kits which include some type of a microcontroller
and a set of peripherals, such as IR sensors, switches, and actuators. These kits
targeted inquisitive minds of all ages and made robotics and mechatronics in gen-
eral enjoyable for learners.16,17 To name a few, kits made by LEGO Mindstorms
and Parallax Inc. are user friendly and did not require significant prior knowledge
of physics and electronics which made them attractive to students of all ages.
The kits’ exercises ranged from simply connecting components to making a
moving machine to more complex systems which require knowledge of program-
ming and advanced electronics.
In this article, we will talk about a specific kit that we used for high school and
college students with different levels of difficulty. The kit, made by Arduino, costs
less than $100 and led to memorable experiences for the students and the instruc-
tor. The basic kit is a simple microcontroller on a printed circuit board ready to
accept digital and analog inputs and provide voltage outputs to a plethora of
peripherals. The set of peripherals depend on the project to be executed and will
be discussed in the following sections. First, we will talk about using the mecha-
tronic kit with high school students with very little or no engineering background
at all and later we will present our findings from an advanced technical
elective course.
The objectives of the work presented here are as follows:
1. Show how mechatronics kits can be used to teach difficult concepts such as
electromagnetism, semiconductors, dynamics, and control to students with little
or no background in the mentioned topics.
2. Show how students can integrate many skills and concepts in one single project
and develop multidisciplinary solutions to real-world problems.
3. Qualitatively assess the impact of knowledge acquired in the mechatronics
course on other courses in the curriculum.
4. Qualitatively assess the level of engagement and learning of students in these
mechatronics activities.
Karkoub and Abduallah 5
graders. The physics behind these concepts were briefly introduced to the students
and hands-on experiments using the Arduino board are used to explain how
various elements behave under different operating conditions, different configura-
tions, and for different applications. The case studies show that the students not
only were able to understand the aforementioned concepts, but also successfully
apply them to complex projects.
components). By the end of the first week, the students became familiar with all
the components needed in the project and completed the conceptual design of
the robot. The second week was dedicated to the design and construction
of the firefighting robot. The project components needed for the project are
listed in Table 2.
The logic for controlling the robot is shown in the flowchart of Figure 1 where
the main tasks are as follows: (1) search for fire source by moving forward
(run motor wheels); (2) if obstacle is encountered, move left, right, or backward
depending on which proximity sensor is activated (loop through IR and ultrasound
sensors); (3) when general area of fire is located (current from LED changes
because of increased luminosity), stop and localize direction of fire by swinging
front of robot (run wheels one at a time); (4) once fire is localized, pump water
toward source (turn pump on). See Figure 1 for more details.
The students completed the construction of the robot and wrote the necessary
code for the robot to roam autonomously within the first three days of the second
week. The fourth day was mainly used to test the robot and tweak the code to
resolve communication errors between the microcontroller and the various sensors
onboard the robot. Figures 2 and 3 show the final product executing two crucial
tasks: (1) finding the source of fire and (2) extinguishing it. During, the last day of
8 International Journal of Mechanical Engineering Education 0(0)
Figure 1. Logic diagram of the firefighting robot. IR: Infrared; UT: Ultrasound Transducer.
the event, the students participated in an industry sponsored half day design show
(see Figure 4) where visitors from industry and academia are asked to assess all
participating projects. The students won top honors with their design.
Equipment Purpose
Figure 5. Control diagram for the AUV. AUV: autonomous underwater vehicle.
follows: (1) turn both propellers on to move forward or one to turn left or right,
(2) use the GoPro camera to take live videos and transmit them to an iPhone,
(3) pan and tilt the camera as needed to obtain a 360 picture of the surroundings
(see Figure 5).
Figure 6 captures the different stages of the design process: (1) brainstorming,
(2) construction of the body of the AUV, (3) testing of the buoyancy of the AUV,
Karkoub and Abduallah 11
Figure 6. Various stages of the AUV design process: (a) Initial design stage, (b) beginning con-
struction of AUV, (c) body and ballast construction, (d) buoyancy testing, (e) final AUV prototype,
and (f) exhibition stage.
and (4) integration of the electronic components with the body of the AUV. It is
worth noting that programming the Arduino board and integration of the sensors
and actuators are executed simultaneously with the design of the body of the AUV.
Postmortem review
The goal of the mechatronics projects offered to high school students is to build
their preengineering background in a unique way and at the same time entice them
to think about an engineering career. In addition, the students will be educated
about important issues of great importance to the country and emphasize the sense
12 International Journal of Mechanical Engineering Education 0(0)
of purpose for a career in engineering. It is apparent that, even though many of the
students had little or no relevant scientific background before the STEM event,
they were able to understand some of the physics behind the devices they used.
Not only that, but they were also able to use these devices correctly and achieve
significant results at the end of the project. The excitement and engagement of the
students were really noteworthy and this was due to the fact that the students
realized they were developing real solutions for real problems not just “kids’
play.” The students’ interaction with the instructors and with each other was
remarkable. At times, we had to leave the students alone for a short period of
time to give them some space to work without “adults” hovering over their should-
ers. The sessions were recorded and examined later in the day to see if the students
behaved differently when they were alone. Interestingly, the students were so
immersed in the tasks that often did not even realize we were gone. The compo-
sition of the group (three girls and three boys) and their diverse background and
interests have given us great insights on the impact of a diluted version of a college-
level mechatronics course on high school students learning and engagement.
In fact, two out of the six students had no interest in engineering and two had
no interest in mechanical engineering. The lack of bias toward engineering and the
scientific background of the students can give an objective insight on whether the
STEM mechatronics course was successful in teaching new concepts and sway
these students toward mechanical engineering or not. Without a doubt, the two-
week event gave students an opportunity to acquire some engineering skills and
insights in a very effective way. A survey was sent to students for feedback to assess
the impact of the two-week course and the results are summarized in Table 4.
The data collected from the survey are in total coherence with our observations
during the various activities of the STEM event. More importantly, the enrollment
in the mechanical engineering program increased by more than 40% as shown in
Table 5. Many of the students who participated in the STEM event joined the
mechanical engineering program and their choice was influenced by the STEM
event. This information was collected through interviews with the freshman class.
The total enrollment for all four engineering programs in the engineering school
is capped to 110 students per year. Therefore, one can conclude that the STEM
mechatronics course achieved its intended objectives. It is worth noting that the
preceding conclusion has been reached after teaching this short course for three
consecutive years: 2013–2017.
2016–2017 39
2015–2016 34
2014–2015 34
2013–2014 28
2012–2013 27
STEM: Science, Technology, Engineering and Mathematics.
lab. The course is not usually a favorite among mechanical engineering students
for three main reasons: (1) weak electrical engineering background, (2) lack of
programming skills with high level languages, and (3) technophobia. It is
common knowledge that mechatronics relies on electrical engineering concepts
and other engineering skills including mechanical and systems engineering.
However, these concepts can be taught in such a way that students with minimal
physics background can understand the concepts and enabling them to use linear
and nonlinear electrical elements in mechatronic designs effortlessly. The concepts
are usually explained using mechanical systems that students can easily relate to.
For example, linear elements, such as resistors, capacitors, and inductors, have
their mechanical counterparts, i.e. dampers, springs, and inertias, and their
behavior can be easily explained to sophomores or higher students. The nonlinear
elements, such as diodes and transistors, have their mechanical counterparts also,
i.e. valves and fluid systems, which can be easily understood by junior and higher
students. More importantly, transistors and diodes are studied as switches and no
detailed information about the physics behind their composition is required for
successful integration of these elements in mechatronic systems. It is worth noting
that the aforementioned elements make up the majority of the circuitry used to
interface sensors and actuators with microcontrollers; hence, students can develop
complex devices and systems based on the functions of these elements and not
necessary their composition.
The programming part of the course is built on prior knowledge of the subject
from other courses where Matlab is used to execute logical instructions to solve
mechanical engineering problems. Matlab and C-programming are very similar,
but different. However, making the switch from Matlab to C is necessary and can
be done in baby steps through a series of labs and exercises and implemented on
the microcontroller. Students are often provided with incomplete blocks of code
which require tweaking for interfacing a particular sensor or actuator (see
Appendix 1), i.e. they need to complete the C-code functions to successfully inter-
face the peripherals. Often, students are required to develop their own code and
integrate other software, such as Python, to create graphical user interfaces
(GUIs). By the eighth week of the semester, students become very familiar with
Karkoub and Abduallah 15
LCD: Liquid Crystal Display; RFID: Radio Frequency Identification; USB: Universal Serial Bus.
and analog peripherals, sensors, and actuators. Here, we present the results of one
term project which deals with the design of a select-checkout-and-pay shopping
system. The system is to be installed in a show room where the customer checks out
the needed items one by one as s/he browses through the aisles and shelves.
The items’ barcodes are scanned and the multiplicity is entered for each item
added to the cart. Once done, the customer scans his credit card to pay for the
items and heads for the exit. The idea here is to eliminate long lines at the checkout
counters. The electrical and mechanical components needed for the project are
listed in Table 7.
The state machine describing all the events of the shopping system is summarized
in the diagram shown in Figure 7. The main station consists of all the Arduino boards
Karkoub and Abduallah 17
Figure 7. State machine for the overall system design. LCD: Liquid Crystal Display; RFID: Radio
Frequency Identification.
and the sensors used in the EZ-shopping system. The main station sends instructions
to the RFID sensor and barcode reader whenever a purchase is made. The customer
ID and item barcode are then recorded and tabulated for the appropriate bill.
The complexity of this project is in the integration of many sensors and actua-
tors to work synchronously to achieve the desired objective. A program is written
in C and downloaded to the microcontroller to read data from the sensors and
input devices and provide data to the actuators and the GUI tabulating the pur-
chased items. In this program the graphic interfaces are an LCD screen to guide
the customer through the instructions and actions required and a GUI to visualize
the purchased items and their costs. The logical steps programmed in the micro-
processor are detailed in Figure 8.
A prototype was constructed and successfully tested by the students to check the
various logical steps of the mechatronics program. Figure 9 shows the prototype
and all its components.
Figure 9. EZ-shopping system prototype. LCD: Liquid Crystal Display; RFID: Radio Frequency
Identification.
Karkoub and Abduallah 19
Item Quantity
Linear actuator 2 Carry a surgical tool and track a prescribed path made by the
master side
Controller board 2 Control the motion of each linear actuator
Master robot 1 Phantom Omni manipulator used to trace a specific trajectory
LASER sensors 2 Measure the displacement of the actuators and the position of the
surgical tool in the plane
Encoders 2 Measure the motion of the actuators internally
Computer 1 Execute control actions between the master and slave sides
A control program was written in C to measure the position of the Stylus of the
Phantom Omni manipulator in the x–y plane and transform it into voltage com-
mand inputs to the controllers of the linear actuators. The exact path traced by the
Phantom Omni is duplicated by the surgical tool positioned on the x–y table
formed by the two linear actuators. The system is shown in Figures 10 and 11
with the appropriate descriptions.
Postmortem review
The goal of this article is to study the effectiveness of mechatronics in providing
a transformative learning experience and its impact on student learning. As was
mentioned earlier, a good portion of the seniors tend to avoid taking this
course as elective which we did not understand until we spent time with
20 International Journal of Mechanical Engineering Education 0(0)
the students in the prerequisite course. Following is the list of reasons the
students gave us for not willing to register in the mechatronics course: (1)
course seems to be very demanding since it has multiple projects and labs,
(2) course is time consuming since it has a lab component and writing lab
reports will be on the expense of other courses, (3) course relies heavily on
electrical engineering concepts, (4) course requires programming, (5)
building things is not my thing. The course was offered twice (Fall 2011 and
2012) and cancelled because of low interest; however, it was successfully offered
in the Fall of 2013. About half a dozen students registered in the course the
first time and the numbers have been on the rise ever since. In addition, to the
regular course requirements, such as exams, homework, and labs, students had
to demonstrate their projects to junior and senior mechanical engineering stu-
dents in the middle and end of the semester. The interaction between the
current mechatronics students and the potential future ones helped alleviate
most of the fears mentioned earlier and resulted in a significant increase in
interest in the course.
The course provided four important benefits to students based on their feed-
back: (1) integration of material covered in other courses, (2) an opportunity to
successfully build a useful device, (3) the possibility to grow through engagement
and self-reliance, and (4) a sense of peace with hardware especially electronics.
Twenty students were invited to take a survey to assess and evaluate their learning
experience and the results are summarized in Table 9.
Karkoub and Abduallah 21
It is worth noting that students who took mechatronics performed very well in
the capstone design course and were successful in projects which required building
of prototypes.
Concluding remarks
It has become clear to most stakeholders in education that there is a need to
change the way we educate young minds these days. The drive for change has
originated from schools, educators, students, government and nonprofit agencies,
professional organizations, industry, etc. and all have their own reasons. In fact,
many top tier schools have been looking for ways to provide unique learning
experiences to students which take advantage of the communication, technologi-
cal, and pedagogical advancements and account for the change in the ways stu-
dents learn these days. Clearly, these schools are pushing for slow metamorphosis
of the classrooms rather than reinventing the wheel. For that reason, heavy invest-
ments in time and efforts are being made to supplement the current teaching
techniques with new technological tools which potentially could raise the students’
engagement level and improve the learning process. Here, we discussed the use of
mechatronic kits in high school as well as college learning activities and have
shown their efficacy in teaching engineering skills otherwise difficult to grasp.
The case studies presented here are the result of a two-week STEM activity for
high school students and semester-long projects from a senior-level mechanical
engineering course. The presented case studies showed high level of engagement
by the students as well as appreciation for hands-on activities.
Funding
The author(s) received no financial support for the research, authorship, and/or publication
of this article.
References
1. Bitter GG and Pierson ME. Using technology in the classroom. 5th ed. Needham
Heights, MA: Allyn & Bacon, Inc., 2001.
2. Hannafin RD and Savenye WC. Technology in the classroom: the teacher’s new role
and resistance to it. Educ Technol 1993; 33: 26–31.
3. King KP. Educational technology professional development as transformative learning
opportunities. Comput Educ 2002; 39: 283–297.
Karkoub and Abduallah 23
4. Smaldino SE, Russell JD and Heinich R. Instructional Technology and Media for
Learning. New Jersey, USA: Pearson/Merrill/Prentice Hall, 2005.
5. Cunningham C and Billingsley M. Curriculum webs: a practical guide to weaving the web
into teaching and learning. Boston, MA: Allyn & Bacon, 2003.
6. Lever-Duffy J, McDonald J and Mizell A (eds). Teaching and learning with technology.
Boston, MA: Pearson Education, Inc, 2003.
7. Solomon G, Allen N and Resta P (eds). Toward digital equity: bridging the divide in
education. Boston, MA: Allyn & Bacon, 2003.
8. Tomei L. The technology façade: overcoming barriers to effective instructional technology.
Boston, MA: Allyn & Bacon, 2002.
9. Levin T and Wadmany R. Teachers’ views on factors affecting effective integration of
information technology in the classroom: developmental scenery. J Technol Teacher
Educ 2008; 16: 233–263.
10. Kleiman GM. Myths and realities about technology in k-12 schools: five years later.
Contemp Issues Technol Teacher Educ 2004; 4: 248–253.
11. Mehlinger HD and Powers SM. Technology & teacher education: a guide for educators
and policymakers. Boston, MA: Houghton Mifflin Company, 2002.
12. Parker R. Increasing faculty use of technology in teaching and teacher education.
J Technol Teacher Educ 1997; 5: 105–115.
13. Strudler N and Wetzel K. Lessons from exemplary colleges of education: factors affect-
ing technology integration in preservice programs. ETR&D 1999; 47: 63–81.
14. Lasry N, Dugdale M and Charles E. Just in time to flip your classroom. Phys Teacher
2014; 52: 34–37.
15. Kim MK, Kim SM, Khera O, et al. The experience of three flipped classrooms in an
urban university: an exploration of design principles. Internet Higher Educ 2014;
22: 37–50.
16. Bishop JL and Verleger MA. The flipped classroom: a survey of the research. In: ASEE
national conference proceedings, Atlanta, GA, June 2013.
17. McCrum D. Evaluation of creative problem-solving abilities in undergraduate
structural engineers through interdisciplinary problem-based learning.
Eur J Eng Educ 2017; 42(6): 684–700.
18. Knapp LR and Glenn AD. Restructuring schools with technology. Boston, MA: Allyn &
Bacon, 1996.
19. Palloff RM and Pratt K. Building learning communities in cyberspace. San Francisco,
CA: Jossey-Bass, 1999.
20. International Society for Technology in Education (ISTE). National education technol-
ogy standards for students: connecting curriculum and technology. Eugene, OR:
ISTE, 2000.
21. Henderson M, Selwyn N and Aston R. What works and why? Student perceptions of
‘useful’ digital technology in university teaching and learning. Stud Higher Educ 2017;
42: 1567–1579.
22. Englund C, Olofsson AD and Price L. Teaching with technology in higher education:
understanding conceptual change and development in practice. Higher Educ Res Dev
2017; 36: 73–87.
24 International Journal of Mechanical Engineering Education 0(0)
void setup() {
// initialize digital pin LED_BUILTIN as an
//output.
Digital output - LED pinMode(LED_BUILTIN, OUTPUT);
}
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
Arduino board connection buttonState = digitalRead(buttonPin);
Item: DC motor
Controlling direction of Description
the DC motor (H-Bridge)
Schematic diagram
C-code
int pinA = 4; // the loop function runs over and
H-bridge connections // H-bridge input 1 //over again forever
int pinB = 12; void loop() {
Purpose // H-bridge input 2 digitalWrite(pinA, HIGH);
The H-bridge can be used to // turn pin A high
drive motors in bidirectional void setup() { digitalWrite(pinB, LOW);
mode. By controlling the states // initialize digital pin pinA and pinB // turn pin B low
of the input pins to the H- // as an output. delay(1000);
pinMode(pinA, OUTPUT); // wait for a second
bridge, the direction of rotation pinMode(pinB, OUTPUT); // Change direction of rotation
of the motor can be changed. } digitalWrite(pinA, LOW);
// turn pin A low
digitalWrite(pinB, HIGH);
// turn pin B high
delay(1000);
// wait for a second
}
26 International Journal of Mechanical Engineering Education 0(0)
Item: DC motor
Controlling speed of the Description C-code
DC motor (PWM)
Schematic diagram
int Motorpin = 9;
void setup(){
Driving actuators – motors pinMode(fadePin, OUTPUT);
}
void loop(){
for(int i = 0; i<255; i++){
analogWrite(Motorpin, i);
delay(15);
}
}
Purpose
The speed of the DC motor can
be controlled using the PWM
technique. The digital pin is
turned on and off at a very fast
rate. The amount of time it is on
compared to a full cycle is known
as the duty cycle. This is
controlled by using the command
analogWrite(PIN, DutyCycle);
C-code
const int transistorPin = 9;
// connected to the base of the
Purpose //transistor
The transistor is an electronic
switch that can control the flow void setup() {
of large current via a small // set the transistor pin as output:
Arduino board connections current input. As such, it can be pinMode(transistorPin, OUTPUT);
used with the microcontroller to }
control devices that draw more
power than the microcontroller void loop() {
digital pins can provide. digitalWrite(transistorPin, HIGH);
delay(1000);
digitalWrite(transistorPin, LOW);
delay(1000);
}
Karkoub and Abduallah 27
C-code
const int RelayPin = 2;
Purpose // connected to the base of the Relay
The relay is an electronic switch
that can open and close high void setup() {
current circuits. In a relay, the // set the Relay pin as output:
circuit being controlled can be pinMode(RelayPin, OUTPUT);
Arduino board connections completely isolated from the }
microcontroller. Some relays
however need more current than void loop() {
the microcontroller can produce. digitalWrite(RelayPin, HIGH);
delay(1000);
Hence a transistor is used to
digitalWrite(RelayPin, LOW);
control it. delay(1000);
}
void setup() {
Serial.begin(9600);
// start the serial port
Digital Input – IR proximity }
sensor
void loop() {
float volts =
analogRead(sensor)*0.0048828125;
// value from sensor * (5/1024)
int distance = 13*pow(volts, -1);
// worked out from datasheet graph
delay(1000);
// slow down serial port
Serial.println(distance);
// print the distance
}
Purpose
The SHARP IR proximity sensor is used to measure the distance to
Arduino board connections an object placed in front of the sensor. It outputs analog voltage that
is nonlinearly correlated with the distance to the object. It can
typically measure between 10 to 70 cm.
28 International Journal of Mechanical Engineering Education 0(0)
if (hallState == LOW) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
Arduino board connections else {
// turn LED off:
digitalWrite(ledPin, LOW);
}}
Purpose
The Hall effect sensor can measure the presence of a magnetic field. The one shown here has a digital
output that is turned on when the presence of a magnetic field crosses a certain threshold. It can also be
used as a revolution counter by placing a ferrous object in the rotating part.
if (digitalRead(7)) {b1=1;}
else {b1=0;}
if(a1!=a0||b1!=b0)
{
delay(5);
if(b1==a0){
rot=0;
Purpose }
The rotary encoder is used to if(a1==b0) {
Digital itnput: Encoder measure angular position. As the rot=1;
knob is rotated, two digital train of }
pulses are generated. By reading
if(rot==0){
them, the microcontroller will be cnt++;
able to determine the angular Serial.println(cnt);
position and the direction of }
rotation. By connecting it to a
pinion of a rack and pinion if(rot==1) {
mechanism, it can also be used to cnt--;
measure linear position. Serial.println(cnt);
}
C-code a0=a1;
int a0,a1, b0, b1, rot; b0=b1;
long cnt=0; }
}
void setup() {
Serial.begin(9600);
pinMode(6,INPUT);
Arduino board connections pinMode(7,INPUT);
}
Karkoub and Abduallah 29
int xPosition = 0;
int yPosition = 0;
int buttonState = 0;
void setup() {
// initialize serial communications at
//9600 bps:
Analog input: Joystick
Serial.begin(9600);
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
Purpose //activate pull-up resistor on the push-
The joystick is an analog sensor //button pin
that returns voltage signals pinMode(buttonPin,
corresponding to the horizontal INPUT_PULLUP);
and vertical position of the
lever. two potentiometers are used // For versions prior to Arduino 1.0.1
to detect the angular position of // pinMode(buttonPin, INPUT);
the lever. A button is also // digitalWrite(buttonPin, HIGH);
embedded in the joystick for
}
additional functionality.
void loop() {
Arduino board xPosition = analogRead(xPin);
connections yPosition = analogRead(yPin);
buttonState = digitalRead(buttonPin);
Serial.print("X: ");
Serial.print(xPosition);
Serial.print(" | Y: ");
Serial.print(yPosition);
Serial.print(" | Button: ");
Serial.println(buttonState);
delay(100);
// add some delay between reads
}