CD-ROM FOR THE 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. P Arduino™ developer environment (IDE) P Example program code for the learning package P VB.NET-programs | You can exchange your own programs with other users online. The example programs are subject to the Open-Source license GPL (General Public License).
| Arduino™ is subject to continuous further development. Updates can be downloaded free of charge from the website . 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.
more than 5 Volt (V) away from the experimenting PCB. PIf possible, do not connect the PCB to the PC directly, but via a hub. This usually includes an additional effective protection circuit. If something happens anyway, the hub, and not the PC, will usually be damaged. THE PARTS AND THEIR FUNCTION The parts of the learning packages are presented here and the respective functions are explained briefly.
A button has a similar function as a switch. You already know switches from switching light on and off in the apartment. When we push the rocker down, the light comes on. When we push it up, the light goes out again. A switch remains in its position. This is different for a button. When we push the button, the circuit is closed. It will only remain closed while we push the button. When we release it, it will open the circuit again and the light will go out.
The resistors of the E24 standard series are as follows: 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.
3.6 | Photo Transistor To determine brightness, modern electronics often use photo transistors. The learning package includes a part that looks very similar to a white light emitting diode, except that it is a photo transistor. It not only looks different from the normal bipolar transistors but also has no base connection. The base, i.e. the input of a normal transistor that is responsible for the current control between the collector and emitter is the light falling into the housing in a photo transistor.
Info If you are working with Arduino™ for the first time, you need to download the Arduino™ developer environment first. You can find it on the official Arduino™-websitehttp://www.arduino.cc. Here, you can select your operating system and determine if you want to use the installer or the Zip-version. In the installer version, you install Arduino™ like a normal standard program. In the Zip-version, you need no installation. Unzip the Zip file and save it in a desired storage site on your computer.
018 019 020 021 022 023 024 025 lcd.print("CNT:"); } void loop() { lcd.setCursor(5, 1); lcd.print(millis() / 1000); } 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 Arduino™-folder, under Arduino\libraries\LiquidCrystal, and check out the LiquidCrystal.h and LiquidCrystal.
001 lcd.begin(16, 2) The basic initialisation is now completed. Now we can use lcd.setCursor to determine the position of the cursor and thus the text to be output. 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. 001 lcd.
002 lcd.print(millis() / 1000) Since the function millis() is very interesting, we will try another experiment before dealing with the LC-display in more detail, since the function millis() can also be used to measure time of program runs, as shown in the following example . Example code: TIME_DIFF 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 // Integrating LCD-Library #include
new program run and subtract the last counter reading that was saved at the end of the program. The delay(100) at the end of the program simulates a longer program runtime. Your program code must be between // My program start and // My program end , to determine the throughput time of your program code. The first experiments and thus also the function test have hereby been completed successfully. Leave the circuit set up as it is. You will need it and expand it in the following experiments.
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.
read with and without lighting. This makes them unlit, but a little dimmer than a reflective version. Nevertheless, it is probably the best compromise for lit LCDs. Transmissive displays have no reflector at all. They can only be read with lighting but are very bright. The LCD in the learning package is a transflective LCD. 5.5 | The Controller of the LC-Display Dot-matrix-displays are produced by many manufacturers around the world (and particularly in Taiwan).
a very low scatter of the electrical properties by now, the technology used in the learning package can also be used with a single fixed resistor. For this, we use a 2.2-kΩ-resistor that is placed between the ground and the contrast connection Vee of the LCD to firmly set the contrast. When using a potentiometer without ballast, the adjustable range that affects the contrast is very low, however.
figure sequence marks that this is a sequence of numbers in binary annotation. The upper and lower 4 bits for the Omega character are made up as follows: 001 upper 002 lower = = 1111 0100 Try outputting other characters as well, checking the , character table. Upload The experiment requires the LCD basic wiring that you set up in the function test.
first looking at the associated data sheet to avoid damage to the LCD . LCD-modules with lighting always require a little care. Some manufacturers do not apply the LED backlighting contacts to pins 15 and 16, but to pins 1 and 2. Again, check the manufacturer's data sheet before connecting the LCD. Info The LCD of the learning package has the LED-connections on pin 15 (+ = anode) and 16 (- = cathode). If you have no data sheet at hand for the LCDs, e.g.
pins (D0 to D7) and connect them to the Arduino™-PCB.
only positions the cursor in the upper left corner. No characters are deleted. .home() 001 lcd.home() sets the cursor to the specified position. As so often in informatics, this count starts at zero. The upper left position, i.e. the first character in row 1, is as follows: .setCursor() 001 lcd.setCursor(0, 0) The first parameter is the character position, the second parameter is the row. 6.6 | .write() .write() writes a single character onto the LCD.
this, there is a number of formatting parameters (BASE), that are indicated as second parameter. Arduino™-Syntax 001 002 003 004 005 006 lcd.print(data, BASE) lcd.print("Arduino") // only a text is output int variable1 = 100 lcd.print(variable1) // the value of "Variable 1" is output 007 008 lcd.print(40 + 2) // the total of 40 + 2 is output 009 010 lcd.print(3.1415, 2) // only 3.14 is output 011 012 lcd.print(42, BIN) // 42 is output in binary 6.8 | .cursor() .cursor() switches on the cursor.
6.11 | .noBlink() .noBlink() switches Arduino™-Syntax off the cursor and ends flashing. 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 last values are restored. Arduino™-Syntax .display() 001 lcd.display() 6.14 | .scrollDisplayLeft() .
001 lcd.scrollDisplayRight() 6.16 | .autoscroll() automatically scrolls the display content from the 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 .autoscroll() 001 lcd.autoscroll() 6.17 | .noAutoscroll() ends the Arduino™-Syntax .noAutoscroll() .autoscroll()-function. 001 lcd.noAutoscroll() 6.18 | .leftToRight() specifies the output direction of the characters.
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.
007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 #define Backlight 9 int i; void setup() { analogWrite(Backlight, 200); lcd.begin(16, 2); lcd.setCursor(0, 0); lcd.print("ARDUINO LCD”); delay(1000); lcd.clear(); } void loop() { // Cursor flashing and position change lcd.clear(); lcd.setCursor(0, 0); lcd.print("blink/setCursor"); delay(1000); lcd.clear(); lcd.
055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 } char txt[6] = {"HALLO"}; for(i = 0; i < 5; i++) { lcd.print(txt[i]); delay(500); } lcd.noCursor(); delay(2000); // Scroll LCD lcd.clear(); lcd.noBlink(); lcd.setCursor(0, 0); lcd.print("scroll LCD"); delay(1000); lcd.setCursor(0, 0); for(i = 0; i < 16; i++) { lcd.scrollDisplayLeft(); lcd.setCursor(0, 0); lcd.
Advice For more on the subject of preprocessors, see: http://www.mikrocontroller.net/articles/C-Pr%C3%A4prozesso r The following program point offers an option for outputting characters individually as if on an old typewriter: 001 002 003 004 005 006 char txt[6] = {"HELLO"}; for(i = 0; i < 5; i++) { lcd.print(txt[i]); delay(500); } Here, an array with 6 characters is set up and preassigned with the string »HELLO« .
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.
DIMMING BACKLIGHT The following experiment shows how we can automatically set the LCD-lighting brighter or darker. By changing the PWM-value at pin D9, the brightness of the backlighting is adjusted gradually. If the PWM-value is chosen higher, the LED will be brighter. A lower value will dim the lighting. By changing the PWM-value, we will change the plus-pause ratio between activation and deactivation duration of the 5-V-signal at D9. The following figure illustrates this.
029 030 031 032 033 034 035 036 037 038 039 } if(flag==0)i++; if(flag==1)i--; if(i==255)flag=1; else if(i==0)flag=0; analogWrite(Backlight, i); previousMillis = currentMillis; } The experiment also shows how an automatic up/down counter with a limit can be put into practice. It is important that the variable named flag receives a defined starting value of 0. When starting the program, the variable i is counted up to 255 .
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.
008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 #define Backlight 9 int cnt, Second, Minute, Hour=0; int LED=13; void setup() { pinMode(LED, OUTPUT); analogWrite(Backlight, 200); lcd.begin(16, 2); // Time specification Second = 12; Minute = 0; Hour = 0; } void loop() { cnt++; if(cnt == 50)digitalWrite(LED, LOW); if(cnt == 100) { digitalWrite(LED, HIGH); lcd.
056 Hour++; 057 if(Hour == 24) 058 { 059 Hour = 0; 060 } 061 } 062 } 063 cnt = 0; 064 } 065 066 delay(10); 067 } If we were to output the counter readings one to one on the display, the counter readings below 10 would look strange because the leading zero would not be displayed. For the clock to have the familiar »00:00:00«- format, we need to check if the value is less than 10 before the output. 001 if(Second < 10) lcd.print("0") If the value is less than 10, a simple output would only display, e.g.
depends on the operating voltage and is indicated in the data sheet for the micro controller at Vcc x 0.7. 001 HIGH = 5V x 0,7 Before a HIGH level is recognised in the digital port, some time will pass. We measure it within the Do-while-loop using the variable C_time. C_time is approximately proportional to the capacity of the capacitor, i.e. when C_time is very large, the capacity to be measured is very large as well.
Example code: CAPA 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 // Integrating LCD-Library #include // Specifying LCD pins // RS, E, D4, D5, D6, D7 LiquidCrystal lcd(11, 10, 2, 3, 4, 5); #define Backlight 9 int messPort=12; float c_time=0.0; float kapazitaet=0.0; void setup() { analogWrite(Backlight,200); lcd.begin(16, 2); lcd.setCursor(0,0); lcd.
046 047 048 049 050 051 052 053 054 055 056 057 058 059 } { lcd.setCursor(0,1); lcd.print(kapazitaet); lcd.print("nF "); } else { lcd.setCursor(0,1); lcd.print(kapazitaet/1000); lcd.print("uF "); } delay(1000); 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.
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.
028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 } void loop() { lcd.clear(); lcd.setCursor(0, 0); lcd.print("PUSH BUTTON"); while(digitalRead(button)); { if(!digitalRead(button)) { delay(50); if(!digitalRead(button)); { lcd.clear(); lcd.setCursor(0, 0); lcd.print("YOUR LOTTERY NUMBERS"); lcd.setCursor(0, 1); for(i=0;i
you put your hand next to the aerial or if the aerial is placed near electrical devices. The result with different number series can only be seen when you push the reset button on the Arduino™-PCB and then have the numbers output. You can enter a fixed number instead of analogRead() once to see that the same number sequences will appear every time after the reset. BAR CHART DISPLAY Bar chart displays are often used in measuring technology. They are also called bar displays.
014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 B00000, B00000, B00000, B00000, B00000, B00000, B00000, B00000, }; byte MyChar1[8] = { B10000, B10000, B10000, B10000, B10000, B10000, B10000, B10000, }; byte MyChar2[8] = { B11000, B11000, B11000, B11000, B11000, B11000, B11000, B11000, }; byte MyChar3[8] = { B11100, B11100, B11100, B11100, B11100, B11100, B11100, B1
062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 B11110, B11110, B11110, B11110, }; byte MyChar5[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111, }; void draw_bargraph(byte percent) { byte i, c1, c2; lcd.setCursor(0, 0); lcd.print(percent); lcd.print("% "); lcd.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 lcd.createChar(0, lcd.createChar(1, lcd.createChar(2, lcd.createChar(3, lcd.createChar(4, lcd.createChar(5, MyChar0); MyChar1); MyChar2); MyChar3); MyChar4); MyChar5); lcd.begin(16, 2); } void loop() { double percent; if(flag == 0)value++; if(flag == 1)value--; if(value > 1024)flag=1; else if(value == 0)flag=0; percent = value / 1024.0 * 100.
use the Map()-function. This scales the input value percent, from 0 to 100 to the output value from 0 to 80. The variable percent then holds a value between 0 and 80, depending on the input value percent. Now we determine the value of percent by dividing the number of boxes to be filled entirely by 5, and write the result into the variable c1. The modulo operation % determines the rest or the partial filling. We will write this value into the variable c2.
010 for(i = 0; i < 16 – (c1 + (c2 ? 1 : 0)); ++i) 011 lcd.write(byte(0)) The loop deletes the superfluous characters from the LCD by determining how long the area that is not used is and overwriting it with spaces. A little know-how is needed for the bar chart display, but once it has been understood, it can be used easily in many applications. LIGHT METER – THE PHOTOMETER A photometer is a meter to determine the light density or light strength. It is used, e.g.
006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 LiquidCrystal lcd(11, 10, 2, 3, 4, 5); #define LCD_LENGHT 16.
054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 B11100, B11100, B11100, B11100, }; byte MyChar4[8] = { B11110, B11110, B11110, B11110, B11110, B11110, B11110, B11110, }; byte MyChar5[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111, }; int adc_AVG(byte channel) { total= total – readings[index]; readings[index] = analogRead(channel); total= tota
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 lcd.print("% "); lcd.setCursor(0, 1); percent = map(percent, 0, 100, 0, 80); c1 = percent / 5; c2 = percent % 5; for(i = 0; i < c1; ++i) lcd.write(byte(5)); lcd.write(c2); for(i = 0; i < 16 – (c1 + (c2 ? 1 : 0)); ++i) lcd.write(byte(0)); } void setup() { analogWrite(9,200); lcd.createChar(0, lcd.createChar(1, lcd.createChar(2, lcd.createChar(3, lcd.
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.
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 measurement. The defined threshold will only cause the alarm to be tripped if the current light value +/- exceeds or undercuts the threshold. 001 002 003 004 005 006 cnt++; if(cnt > 2000) { cnt = 0; value = analogRead(PHOTOTRANSITOR) } If the variable cnt is above 2,000, a new value will be read from the analogue input A0.
002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 #include // Specifying LCD pins // RS, E, D4, D5, D6, D7 LiquidCrystal lcd(11, 10, 2, 3, 4, 5); #define Backlight 9 int PHOTOTRANSITOR = 0; int cnt = 0; int value, Threshold; void setup() { analogWrite(Backlight, 200); lcd.begin(16, 2); lcd.setCursor(1, 0); lcd.
049 delay(5); 050 051 } DIGITAL VOLTMETER WITH BAR CHART DISPLAY AND USB INTERFACE 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.
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.
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. 001 crc = 170^highbyte^lowbyte 002 Serial.write(crc) Info The program also works without PC-program and can be used as a stand-alone volt meter.
031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 B10000, B10000, B10000, B10000, B10000, }; byte MyChar2[8] = { B11000, B11000, B11000, B11000, B11000, B11000, B11000, B11000, }; byte MyChar3[8] = { B11100, B11100, B11100, B11100, B11100, B11100, B11100, B11100, }; byte MyChar4[8] = { B11110, B11110, B11110, B11110, B11110, B11110, B11110, B11110, }; byte MyChar5[8]
079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 B11111, }; int adc_AVG(byte channel) { total= total – readings[index]; readings[index] = analogRead(channel); total= total + readings[index]; index = index + 1; if (index >= numReadings)index = 0; return total / numReadings; } void draw_bargraph(byte percent) { byte i, c1, c2; lcd.
127 void loop() 128 { 129 double percent; 130 float voltage; 131 byte highbyte, lowbyte, crc; 132 int adc_raw = adc_AVG(ADC_CHANNEL); 133 134 voltage = (5.0 / 1024.0) * adc_raw; 135 136 lcd.setCursor(0, 0); 137 lcd.print(voltage, 2); 138 lcd.print(" V "); 139 140 percent = voltage / 5.0 * 100.0; 141 draw_bargraph(percent); 142 143 Serial.flush(); 144 highbyte=adc_raw/256; 145 lowbyte=adc_raw%256; 146 Serial.write(highbyte); 147 Serial.write(lowbyte); 148 crc=170^highbyte^lowbyte; 149 Serial.
interface and coding. Without importing the Encoding Library, we will, e.g., be unable to evaluate any values exceeding 128, since we cannot switch the interface to UTF-8 format then. Our measured result would be wrong then! 001 Dim input_data(10) As Byte input_data(10) is used to set up an array that can take up up to 10 bytes. The received bytes from the serial interface will be filed in this later. 001 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.
is then available for other programs again, such as the Arduino™-IDE. If you want to transfer any program changes or other programs to your Arduino™-board, you need to terminate the program first or click Disconnect to release the interface again. 001 Private Sub SerialPort1_DataReceived(sender As Object , e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.
assembled again data_Word = ((HighByte * 256) + LowByte) voltage = data_Word * (5.0 / 1024.0) 040 041 042 043 044 045 046 047 048 049 050 051 052 053 ' RAW value conversion and display as voltage Label1.Text = Format(voltage, "0.00 V") End If End If Catch ex As Exception End Try End Sub In the function SerialPort1_DataReceived(), the most interesting part of the VB.NET-program will now follow. This function will be called every time data are received from the serial interface.
5 V / 1,024 = 0.00488 V = 4.88 mV If we were to raise the input voltage range to 30 V, the resolution would deteriorate five-fold ((30 V – 5 V) / 5 V = 5). We would »only« be working with a resolution of 0.0244 V = 24.4 mV anymore. Now we can determine the voltage divider for a measuring range up to 30 V. We already know that we want to expand the input range from 5 V to 30 V, which corresponds to factor 5. The measuring input for voltage measurements must not be too low-Ohmic and should be at least 100 kΩ.
Therefore, we should not go any higher than 100 kΩ with the input voltage divider to still get useful measuring results. For more precise results, you may perform the calculation for a loaded voltage divider and include the resistance of the ADC in R2. Also consider that the tolerance adds up in a serial circuit. If you are using two resistors with 5 % tolerance each for the circuit shown, the total tolerance is already at 10 %. The values of the E12-series have turned out to be ideal.
003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 // Specifying LCD pins // RS, E, D4, D5, D6, D7 LiquidCrystal lcd(11, 10, 2, 3, 4, 5); #define Backlight #define ADC_NTC 9 0 float temp_celsius, temp_fahrenheit; int ADC_raw; float Grad_to_Fahrenheit(float grad) { return (9.0 / 5.0) * grad + 32; } void setup() { analogWrite(Backlight, 200); lcd.begin(16, 2); lcd.
051 052 053 054 055 } Serial.print(temp_fahrenheit); Serial.println(" °F"); delay(1000); The resistance curve of the NTC is not precisely linear and needs to be adjusted by a calculation. 001 temp_celsius = (580.0 – ADC_raw) / 10 To receive the output not only in degrees Celsius, the value will be converted to Fahrenheit and displayed on the LCD. 001 float Grad_to_Fahrenheit(float grad) 002 { 003 return (9.0 / 5.
temperature value to the PC. The circuit remains the same, but the program is changed as follows: 001 002 003 004 005 006 007 Serial.flush() highbyte=ADC_raw/256 lowbyte=ADC_raw%256 Serial.write(highbyte) Serial.write(lowbyte) crc=170^highbyte^lowbyte Serial.write(crc) As you can see, we transfer the temperature value like the measured value of the voltage in the digital USB-Voltmeter. You can find the complete program on the enclosed CD-ROM. It is called »TEMP_PLOT“.
The experiment requires the LCD basic writing that you set up in the function test. 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 // Integrating LCD-Library #include // Specifying LCD pins // RS, E, D4, D5, D6, D7 LiquidCrystal lcd(11, 10, 2, 3, 4, 5); #define Backlight 9 byte Hour, Minute, Second; void setup() { Serial.
044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 } lcd.print(":"); } if(Minute < 60) { if(Minute < 10) lcd.print("0"); lcd.print(Minute); lcd.print(":"); } if(Second < 60) { if(Second < 10) lcd.print("0"); lcd.print(Second); } } Serial.flush(); delay(100); The basic structure of the program corresponds to that of the regular clock (RTC) that we have already learned about at the beginning of the learning package. This time, we receive no data in the VB.
The timer could also be set to 1,000 ms. It is also possible that the second output will jerk on the LCD now and then because the data overlap. It is better to set the update time a little faster or just to half, to make the output appear more fluent. In the VB.NET-timer function, a check is performed before the actual output for safety purposes to see whether the serial connection is opened. If this is the case, SerialPort1.Write() will be used to transfer the time data.
tres ASCII-Table Charac decima hexadecima binary ter l l Description Charac decima hexadecima binary ter l l NUL 000 000 00000000 Null Character SOH 001 001 00000001 Start of Header STX 002 002 00000010 Start of Text ETX 003 003 00000011 End of Text EOT 004 004 00000100 End of Transmission ENQ 005 005 00000101 Enquiry ACK 006 006 00000110 Acknowledgment BEL 007 007 00000111 Bell BS 008 008 00001000 Backspace HAT 009 009 00001001 Horizontal TAB
Charac decima hexadecima binary ter l l Description EM 025 019 00011001 End of Medium SUB 026 01A 00011010 Substitute ESC 027 01B 00011011 Escape FS 028 01C 00011100 File Separator GS 029 01D 00011101 Group Separator RS 030 01E 00011110 Request to Send, Record US 031 01F 00011111 Unit Separator SP 032 020 00100000 Space ! 033 021 00100001 Exclamation Mark « 034 022 00100010 Double Quote # 035 023 00100011 Number Sign $ 036 024 00100100 Dollar
Charac decima hexadecima binary ter l l Description 7 055 037 00110111 8 056 038 00111000 9 057 039 00111001 : 058 03A 00111010 Colon ; 059 03B 00111011 Semi-Colon < 060 03C 00111100 Less Than = 061 03D 00111101 Equal > 062 03E 00111110 Greater Than ? 063 03F 00111111 Question Mark @ 064 040 01000000 AT Symbol A 065 041 01000001 B 066 042 01000010 C 067 043 01000011 D 068 044 01000100 E 069 045 01000101 F 070 046 01000110 G 071
Charac decima hexadecima binary ter l l Description S 083 053 01010011 T 084 054 01010100 U 085 055 01010101 V 086 056 01010110 W 087 057 01010111 X 088 058 01011000 Y 089 059 01011001 Z 090 05A 01011010 [ 091 05B 01011011 Left opening Bracket \ 092 05C 01011100 Back Slash ] 093 05D 01011101 Right closing Bracket ^ 094 05E 01011110 Caret _ 095 05F 01011111 Underscore ` 096 060 01100000 a 097 061 01100001 b 098 062 01100010 c 099 0
Charac decima hexadecima binary ter l l Description o 111 06F 01101111 p 112 070 01110000 q 113 071 01110001 r 114 072 01110010 s 115 073 01110011 t 116 074 01110100 u 117 075 01110101 v 118 076 01110110 w 119 077 01110111 x 120 078 01111000 y 121 079 01111001 z 122 07A 01111010 { 123 07B 01111011 Left opening Brace | 124 07C 01111100 Vertical Bar } 125 07D 01111101 Right closing Brace ~ 126 07E 01111110 Tilde DEL 127 07F 01111111