Embedded Lab: Arduino Projects in Science Lessons

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

4thMediterranean Conference on Embedded Computing MECO – 2015 Budva, Montenegro

Embedded Lab: Arduino Projects in Science Lessons

Gordana Laštoviþka-Medin, Marko Petriü


Faculty of Science and Mathematics
University of Montenegro
Podgorica, Montenegro
[email protected]

Abstract—We describe the way we designed and built embedded source idea, not only in the way they have been and still are
labs while teaching students the basic principles of digital being developed, but also within their community of users.
electronics. By this means, we also introduced students to the Processing, for example, has a feature which allows a
world of embedded microcontrollers with the thought that they publication of a project in form of a website, including an
might someday build their own circuits. applet and the source code. Because of this feature, many
projects built with Processing are being published with the
Keywords-open source hardware, embedded lab, Arduino, LCD, source code, which allows other people, especially beginners,
ultrasound sensor, electronic composer, measurement
to learn from existing projects. They share an orientation
I. INTRODUCTION towards designers and artists as users. The tools'
functionalities, workflow, and language are focused on the
Why did embedded systems and system designs become a activities of sketching: Without any initial setup, users can start
core of our teaching approach implemented in Basic experimenting immediately, and directly experience the results.
Measurement in Physics course? The answer is in the In conjunction with Arduino and other electronic prototyping
following: firstly, embedded systems architecting or designing kits, users use a breadboard and wire up their circuits manually.
architecture of experimental set-up cannot be achieved through This proves to be compatible with a self-taught trial-and-error
rote learning or the cognitive application of pre-defined copy-and paste approach. It also enables the seeing-drawing-
knowledge since by definition the solution to the problem to be seeing cycle, where the design is explored in a tight iteration of
solved is not known in advance [1]. Rather, it depends on the modification followed by testing the experience [5].
ability to learn, and to progress through a formative, dynamic Additionally, a standard electronic interface based upon the
learning process which draws on higher order creative critical “shield” concept makes working with complex hardware a
thinking that begins with experience and observation and simple matter of plugging in the optional boards. All those
concludes with a product which is unique application of features of open source platforms support the system thinking
knowledge for a particular physical/engineering purpose [1]. teaching and building an experimental set-up. Along with
The process of designing a system involves thinking deeply Arduino, Fritzing [5] becomes a powerful new way to think
about the state of system that has been envisioned, and how the about designing electronics and hardware since it allows the
particular components interconnect with each other. But it is users to empower themselves by designing hardware that was
also about considering: what to do when things go wrong, why once only in reach of trained electrical engineers.
a proposed solution might fail, and what unintended
consequences might occur based on built design. As a This paper explores the world of Arduino, Fritzing and
methodology for learning about systems, design is about sensors through multiple versions of existing ideas. We
providing constructive context in which to explore ideas, integrate ongoing feedback into the learning process, and
interactions and expressions. Linking design to digital media identify the strength and weakness of designed systems [6].
tools expands this concept further. When learning the tools of
networks and computer systems, it is important to think of II. THE EMBEDDED LAB
them as a system rather than a specified set of interfaces [1-2]. The lab consists of a small data acquisition board able to
read signals from various sensors connected to a standard
The programming environment Processing [3] and the personal computer through a USB cable. There are four main
microcontroller Arduino [4] have been two important tools in components to the framework, namely: (a) an Arduino board,
system design development including embedded systems. equipped with a microcontroller; (b) the computer program
Processing is a Java-based programming language including an running on the microcontroller itself, loaded from the PC; (c) a
easy-to-use IDE with focus on visual programming. Arduino is custom shield (which could be developed as a series of shields)
a system consisting of a microcontroller with USB or (d) the control software running on the host computer and set
Bluetooth connections, and a programming environment of sensors interfaced to the Arduino platforms and used to
targeted towards designers and artists who want to build interact with the surrounding.
interactive artifacts. Processing and Arduino rely on the open

– 284 –
4thMediterranean Conference on Embedded Computing MECO – 2015 Budva, Montenegro

The Arduino platform. – The Arduino platform is an open The connection of the Arduino module to the breadboard is
source electronics prototyping platform based on flexible, easy- shown in Figure 2. The breadboard power supply and ground
to-use hardware and software. It is intended for artists, (GND) pins were connected to the corresponding pins on the
designers, hobbyists and anyone interested in creating microcontroller. On the Arduino module, the 5V pin and any of
interactive objects or environments. The system provides sets the ground connections were used. One end of the 8 ȍ speaker
of digital and analog I/O pins that can be interfaced with was connected to pin 8 of the Arduino board. The other end
various extension boards and other circuits. The boards feature was connected to the ground pin. The experimental-set up can
serial communications interfaces, including USB on some be further modified by adding two photo resistors as shown in
models, for loading programs from personal computers. For Figure 3. The photocells act as a voltage divider, allowing us to
programming the microcontrollers, the Arduino platform change the value of the analog input by covering either one of
provides an integrated development environment (IDE) based them.
on the Processing project, which includes support for C and
C++ programming languages [7].
The Arduino shield. -The shields are small print circuit
boards (PCB) to be plugged into the top of the Arduino board,
and which act as an interface between the board and the
external world (e.g.,with sensors) or extend the functionalities
of the board itself.
The Arduino firmware – By building onto the Arduino core
library, we have implemented a set of configurable programs
(or sketches) for the microcontroller.
III. APPLICATIONS
On its own, Arduino is simply a microcontroller
development board. But by building a project around it, an Figure 2. The sensor circuit consists of the Arduino and a breadboard.
embedded system is created. A few of the projects designed
during the Basic Measurement in Physics course are presented
below. Students attending the course are second-year
undergraduates of the Department of Physics at the Faculty of
Science of the University of Montenegro.
A. Making music with Arduino and a speaker: a composer
fed by an electrical signal
The aim of the project was to produce Beethoven’s Für
Elise. In order to produce the tone output, the following
hardware components were used: an Arduino board, an 8ȍ
small speaker, a 1Kȍ resistor, and hook-up wires. The circuits
and hardware components are displayed in Figure 1.
Figure 3. Sensor circuit with two additional photodiodes, done by Fritzing
program..

When we use analogOut() to create pulse width modulation


(PWM) on an output pin, we can change the on-off ratio of the
output (also known as the duty cycle) but not the frequency. If
a speaker is connected to an output pin running analogOut(),
changing loudness is achieved, but the tone is kept constant. To
change the tone, the frequency has to be changed and it is done
by using tone() command. The syntax of the tone function is
governed by three parameters: the pin (the pin on which to
generate the tone); tone frequency (in hertz) and tone duration
(in milliseconds). The tone function generates a square wave of
the specified frequency on a pin. Each musical note is
determined by a frequency. The Pitches.h file contains all the
Figure 1. a) Electric circuit diagram. b) Arduino Mega 2560, USB cable, 1K pitch values for typical notes. For example, the frequency for
ȍ resistor, 8ȍ speaker. note A4 (A for "La" and 4 for the 4th octave) is 440 Hz. In the
array, it will be called NOTE_A4, while NOTE_C4 is middle
C.

– 285 –
4thMediterranean Conference on Embedded Computing MECO – 2015 Budva, Montenegro

The code is as follows: int Pause = IntTone * 1.30;


#include "pitches.h" //We can define pause as: Pause = IntTone*1.3 delay.
int ZaElizu[] = { delay(Pause);
NOTE_E4, NOTE_DS4, NOTE_E4, NOTE_DS4, NOTE_E4, noTone(127);
NOTE_B3, NOTE_D4, NOTE_C4, NOTE_A3, NOTE_E2,
NOTE_A2, NOTE_C3, NOTE_E3, NOTE_A3, NOTE_B3, }}
NOTE_E2, NOTE_GS2, NOTE_E3, NOTE_GS3, NOTE_B3,
NOTE_C4, NOTE_E2, NOTE_A2, NOTE_E3, NOTE_E4, void loop() {}
NOTE_DS4, NOTE_E4, NOTE_DS4, NOTE_E4,NOTE_B3, There is no need to repeat the melody, so there are no
NOTE_D4, NOTE_C4, NOTE_A3, NOTE_E2, NOTE_A2, arguments in the command void loop.
NOTE_C3, NOTE_E3, NOTE_A3, NOTE_B3, NOTE_E2,
NOTE_GS2,NOTE_E3, NOTE_C4, NOTE_B3,
NOTE_A3,NOTE_E2, NOTE_A2, NOTE_B3,
NOTE_C4,NOTE_D4,NOTE_E4,NOTE_G2,NOTE_C3,NOTE_G3,
NOTE_F4,NOTE_E4,NOTE_D4,NOTE_G2,NOTE_B2,NOTE_F3,N
OTE_E4, NOTE_D4, NOTE_C4, NOTE_E2, NOTE_A2,NOTE_E3,
NOTE_D4, NOTE_C4, NOTE_B3, NOTE_E2, NOTE_E3,
NOTE_E3, NOTE_E4, NOTE_E3, NOTE_E4, NOTE_E4,
NOTE_E5,NOTE_DS4, NOTE_E4, NOTE_DS4, NOTE_E4,
NOTE_DS4, NOTE_E4,NOTE_DS4, NOTE_E4, NOTE_DS4,
NOTE_E4, NOTE_B3, NOTE_D4, NOTE_C4, NOTE_A3,
NOTE_E2, NOTE_A2, NOTE_C3,NOTE_E3, NOTE_A3,
NOTE_B3, NOTE_E2, NOTE_GS2, NOTE_E3,
NOTE_GS3,NOTE_B3, NOTE_C4, NOTE_E2, NOTE_A2,
NOTE_E3, NOTE_E4, NOTE_DS4, NOTE_E4, NOTE_DS4,
NOTE_E4,NOTE_B3, NOTE_D4, NOTE_C4, NOTE_A3, Figure 4. Sensor circuit to design a keyboard feature
NOTE_E2, NOTE_A2, NOTE_C3, NOTE_E3, NOTE_A3,
NOTE_B3, NOTE_E2, NOTE_GS2,NOTE_E3, NOTE_C4, After successfully composing Fur Elise, we did some more
NOTE_B3, NOTE_A3 exploring. A diagram of the circuits for an interesting keyboard
is shown in Figure 4. We used this to design a more complex
};
project in order to build a larger instrumental ensemble
//The tone interval is defined as follows:: containing a string section and woodwind percussion
instruments. This project is still under development.
int IntTone[] = {
B. Using an HD44780 Compatible LCD module with an
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, Arduino microcontroller and Programming Environment
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
When a design requires visual output, there are several
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, different options available: color LCDs, monochrome LCDs,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, and individual LEDs. Each of these options has distinct
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,4,4,1 advantages over the others. LEDs are the simplest to
implement, but convey only limited information. Color LCDs
}; are capable of displaying a great deal of information, but are
the most difficult to implement, in addition to being the most
void setup()
expensive. A good compromise between the two is the
{ monochrome LCD. The most common controller chip used on
monochrome LCD modules is the Hitachi HD44780. Figure 5
//void setup is used to define the pins that will be used or to shows a photograph of the HD4478 and a pin diagram.
define the set variables
The HD44780 is a chip which receives information from a
for (int NumNote = 0; NumNote < 127; NumfNote++) microcontroller, and then uses that information to display
{ characters on the LCD by turning individual pixels on and off.
LCDs are easily interfaced with the Arduino [4]. There are
int IntTone = 1000/IntTone[NumNote]; only two decisions to make: which digital I/O pins will be used
tone(8, ZaElizu[NumNote],IntTone); on the Arduino, and whether 8-bit addressing is necessary.
When connecting an LCD to the Arduino, any of the Arduino’s
//tone() generates a digital signal with a particular digital pins can be used, as long as the programming accounts
frequency and conducts it to the pins. It ends with the command for each pin used, as covered in Section C. There are two
notone(). Only one tone can be generated, chord can not be addressing modes for HD44780 controllers: 4-bit and 8-bit. In
produced. an 8-bit scheme, there will be a total of 10 I/O pins used,
whereas 4-bit addressing requires only 6. We used a 2x16 LCD

– 286 –
4thMediterranean Conference on Embedded Computing MECO – 2015 Budva, Montenegro

and a Keypad shield for Arduino Omega boards. A 2x16 LCD first detected echo is assumed to measure the range to the
is one which can display a total of two lines with up to 16 closest object. Robots then use this information to plan paths
characters per line. The Arduino LCD Keypad shield operates around obstacles and to prevent collisions. In sonar mapping, a
in 4-bit mode. This means it uses a total of 6-pins to control the collection of echoes acquired by performing a rotational scan
LCD display: pins 4, 5, 6, 7, 8, and 9. To control LCD data, it or from a sonar array is used to construct a map of the
uses pins 4, 5, 6, and 7, while the RS and Enable pin are environment. Similar to a radar display, a range dot is placed
controlled by pins 8 and 9. The shield is simply plugged into on the detected range, along the probing pulse direction. For
the Arduino main board with no soldering required. object recognition, a sequence of echoes or sonar maps is
processed to classify echo-producing structures composed of
one or more physical objects. When successful, this
information is useful for robot registration or landmark
navigation.
The project was implemented as follows: Firstly, students
were taught basic sonar principles. Secondly, they were taught
how to build Arduino, sensor, and LCD circuits for measuring
distance. Fourthly, a short experiment was conducted in order
to investigate the sensor's limitations.
The HC-SR04 ultrasonic ranging module designed for
embedded system projects is used as a sensor. It has a
resolution of 0.3 cm and a distance range from 2cm to 500cm.
It runs on a 5V DC supply with a standby current of less than
2mA. The module transmits an ultrasonic signal, picks up its
echo, measures the time elapsed between the two events and
outputs a waveform whose high time is modulated by the
measured time which is proportional to the distance.

Figure 5. Photograph and diagram of the HD4478

In this project students learned to use a LiquidCristal


library in order to manipulate an LCD screen. The
LiquidCristal library allows an Arduino board to control LCDs.
The result is shown in Figure 6 where the name of the course
(in Montenegrin) is displayed on the screen. Both the Arduino
development board and LCDs employing the Hitachi HD44780
controller chip, two low-cost and highly capable devices,
provide numerous possibilities for the creation of new
products.
Figure 7. Image of HC-SR04 ultrasound sensor (front and back side)

The photograph of an HC-SR04 module is shown in Fig. 7.


The module is about 45x20x15 mm in size and has a 4-pin
connection. Two pins are needed to power the module with 5
volts. The working current is about 15 mA. One pin is the
trigger ping and the other pin, the echo pin, is used to read the
result of the measurements. The measuring angle from the HC-
SR04 is 15 degrees. One ping of the HC0SR04 actually
consists of 8 pulses at 40 kHz. In order to start a ping we need
Figure 6. The name of the course (Basic Measurement in Physics), is
displayed on the LCD screen, in Montenegrin.
to provide a 10ȝS pulse on the trigger input. When the distance
is measured by the 8 pulses, the HC0SR04 puts a pulse on the
C. Ultrasound sensors and measuring distance echo pin. The distance is calculated using the length of the
echo pulse and the speed of sound. The speed of sound is 340
Sonars use acoustic energy at higher frequencies than m/s or 2.9 micro seconds per mm. The length of the pulse is
normal human hearing in order to extract information from the then divided by 2.9 to get the result (distance) in mm. The ping
environment. There are three different, but related purposes of travels towards an object and back to the sensor again.
the sonar in robotics: 1) obstacle avoidance, 2) sonar mapping Therefore, we need to divide the result by two. Between the
and 3) object recognition. In the case of obstacle avoidance the two pings we need to keep a 50ms measurement cycle. The

– 287 –
4thMediterranean Conference on Embedded Computing MECO – 2015 Budva, Montenegro

connection of the HC-SR04 to an Arduino microcontroller is HD44780 (or a compatible) chipset, which is found on most
completed as follows: The sensor module’s 5V and Ground text-based LCDs.
pins are connected to the Arduino pins. In this example, the
module’s trigger and echo pins are connected to pin 52 and pin The Arduino code is used as follows:
53 of the Arduino, respectively. #include <LiquidCrystal.h>
This command activates the library which contains
commands connected to the LCD[4]. The active pins for the
LCD are defined as follows:
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int t2,t1,i,j;
//Trig i Echo pins are defined and declared.
const int trigPin=52, echoPin=53;
void setup()
{
Figure 8. Arduino with ultrasound sensor for distance measurements
//initialize serial communication
Fig. 8 shows the hardware, while Fig. 9 shows ultrasonic
Serial.begin(9600);
module operation. The 10 ȝs High Level (5V) pulse is
generated by the microcontroller (Arduino) and then used by lcd.begin(16, 2);
the ultrasound sensor as a trigger signal. The ultrasound
module then automatically transmits eight 40 KHz ultrasonic lcd.clear();
burst. If an obstacle is located in front of the ultrasound sensor, //Configures the specified pin to behave either as an input
it will reflect the ultrasonic bursts. If a signal returns, the or an output
ECHO output of the sensor will be in HIGH state (5V) for the
time it takes to send and receive the ultrasonic bursts. Pulse pinMode(52,OUTPUT);
width ranges from about 150ȝs to 25ms; and if no obstacle is pinMode(53,INPUT);
detected, the width of the echo pulse will be approximately
38ms. From the timing chart, one can observe that the 40KHz }
pulse train is transmitted just after the 10uS triggering pulse //Trig pin is output because it sends the signal, while Echo
while the echo output follows somewhat later. The next is input since it receives the signal.
triggering pulse can be made only after the echo has faded
away. This time period is called the cycle period. As mentioned float length()
earlier, the cycle period for the HC-SR04 must not fall below
{
50ms. In order to visualize information, the LCD was plugged
into Arduino shield. float time, distance;
// The digitalWrite() sets the value of a digital output pin.
Possible values are HIGH or LOW. If the pin has been
configured as an OUTPUT with pinMode(), its voltage will be
set to the corresponding value: 5V (or 3.3V on 3.3V boards)
for HIGH, 0V (ground) for LOW. If the pin is configured as an
INPUT, digitalWrite() will enable (HIGH) or disable (LOW)
the internal pull-up on the input pin..
digitalWrite(trigPin,HIGH);
delay(1);
Figure 9. Ultrasonic Module Operation digitalWrite(trigPin,LOW);
// pulseIn() reads a pulse (either HIGH or LOW) on a pin.
When all the components were connected (HC-SR04
ultrasonic ranging module, LCD, wires, breadboard, the time=pulseIn(echoPin,HIGH);
Arduino) the next phase of the project was to program the
// Distance is calculated as one-half the product of
Arduino board via Arduino IDE (Integrated Development
traveling time and ultrasound speed. Speed of sound is 340m/s
Environment) software. A LiquidCristal library allows the
or 1/29.1 ms/cm.
Arduino board to control LCDs employing the Hitachi

– 288 –
4thMediterranean Conference on Embedded Computing MECO – 2015 Budva, Montenegro

distance=(time/2)/29.1; IV. CONCLUSION AND FUTURE WORK

return distance; This paper presents a new approach in teaching the Basic
Measurements in Physics course, where the design and
} architecture of embedded systems were used as an inspiration
void loop() for a lab-on-chip laboratory design. Various projects are
shown. The Arduino, combined with sensors, was shown to
{ have huge developmental potential and is a great source of
lcd.clear(); learning inspiration for students. Open source platform linked
to the digital media moves education away from using ICT to
float x; x=distance(); deliver and control instruction to an environment supporting
lcd.print(x); the learners’ own creation of knowledge as well as their
investigative and thinking processes. It changes the way ICT is
Serial.println(x); lcd.print(" cm"); used: from a means of transmitting information by
representation to a mechanism for generating knowledge,
delay(300);
moving from linear logic to non-linear, networked logic. The
} interplay of student-owned laboratories and embedded systems
is shown to have a powerful influence on students. When the
After the code was checked and further developed, we conventional method of teaching was used, students exhibited a
conducted a short experiment to investigate the sensor's lack of motivation to work intensely towards finding the
limitations. Here are the main obstacles we found: solution to a problem, and often struggled with misconceptions.
• The slow sound speed, relative to an optical sensor, On the other hand, moving to a student-owned lab, caused
reduces the sonar sensing rate. A new probing pulse significant improvement in their understanding of electronic
should be transmitted after all detectable echoes from circuits and scientific concepts. This was demonstrated mainly
the previous pulse have expired, otherwise a false by the considerable change we saw in the students’ attitude
reading can occur. toward independent, self-regulated and self-directed learning.
Furthermore student-owned labs support collaborative learning,
• The wide sonar beam causes poor directional which can be further amplified if learners are taught to think
resolution. about alternatives and to articulate their thoughts.
• Soft surfaces cause a signifiant uncertainties. ACKNOWLEDGMENT
• Multiple reflections cause artifacts (no objects exist but The work is part of the Basic Measurement in Physics
echo signal is received); course of Faculty of Science and Mathematics at the University
of Montenegro.
• Signal travel time and amplitude variations are caused
by inconsistencies in the sound speed due to REFERENCES
inhomogeneous of medium. This cause furthermore
uncertainties in echo time.
[1] P- Godfrey, R. Deakin Crick, and S. Huang, “Systems Thinking,
• Interference between sensors is very significant for Systems, Design and Learning Power in Engineering Education”,
International Journal of Engineering Education, Vol. 30, No. 1, pp. 112–
small sensor spacing and long distances. 127, 2014.
• Thermal fluctuations cause re-direction through echo [2] P. Blumenfeld, T. Kempler and J. Krajcik., “Motivation and cognitive
engagement in learning environments“. In R. K. Sawyer (Ed.),
refractions. This cause furthermore temporal variations Cambridge Handbook of the Learning Sciences (pp. 475-488).
in the echoes and variations in their amplitude. Cambridge: Cambridge University Press., 2006
Our findings lead to several more ideas. The variations in [3] C. Reas, and B. Fry, “Processing: A Programming, Handbook for Visual
Designers and Artista“, MIT Press, 2007. Software available at
echo amplitude that are caused by changes in environmental http://www.processing.org
conditions could be used for monitoring the changes in
[4] http://arduino.cc/
breathing patterns in people with breathing problems such as
[5] http://fritzing.org/media/uploads/publications/Fritzing-TEI09-final.pdf
sleep apnea. This serious disorder causes people to stop
[6] A.F Mondragon-Torres, J.W. Christman, “A comprehensive embedded
breathing several times during sleep. For that purpose, we systems design course and laboratory”, Microelectronic Systems
would like in future to determine the viability of an ultrasonic Education (MSE), 2013 IEEE International Conference, pp 56 – 59,
device for recording breathing activity, which makes no ISBN: 978-1-4799-0139-5
contact with, and is otherwise imperceptible by the subject. [7] David James Russell, “Introduction to embedded systems: using ANSI C
Based on a low-powered ultrasonic active source and and the Arduino development environment”, Publisher: San Rafael,
transducer, the device would measure frequency shifts Calif. (1537 Fourth Street, San Rafael, CA 94901 USA) : Morgan &
Claypool, 2010, ISBN- 9781608454990, 9781608454983
produced by the difference in velocity between the flow of
exhaled air and the ambient environment, i.e., the Doppler
effect.

– 289 –

You might also like