001384145-an-01-en-LERNPAKET ARDUINO VERSTEHEN UND ANWENDEN
001384145-an-01-en-LERNPAKET ARDUINO VERSTEHEN UND ANWENDEN
001384145-an-01-en-LERNPAKET ARDUINO VERSTEHEN UND ANWENDEN
LEARNING PACKAGE
This learning package includes a CD-ROM that contains various
programs and examples. The CD-ROM will make it easier for you
to work with this book. The examples printed here are included
on the CD-ROM.
|
You can exchange your own programs with other users online. The
example programs are subject to the Open-Source license GPL
(General Public License). Therefore, you are entitled to modify,
publish and provide the programs to other users under the
conditions of the GPL, provided that you subject your programs
to the GPL as well.
CONTENT OF THE
LEARNING PACKAGE
The learning package includes all parts that you need for the
experiments. Please check the parts for completeness before
starting the experiments!
Note
The Arduino™-UNO-micro controller PCB is not included in the
delivery. Since this is a learning package targeted at the
advanced Arduino™ programmer, an Arduino™ UNO or MEGA should
already be present at the workplace. The boards are available
at low costs at Conrad Electronic, in the Franzis Shop or at
other online businesses.
Parts List
1 x breadboard Tiny, 1 x LCD 16 x 2 blue, 1 x pin strip 16 pins
for soldering in, 1 x button, 1 x NTC 472, 1 x photo tran-
sistor, 1 x 10 kΩ, 1 x 2.2 kΩ, 1 x 330 Ω, 14 x jumpers
The Arduino™ PCBs and the display are mainly secured against
errors, so that it is hardly possible to damage the PC. The
connections of the USB-socket are not insulated on the bottom
of the PCB. If you place the PCB onto a metal conductor, there
may be a higher current, which may damage the PC and the PCB.
There are buttons that close the circuit when actuated, and such
that open the circuit . Buttons that close a circuit are often
called »N. O.« (normally open) and those that open the circuit
»N. C.« (normally closed). The figure shows a button that is
enclosed with the learning package. It closes the circuit when
pushed and the current can then flow from contact 1 to 2. The
two other contacts each are connected with each other.
3.4 | Resistors
Resistors are needed to limit current and to set working points,
or as voltage dividers in electrical circuits. The unit for
electrical resistance is Ohm (Ω). The prefix Kilo (k, thousand)
or Mega (M, million) shortens the way of writing large re-
sistances.
1 kΩ = 1000 Ω
10 kΩ = 10,000 Ω
100 kΩ = 100,000 Ω
1 MΩ = 1,000,000 Ω
10 MΩ = 10,000,000 Ω
In circuit diagrams, the symbol Ω is usually left out and 1 kΩ
is shortened to 1 k. The value of the resistor is applied to the
resistor in the form of a colour code. Usually, there are three
coloured rings, and an additional fourth ring that indicates the
accuracy of the resistor. Metal film resistors have a tolerance
of only 1 %. This is indicated by a brown tolerance ring that
is a little wider than the other four colour rings. This is to
prevent mistakes for a normal value ring with the meaning »1«.
1.0 / 1.1 / 1.2 / 1.3 / 1.5 / 1.6 / 1.8 / 2.0 / 2.2 / 2.4 /
2.7 / 3.0 / 3.3 / 3.6 / 3.9 / 4.3 / 4.7 / 5.1 / 5.6 / 6.2 /
6.8 / 7.5 / 8.2 / 9.1
The colour code is read from the ring closer to the edge of the
resistor. The first two rings represent two digits, the third
ring the multiplier of the resistance value in Ohm. A fourth one
indicates the tolerance.
A resistor with the colour rings yellow, violet, brown and gold
has the value 470 Ω at a tolerance of 5 %. Try to identify the
resistors of the learning package right away.
Advice
Entering the search term »Resistance code calculator« online
will return many resistor colour code calculators, e.g.
un-
der http://www.ab-tools.com/de/software/resistancesrechner/
or http://www.dieelektronikerseite.de/Tools/resistancesrec
hner.htm.
3.7 | LC-Display
The main actor of this learning package is the blue-white LCD.
The learning package uses an LCD with two rows 16 columns with
5 x 8 dots each. These displays can now also be purchased
separately in any good electronics store or online store for a
few Euro. They are available in green, blue, amber, yellow and
a few special colours that are usually more expensive. In our
case, a blue LCD is installed. The LCD controller installed is
a KS0066/HD44780 that is produced by many manufacturers - more
on this later.
Before you can use the LCD in the experiments, you need to solder
the enclosed 16-pin pin strip into the contacts of the LCD. For
this, plug the pin strip with the short contacts into the LCD
from behind and solder only one contact on first. This way, you
can align the pin strip cleanly at a 90°-angle. When the pin strip
has been aligned, you can solder on the other pins. If you have
no soldering gun yet, get a cost-efficient hand-held soldering
gun with an output between 20 and 30 W and electric wire solder.
This investment will pay off when dealing with Arduino™ and
electronics in any case.
Attention
Only save Arduino where you have all rights to read, write,
etc.!
For the first function test, load the following program onto the
Arduino™-board. The example programs can all be found on the
enclosed CD in the Examples folder.
The program will make a text and a kind of counter appear on the
LCD and is well suitable as the first function test to check that
everything is working properly because it is very small and
well-structured.
Example code: LCD
In the first line of the program, you can see that operation of
the of the LCD requires integration of the Arduino™ Library with
the name LiquidCrystal.h. It includes the more complex code that
is needed to control the display. You can look in the Ar-
duino™-folder, under Arduino\libraries\LiquidCrystal, and
check out the LiquidCrystal.h and LiquidCrystal.cpp files to get
an idea of the function of the Library. To open these files, it
is recommended to use, e.g., the program Notepad++. You can
download it free of charge from
http://www.notepad-plus-plus.org.
You will see that this Library will do a lot of work for you that
other programmers have already completed. In our Ar-
duino™-program, we integrate only the header file with
LiquidCrystal.h. Arduino™ will now automatically know all LCD
functions.
In the next line, we inform Arduino™ which pins of the LCD are
connected to the Arduino™-PCB.
001 lcd.setCursor(0, 0)
The first parameter indicates the position within the row, i.e.
0 to 15 in this case. The second parameter indicates the row
number, i.e. 0 or 1.
Now we can output the text in the specified position at the LCD
with the commandlcd.print.
We can also see that we always need to write »lcd.« before the
actual function of the LCD output. This specifies that we use
the class lcd that we have integrated with #include <Liquid-
Crystal.h>. Now Arduino™ knows where the call comes from and
which class is responsible for it when »translating«, referred
to as »compiling« by specialists.
If you have ever dealt with the programming language C++ before,
you will recognise by the ending *.cpp, that these are
C++-classes. Arduino™ is basically based on C++. This is a good
way of programming own classes or Library and providing them to
other Arduino™ users.
After this brief C++-excursion, let us return to our example.
Up to now, we still remained in the function Setup()-which is gone
through once at all times when starting the program and that is
mostly used for start configuration. In it, we can pre-initialise
variables before the actual program start and pre-configure the
hardware.
The following Loop() function is an endless loop that is never
ended. This is the Arduino™-main loop for our program at the same
time. Here, we call the runtime in milliseconds at each run with
the function millis() . Division by 1,000 will lead to the output
in seconds. We will represent the program runtime in seconds on
the LCD.
001 lcd.setCursor(5, 1)
002 lcd.print(millis() / 1000)
|
Polarisation in LC-displays does not mean polarity of the voltage
supply, but the gas, liquid and filter structure of the display.
Most LCDs are TN-displays (Twisted-Nematic-displays). They contain
a liquid that turns the polarisation level of light by 90°. STNs
(Super-Twisted-Nematics) turn the polarisation level of light by
at least 180°. This improves the display's contrast. However, this
technique will lead to a certain colouration of the display. The
most common colourations are called yellow-green and blue mode. A
grey mode appears more blue than grey in practice. To compensate
for the undesired colour effect, FSTN-technology uses another foil
on the outside. The resulting light loss, however, makes this
technology only sensible for lit displays. The different colours
appear only in unlit or white-lit displays, however. Once the
lighting is coloured (e.g. LED-lighting yellow-green), the re-
spective display colour moves to the background. A blue-mode-LCD
with yellow-green LED-lighting will always look yellow-green.
001 lcd.write(B11110100)
If you have no data sheet at hand for the LCDs, e.g. if you have
purchased the LCD on an electronics flea market, you need to track
the tracks to find the backlighting connections. They are usually
a little thicker than the other tracks. When you are sure which
connections are responsible for lighting, you can use a mul-
timeter set to diode testing to determine polarity. The passage
duration must return a passage voltage between 2 and 4 V. Another
option would be to identify the LED-pins and polarity when making
the LED light up with a mains unit or a battery of approx. 5 V
and a relatively high ballast (approx. 1–4.7 kΩ). The high
ballast has a relatively small danger of destruction of the LCD.
THE ARDUINO™
LIQUITCRYSTAL LI-
BRARY
As we have already learned in the function test, the Arduino™
LiquidCrystal Library has a number of functions specifically
determined for output on the LCD. Now you will learn more about
the LCD functions.
.begin() initialises the LCD with the indicating rows and columns.
Our LCD has 2 rows and 16 columns. Parametrisation therefore
needs to be as follows:
001 lcd.begin(16, 2)
001 lcd.clear()
only positions the cursor in the upper left corner. No
.home()
characters are deleted.
001 lcd.home()
001 lcd.setCursor(0, 0)
6.6 | .write()
.write() writes a single character onto the LCD. This can be used
to output special characters from the character table as well,
or to indicate the ASCII-code for the character.
Arduino™-Syntax
001 lcd.write(64)
001 lcd.write('@')
6.7 | .print()
With .print(), we can output entire character sequences, called
Strings. It is also possible to output variables this way. For
this, there is a number of formatting parameters (BASE), that
are indicated as second parameter.
Arduino™-Syntax
6.8 | .cursor()
.cursor()
switches on the cursor. If the cursor has been off, it
is visible again now.
Arduino™-Syntax
001 lcd.cursor()
6.9 | .noCursor()
.noCursor() switches off the cursor (invisible).
Arduino™-Syntax
001 lcd.noCursor()
6.10 | .blink()
.blink()switches on the cursor and makes it flash.
Arduino™-Syntax
001 lcd.blink()
6.11 | .noBlink()
.noBlink()
switches off the cursor and ends flashing.
Arduino™-Syntax
001 lcd.noBlink()
6.12 | .noDisplay()
.noDisplay() switches off the display. The character and cursor
position are saved.
Arduino™-Syntax
001 lcd.noDisplay()
6.13 | .display()
switches on the LCD again after a .noDisplay(). The
.display()
last values are restored.
Arduino™-Syntax
001 lcd.display()
6.14 | .scrollDisplayLeft()
.scrollDisplayLeft() scrolls the screen content to the left by one
character every time it is called.
Arduino™-Syntax
001 lcd.scrollDisplayLeft()
6.15 | .scrollDisplayRight()
scrolls the screen content to the right by one
.scrollDisplayRight()
character every time it is called.
Arduino™-Syntax
001 lcd.scrollDisplayRight()
6.16 | .autoscroll()
automatically scrolls the display content from the
.autoscroll()
right to the left. When the end of the character string is
reached, the scroll direction is automatically switched. It is
pushed on 1 x (scrolled) at each call.
Arduino™-Syntax
001 lcd.autoscroll()
6.17 | .noAutoscroll()
ends the
.noAutoscroll() .autoscroll()-function.
Arduino™-Syntax
001 lcd.noAutoscroll()
6.18 | .leftToRight()
specifies the output direction of the characters.
.leftToRight()
They are written from the left to the right.
Arduino™-Syntax
001 lcd.leftToRight()
6.19 | .rightToLeft()
specifies the output direction of the characters.
.rightToLeft()
They are written from the right to the left.
Arduino™-Syntax
001 lcd.rightToLeft()
6.20 | .createChar()
.createChar() creates a dedicated character. For this, we need to
create an array with eight data fields, by defining our
character. lcd.createChar gives our character a serial number with
the first parameter. The Second parameter hands over the name
of the array. Up to eight own characters, which are called with
0 to 7 can be created.
Arduino™-Syntax
LCD FUNCTIONS
The following example summarises the LCD functions explained
above in a larger example. Look at the program code and change
a few of the parameters just described to fully understand the
function.
The experiment requires the LCD basic writing that you set up
in the function test.
CREATING OWN
CHARACTERS
Creating own characters as has already been described just now
using .createChar() is often needed when using dot-matrix LCDs,
since many characters needed in practice are not included in the
character table of the LCD. There is the option of creating own
characters dot by dot for this and displaying them then. If you
need, e.g., a smiley, you can define it via an array and send
it to the LCD.
There is the option of filing up to eight own characters in the
RAM (memory) of the LCD. The array for our special character must
be 8 bytes large and is best written as shown in the example code.
The character can, e.g., be designed on a checked drawing pad.
You can see that it is made up of 8 rows at 5 values each, which
reflect our 5 x 8 dots in the LCD. Where we set a 1 in the binary
code, a white dot will appear later. With lcd.write(byte(0)), we
write the character onto the LCD.
The example makes the entire thing even clearer. Try to produce
a battery symbol or a thermometer.
The experiment requires the LCD basic writing that you set up
in the function test.
The experiment requires the LCD basic writing that you set up
in the function test.
DOT-MATRIX-LCD
CLOCK
In many applications, a clock is needed for program control -
either a simple timer, a control to comply with a precise
schedule, or an operating hours counter. The applications that
need a clock are diverse.
The experiment shows how to program a very simple clock yourself.
The program runs in the Loop()-function, is finite and counts up
at a cycle of 10-ms. If the counter reading cnt = 100, the time
is output. This is done every second. Our user LED L will flash
every second as well. We monitor the function of the program to
ensure that it is still running and to see if an error occurred
in programming. However, note that the clock does not have the
precision of an actual quartz clock since the cycle and the
deviation of the micro controller quartz at 16 MHz is much higher
than in a clock quartz in the Kilohertz range (clock quartz =
32.768 kHz). Deviations of more than one minute per day are not
rare. The accuracy also strongly depends on ambience temperature.
If it fluctuates strongly over time, the clock will also have a
higher time error. We can correct the time deviation with delay ().
Alternatively, we can also use delayMicroseconds() to correct the
deviation even better. For this, configure a digital pin as the
output and toggle it at every program run , change the condition
once at every run. This signal can be trimmed precisely to a
throughput time of 10 ms with an oscilloscope. You can determine
the deviation across an extended period by comparing the time to
a different, precise clock, e.g. a DCF-clock for a while (1 to 2
days), calculating the difference and then correcting the de-
viation with delayMicroseconds().
001 Second = 12
002 Minute = 0
003 Hour = 0
Advice
For more on the subject of clock quartz,
see: http://de.wikipedia.org/wiki/Uhrenquarz
The experiment requires the LCD basic writing that you set up
in the function test.
If the value is less than 10, a simple output would only display,
e.g. »12:1:8«. However, we check if the value is less and add
a »0« manually if necessary to fill the tens.
CAPACITY METER
Building your own meters with the simplest of media is always
interesting and exciting. Arduino™ permits programming a ca-
pacity meter for small capacitors in the range of 1 nF to approx.
100 µF for our hobby lab at very low costs and effort. This is
how our capacity meter with auto range function works:
At commencement of the measurement, the variable C_time is
initialised with zero. Port D12 is configured as an output and
then immediately switched to LOW (GND), to discharge the
connected capacitor (test piece) before the actual measurement.
After a brief end charging pause of 1 second, port D12 will be
configured as input and the internal pull-up-resistance will be
activated. The pull-up-resistance will now charge the capacitor
to be tested until the port D12 recognises HIGH. The threshold
from when onwards the digital port recognises HIGH is at approx.
3.5 V at an operating voltage of 5 V. This level therefore
depends on the operating voltage and is indicated in the data
sheet for the micro controller at Vcc x 0.7.
RANDOM NUMBERS –
THE LOTTERY RESULTS
GENERATOR
When writing measuring, control, regulating or playing programs,
it is often of benefit to generate random numbers, e.g. when
lights are to go on and off at different times in a house to
program a presence simulator. For this purpose, the Ar-
duino™-random()-function can be used. This permits a simple
lottery number generator that will draw 6 out of 49 for you. You
will no longer have to think about which numbers you are supposed
to take when you complete your lottery slip.
For the setup of the lottery number generator, you need a button
and an aerial. The button is debounced in the software. The button
and switch tend not to close the contact 100 % at once but to
trigger several times after being pushed. This is comparable to
tossing a ball to the floor. It will bounce a few times before
finally resting on the ground. This happens much faster in a
button, but the Arduino™-micro controller is so fast that it will
still record these millisecond »hops«. To avoid this, the button
is debounced by being queried twice in sequence with a break of
50 ms, which is enough for a debouncing routine in practice . Only
if the second evaluation still recognises a LOW at input D7 will
the instruction between the brackets be executed.
At commencement of the program, we switch the port D7 to INPUT
and activate the internal pull-up-resistance, by
ing digitalWrite() to write a 1 for HIGH on the input. Now a voltage
of approx. 5 V is pending at the input in the resting condition.
Now you can pull the input against GND (ground) with the button.
This pull-up-resistance is integrated in the microcontroller and
has a value of approx. 20 to 50 kΩ. Regarding function, it is
the same as if applying an external resistor from input D7 to
+5 V. In the resting condition, the program will therefore always
recognise a HIGH at input D7 and a LOW when the button is pushed.
Therefore, the button query is applied with a question mark in
the program. This is called the NOT-operator in C-programming.
Since it is known that an If()-query checks for TRUE , everything
else will be interpreted as FALSE . If the If()-query has been
performed without this operator, the condition would always be
TRUE. It would then already be performed before the button had
even been pushed. The NOT-operator inverts the status of the
button. 1 turns into 0 and 0 turns into 1 and the If()-query is
now only TRUE if the button has actually been pushed.
The experiment requires the LCD basic writing that you set up
in the function test.
001 if(condition)
002 {
003 // Expression1
004 }
005 else
006 {
007 // Expression2
008 }
009
010 for(i = 0; i < 16 – (c1 + (c2 ? 1 : 0)); ++i)
011 lcd.write(byte(0))
When you have set up the circuit and transferred the example code
to the Arduino™-board, a value near 100 % will be displayed on
the LCD in bright environments, and the bar of the bar chart will
fill the lower row of the LCD almost completely.
If you darken the photo transistor now, the value will reduce
to near zero. Look at the circuit more precisely. The photo
transistor is connected to the 10-kΩ-resistance at the col-
lector, which is connected to +5 V, and to GND (ground) at the
emitter. The analogue input 0 of the Arduino™-PCB is connected
to the node point of the collector and the resistor. If the photo
transistor is now exposed to light, it will become conductive,
and the voltage drop between collector and emitter will reduce.
We are measuring a very low voltage. When the photo transistor
is darkened, barely any current will flow, the photo transistor
will lock and the collector-emitter voltage will increase. Now
we measure almost the entire 5 V.
Between the two extremes, the photo transistor will be very
dynamic and react even to the smallest light fluctuations. Since
the display would work precisely inverted this way - very bright
would be a low value and dark a very high one - we need to adjust
the measured value. For this, we subtract the measured value from
100 %, to get the desired result. We invert our analogue measured
value.
To keep the bar chart display from »twitching“ too much at
smallest light changes, the bar charge display function had an
average formation added. It smoothens out the analogue measured
values and calculates a sliding average, called AVG for Average,
from it .
For this, the current measured value is added to an array at each
run and, depending on how high the counter reading in this function
is at the moment, divided by it. This will continually return the
current average. The number of measuring series for average
formation is specified in the variable numReadings-. The higher the
number of the values to be averaged, the more precise, but also
the more idle the display. You can experiment with the values here.
Values between 8 and 64 have proven to be sensible. At the end of
the AVG-function, the input value (0 to 1,023) is then calculated
for a percentage for the bar chart function.
This kind of photometer can also be reprogrammed to automatically
activate and deactivate lighting or, as the next experiment
shows, be turned into an alarm system.
ALARM SYSTEM
The photometer can also be used as an alarm system that will react
to the smallest light changes. At the beginning of the alarm
system program, the current light intensity at the analogue input
A0 that is used as the reference point for the measurement will
be determined . If the voltage value in the continuous meas-
urement increases or reduces due to a light change (e.g. a person
walking past), and if this exceeds or undercuts the specified
threshold, the alarm will trigger.
Since brightness in a room will change over the course of the
day, a new reference value (current voltage of the photometer)
will be determined automatically every 10 seconds to be used as
the new reference point for continuous measurements.
We therefore compare a fixed light value that is measured anew
every 10 seconds to the light value of the continuous meas-
urement. The defined threshold will only cause the alarm to be
tripped if the current light value +/- exceeds or undercuts the
threshold.
001 cnt++;
002 if(cnt > 2000)
003 {
004 cnt = 0;
005 value = analogRead(PHOTOTRANSITOR)
006 }
If the variable cnt is above 2,000, a new value will be read from
the analogue input A0. An inserted pause that influences the
program run speed will only increment the variable cnt by 1 every
5 ms. This leads to a value of 5 ms x 2,000 = 10,000 ms = 10
seconds.
001 Threshold = 25
002 if(analogRead(PHOTOTRANSITOR) > (value + Threshold) ||
analogRead(PHOTOTRANSITOR) < (value – Threshold))
DIGITAL VOLTMETER
WITH BAR CHART DIS-
PLAY AND USB INTER-
FACE
With what you have learned so far, you can now program a digital
Voltmeter with analogue bar chart display. The bar chart display
will be valuable for setting work. You can see much more precisely
where, e.g., the maximum or minimum is, on an analogue display
than on a digital display with pure numeric output. As a special
feature, we supplement the program with a serial output that will
send your measured data to the PC via the USB interface. Here,
we use the USB- interface already present on the Ar-
duino™-UNO-board that we are already using for programming.
Resistors R1 and R2 are not needed in this experiment and are
not enclosed with the learning package! They will, however, be
further explained in this chapter. If you need them, you can
purchase them in a specialist electronics store later.
You can use the circuit to measure very precise voltages between
0 and 5 V using the analogue input A0 without the two resistors
R1/R2. However, ensure that you do not connect any higher
voltages to the connection, since the Arduino™-board would be
damaged by this. You may already measure the voltage of one or
two Mignon cells (AA) or Micro cells (AAA) extremely precisely
with the circuit. The example is very similar to that of the
photometer, but with a few different details. This time, we also
use the serial interface (UART = Universal Asynchronous Receiver
Transmitter) of the Arduino™-micro controller. The measured data
are sent through the serial interface of the micro controller
(UART) to the UART-to-USB-converter on the Arduino™-PCB , which
passes it on to the PC. The serial connections D0/RX and D1/TX
are already firmly connected to the converter and no further
wiring work is required for this. On the PC-side, a virtual
Comport is produced when installing the Arduino™-PCB. This is
already used for programming. Now, we can also simply use it to
transfer data to the PC. For this, we only need to initialise
the UART interface in the program. This is configured
with Serial.begin(). The parameter 19200 between the brackets
represents the transfer speed. Initialisation only needs to be
executed once at program start in the Setup()-function.
001 Serial.begin(19200)
Baud is the unit for the symbol rate in message and telecom-
munications technology. 19200 Baud means , that 19,200 symbols
per second will be transferred. The symbol rate can contain
different numbers of bits depending on coding and must be set
equally on the transmitter and receiver sides to permit
transmission.
The following lines are now used to send the measured result of
the ADC (0 to 1013) to the PC directly without prior conversion.
Conversion to Volt takes place in the PC-program, since we only
need to send two individual bytes to the PC this way, which are
much easier to evaluate than a string (ASCII-character string).
Now the buffer of the UART-interface will be emptied with flush.
001 Serial.flush()
Now we will take apart the analogue measured value, which ranges
from 0 to 1023, into a high and a low byte. We will get the high
byte by dividing the measured value by 256.
We will get the low byte with the modulo operation 256.
Then we will send first the high byte and then the low byte to
the PC.
001 Serial.write(highbyte)
002 Serial.write(lowbyte)
To check that the values have been transferred correctly, we can
see a checksum at the end of the transfer that is made up of a
fixed number and the XOR-formation of this, as well as the two
bytes.
Info
The program also works without PC-program and can be used as
a stand-alone volt meter.
To start the PC-program, you only need to execute the EXE file
in the folder ...\VOLTMETER\vb.net\bin\Release. Then choose the
Comport, which is identical to the one you have already set in
the Arduino™-IDE for the program transfer. If you click Connect
now, the voltage in the PC-program will be displayed.
The VB.NET-program is enclosed as source code and can be used
as a basis for your own experiments. For this, you need to
download the free Visual-Basic-Express-Version by Microsoft.
You can find it
athttps://www.visualstudio.com/downloads/download-visual-stu
dio-vs. When you have opened the program with Visual Basic, you
will see the source code and the designer before you. The designer
displays the visual control elements such as buttons, texts
fields, etc. Now have a look at the source code of the Voltmeter
program by switching to source code view.
Here, we specify the Comport, the Baud rate and the Encoding,
and open the interface with SerialPort1.Open(), which will then be
ready to transfer and receive.
TEMPERATURE DISPLAY
IN DEGREES CELSIUS
AND FAHRENHEIT
This experiment shows how you can use a cost-efficient temperature
resistor like the NTC (Negative Temperature Coefficient Ther-
mistor) used here to program a simple LCD-thermometer.
An NTC is a resistor that changes its resistance depending on
its temperature. The NTC is called a hot conductor. This means
that its resistance reduces when the temperature increases.
The circuit diagram shows the setup in more detail. This is
another variable voltage divider, consisting of a 10-kΩ-fixed
resistor and the variable NTC-resistor. As the temperature
drops, the resistance of the NTC increases and so does the voltage
at the analogue input A0.
The resistance curve of the NTC is not precisely linear and needs
to be adjusted by a calculation.
To receive the output not only in degrees Celsius, the value will
be converted to Fahrenheit and displayed on the LCD.
TEMPERATURE PLOT-
TER WITH
USB-INTERFACE
Let us expand the thermometer with a VB.NET-program and change
the program code so that the plain text output as in the
predecessor program will be replaced by sending only the
temperature value to the PC. The circuit remains the same, but
the program is changed as follows:
001 Serial.flush()
002 highbyte=ADC_raw/256
003 lowbyte=ADC_raw%256
004 Serial.write(highbyte)
005 Serial.write(lowbyte)
006 crc=170^highbyte^lowbyte
007 Serial.write(crc)
WEBSYNCHRONOUS
CLOCK
We have already programmed a clock in this learning package.
Since it is not very precise and subject to a very large deviation
in the course of the operating time, we now program a
web-synchronous clock, knowing about the serial transmission
between PC and Arduino™. It is websynchronous, because the
Windows time is by default automatically reconciled with an
online time server in the background. In this VB.NET-program,
we will now send the time of the PC to Arduino™ and output it
on the LCD. The VB.NET-program is enclosed as an executable EXE
file and as source code.
The experiment requires the LCD basic writing that you set up
in the function test.
ANNEX
We distinguish between voltage, current, resistance and the
units in which the values are measured (e.g. Volt or Ampere).
Every unit has an abbreviation that is used in the formulas. The
abbreviations permit a short and well-structured annotation.
Instead of current equal 1 Ampere we write only I = 1 A.
These abbreviations are used in all formulas in his book.
Voltage U Volt V
Current I Ampere A
Resistance R Ohm Ω
Power P Watt W
Frequency f Hertz Hz
Time t Second s
Inductiveness L Henry H
Capacity C Farad F
ASCII-Table
PROCUREMENT
SOURCES