{"id":1058,"date":"2017-03-16T20:10:20","date_gmt":"2017-03-16T19:10:20","guid":{"rendered":"https:\/\/pa3csg.nl\/?page_id=1058"},"modified":"2019-05-08T08:27:45","modified_gmt":"2019-05-08T06:27:45","slug":"arduino-temperature-meter-for-solid-state-pa","status":"publish","type":"page","link":"https:\/\/pa3csg.nl\/?page_id=1058","title":{"rendered":"Arduino temperature meter for solid state PA"},"content":{"rendered":"<p>For my 23cm PA consisting of 4 PA&#8217;s I needed a temperature meter with protection in case the amplifier gets hot. The system is build on the same board as the power meter. The full scale temperature can be set with a push button.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-1059\" src=\"https:\/\/pa3csg.nl\/wp-content\/uploads\/2017\/03\/DSC_5657-300x151.jpg\" alt=\"DSC_5657\" width=\"781\" height=\"393\" \/><\/p>\n<p>The code derived from the power \/ swr meter.<\/p>\n<p>\/*<br \/>\nTemperature meter based on the powermeter swrmeter board, connections for<br \/>\npushbuttons leds etc. remain the same as on the original board<br \/>\nPA3CSG march 2017 V1.0<br \/>\nCode comes without any warranty.<\/p>\n<p>***********************CHANGELOG****************************************<\/p>\n<p>************************************************************************<br \/>\n*\/<\/p>\n<p>\/\/ include the library code:<br \/>\n#include &lt;LiquidCrystal.h&gt;<br \/>\n#include &lt;EEPROM.h&gt;<br \/>\n#include &lt;LcdBarGraph.h&gt;<\/p>\n<p>\/\/ initialize the library with the numbers of the interface pins<br \/>\nLiquidCrystal lcd(12, 11, 5, 4, 3, 2);<br \/>\n\/\/ &#8212; creating bargraph instance, format is (&amp;lcd, lcdNumCols, start X, start Y). So (&amp;lcd, 16, 0, 1) would set the bargraph length to 16 columns and start the bargraph at column 0 on row 1.<br \/>\nLcdBarGraph lbg0(&amp;lcd, 20, 0, 1);<br \/>\nLcdBarGraph lbg1(&amp;lcd, 20, 0, 3);<\/p>\n<p>\/\/ variables for input pin and control LED<br \/>\n\/\/variables for the power meter<br \/>\n\/\/ For the AD converters<\/p>\n<p>int analogInputTEMP1 = 0; \/\/input 1st LM35 sensor on pin A0<br \/>\nint analogInputTEMP2 = 1; \/\/input 2nd LM35 sensor on pin A1<br \/>\n\/\/For the alarms<br \/>\nint alarmtemp1 = 7; \/\/Temp1 alarm on pin 7<br \/>\nint alarmtemp2 = 1; \/\/Temp2 alarm on pin 1<br \/>\n\/\/float variables<\/p>\n<p>float TEMP1 = 0.0;<br \/>\nfloat TEMP2 = 0.0;<br \/>\n\/\/ variable to store the value<br \/>\nint counterTemp = EEPROM.read(0);<br \/>\nint counteroldTemp = counterTemp;<br \/>\nint counterMode = 0;<br \/>\nint counteroldMode = counterMode;<br \/>\n\/\/int updater = 0;<br \/>\nint incrementStateTemp = 0; \/\/will read increment for Power button<br \/>\nint lastIncrementStateTemp = 0;<br \/>\nint incrementStateMode = 0; \/\/will read increment for Mode button<br \/>\nint lastIncrementStateMode = 0;<br \/>\nbyte incrementButtonTemp = 8; \/\/ the pin that the pushbutton for the power selection is attached to<br \/>\nbyte incrementButtonMode = 13; \/\/ the pin that the pushbutton for the power selection is attached to<br \/>\nvoid setup() {<\/p>\n<p>\/\/ declaration of pin modes<br \/>\nanalogReference(EXTERNAL); \/\/sets reference to external connected reference 2,5V LT1009 reference<\/p>\n<p>\/\/ For the AD converters<br \/>\npinMode (analogInputTEMP1, INPUT); \/\/input from LM35<br \/>\npinMode (analogInputTEMP2, INPUT); \/\/input from LM35<br \/>\n\/\/For the pussh buttons<br \/>\npinMode(incrementButtonTemp, INPUT); \/\/ initialize the button pin for the Pwr switch as an input:<br \/>\npinMode(incrementButtonMode, INPUT); \/\/ initialize the button pin for the Mode switch as an input:<\/p>\n<p>\/\/for the leds outputs<br \/>\npinMode (alarmtemp1, OUTPUT); \/\/Temp warning on pin 7<br \/>\npinMode (alarmtemp2, OUTPUT); \/\/Temp alarm on pin 1<\/p>\n<p>\/\/setup alarms<br \/>\ndigitalWrite(alarmtemp1, LOW);<br \/>\ndigitalWrite(alarmtemp2, LOW);<\/p>\n<p>\/\/ set up the LCD&#8217;s number of columns and rows:<br \/>\nlcd.begin(20, 4);<\/p>\n<p>\/\/ A little bit of PR<br \/>\nlcd.setCursor(0, 0);<br \/>\nlcd.print(&#8221; TEMPERATURE METER&#8221;);<br \/>\nlcd.setCursor(7, 1);<br \/>\nlcd.print(&#8220;PA3CSG&#8221;);<br \/>\nlcd.setCursor(6, 2);<br \/>\nlcd.print(&#8220;Welcome&#8221;);<br \/>\nlcd.setCursor(5, 3);<br \/>\nlcd.print(&#8220;Have fun!&#8221;);<br \/>\ndelay(1500);<br \/>\nlcd.clear();<\/p>\n<p>\/\/print things on the lcd that donnot change anymore<\/p>\n<p>\/\/first line<br \/>\nlcd.setCursor(0, 0);<br \/>\nlcd.print(&#8220;AMP3=&#8221;);<br \/>\nlcd.setCursor(8, 0);<br \/>\nlcd.print((char)223);<br \/>\nlcd.print(&#8220;C&#8221;);<br \/>\nlcd.setCursor(12, 0);<br \/>\nlcd.print(&#8220;FS= &#8220;);<br \/>\n\/\/second line is bargraph<\/p>\n<p>\/\/third line<\/p>\n<p>lcd.setCursor(0, 2);<br \/>\nlcd.print(&#8220;AMP4=&#8221;);<br \/>\nlcd.setCursor (8, 2);<br \/>\nlcd.print((char)223);<br \/>\nlcd.print(&#8220;C&#8221;);<br \/>\nlcd.setCursor(12, 2);<br \/>\nlcd.print(&#8220;FS= &#8220;);<\/p>\n<p>\/\/fourth line is bargraph<br \/>\n}<\/p>\n<p>\/\/ main calculation routine starts here<\/p>\n<p>void loop() {<br \/>\nincrementStateTemp = digitalRead(incrementButtonTemp); \/\/read the increment button state<br \/>\nif (incrementStateTemp != lastIncrementStateTemp) \/\/compare increment button state to its last state<br \/>\n{<br \/>\nif (incrementStateTemp == LOW) \/\/increment button is pressed<br \/>\n{<br \/>\ncounterTemp = counterTemp + 1; \/\/increment the counter<br \/>\ndelay(10); \/\/debounce delay<br \/>\n}<br \/>\n}<br \/>\nlastIncrementStateTemp = incrementStateTemp;<br \/>\n\/\/Reading and counting the button for Mode<\/p>\n<p>incrementStateMode = digitalRead(incrementButtonMode); \/\/read the increment button state<br \/>\nif (incrementStateMode != lastIncrementStateMode) \/\/compare increment button state to its last state<br \/>\n{<br \/>\nif (incrementStateMode == LOW) \/\/increment button is pressed<br \/>\n{<br \/>\ncounterMode = counterMode + 1; \/\/increment the counter<br \/>\ndelay(10); \/\/debounce delay<br \/>\n}<br \/>\n}<br \/>\nlastIncrementStateMode = incrementStateMode;<br \/>\n\/\/limits the the counterTemp to 3 counts and resets to 0<\/p>\n<p>if (counterTemp &gt; 2)<br \/>\n{<br \/>\ncounterTemp = 0;<br \/>\n}<br \/>\n\/\/limits the the counterMode to 1 counts and resets to 0<\/p>\n<p>if (counterMode &gt;= 1)<br \/>\n{<br \/>\ncounterMode = 0;<br \/>\n}<\/p>\n<p>\/\/code to read and calculate TEMP1 from sensor<\/p>\n<p>TEMP1 = analogRead(analogInputTEMP1);<\/p>\n<p>TEMP1 = (TEMP1 \/ 4.096);<br \/>\ndelay (5);<\/p>\n<p>\/\/sets level for the alarmtemp.<\/p>\n<p>if (TEMP1 &gt; 55) {<\/p>\n<p>digitalWrite (alarmtemp1, HIGH);<br \/>\nlcd.clear();<br \/>\nlcd.setCursor(4, 0);<br \/>\nlcd.print(&#8220;***ALARM***&#8221;);<br \/>\nlcd.setCursor(2, 2);<br \/>\nlcd.print(&#8220;*TEMPERATURE AMP1*&#8221;);<br \/>\nwhile (1) { } \/\/endless loop to stop<br \/>\n}<br \/>\n\/\/code to read and calculate TEMP2 from sensor<\/p>\n<p>TEMP2 = analogRead(analogInputTEMP2);<\/p>\n<p>TEMP2 = (TEMP2 \/ 4.096);<br \/>\ndelay (5);<\/p>\n<p>\/\/sets level for the alarmtemp.<\/p>\n<p>if (TEMP2 &gt; 55) {<\/p>\n<p>digitalWrite (alarmtemp2, HIGH);<br \/>\nlcd.clear();<br \/>\nlcd.setCursor(4, 0);<br \/>\nlcd.print(&#8220;***ALARM***&#8221;);<br \/>\nlcd.setCursor(2, 2);<br \/>\nlcd.print(&#8220;*TEMPERATURE AMP2&#8243;);<br \/>\nwhile (1) { } \/\/endless loop to stop<br \/>\n}<br \/>\n\/\/ print calculated results to lcd display<\/p>\n<p>\/\/ first line of the display<\/p>\n<p>\/\/clears the space were the temp1 is printed<br \/>\nlcd.setCursor(6, 0);<br \/>\nlcd.print(&#8221; &#8220;);<br \/>\nlcd.setCursor(6, 0);<br \/>\nlcd.print (TEMP1 , 0);<br \/>\nlcd.setCursor (8, 0);<br \/>\nlcd.print((char)223);<br \/>\nlcd.print(&#8220;C&#8221;);<\/p>\n<p>\/\/second line of the display this is a bargraph<br \/>\n\/\/third line of the display<\/p>\n<p>\/\/clears the space were the temp2 is printed<\/p>\n<p>lcd.setCursor(6, 2);<br \/>\nlcd.print(&#8221; &#8220;);<br \/>\nlcd.setCursor(6, 2);<br \/>\nlcd.print (TEMP2 , 0);<br \/>\nlcd.setCursor (8, 2);<br \/>\nlcd.print((char)223);<br \/>\nlcd.print(&#8220;C&#8221;);<\/p>\n<p>\/\/fourth line of the display this is a bargraph<br \/>\n\/\/small routine to print the FS temperature of the bargraph on the first &amp; third line of the display.<\/p>\n<p>if (counterTemp == 0 )<br \/>\n{<br \/>\nlcd.setCursor(15, 0);<br \/>\nlcd.print(&#8221; &#8220;);<br \/>\nlcd.setCursor(15, 0);<br \/>\nlcd.print(&#8221; 50&#8243;);<br \/>\nlcd.setCursor (18, 0);<br \/>\nlcd.print((char)223);<br \/>\nlcd.print(&#8220;C&#8221;);<br \/>\n}<br \/>\nif (counterTemp == 1 ) {<br \/>\nlcd.setCursor(15, 0);<br \/>\nlcd.print(&#8221; &#8220;);<br \/>\nlcd.setCursor(15, 0);<br \/>\nlcd.print(&#8220;100&#8221;);<br \/>\nlcd.setCursor (18, 0);<br \/>\nlcd.print((char)223);<br \/>\nlcd.print(&#8220;C&#8221;);<br \/>\n}<br \/>\nif (counterTemp == 2 ) {<br \/>\nlcd.setCursor(15, 0);<br \/>\nlcd.print(&#8221; &#8220;);<br \/>\nlcd.setCursor(15, 0);<br \/>\nlcd.print(&#8220;200&#8221;);<br \/>\nlcd.setCursor (18, 0);<br \/>\nlcd.print((char)223);<br \/>\nlcd.print(&#8220;C&#8221;);<br \/>\n}<\/p>\n<p>if (counterTemp == 0 )<br \/>\n{<br \/>\nlcd.setCursor(15, 2);<br \/>\nlcd.print(&#8221; &#8220;);<br \/>\nlcd.setCursor(15, 2);<br \/>\nlcd.print(&#8221; 50&#8243;);<br \/>\nlcd.setCursor (18, 2);<br \/>\nlcd.print((char)223);<br \/>\nlcd.print(&#8220;C&#8221;);<br \/>\n}<br \/>\nif (counterTemp == 1 ) {<br \/>\nlcd.setCursor(15, 2);<br \/>\nlcd.print(&#8221; &#8220;);<br \/>\nlcd.setCursor(15, 2);<br \/>\nlcd.print(&#8220;100&#8221;);<br \/>\nlcd.setCursor (18, 2);<br \/>\nlcd.print((char)223);<br \/>\nlcd.print(&#8220;C&#8221;);<br \/>\n}<br \/>\nif (counterTemp == 2 ) {<br \/>\nlcd.setCursor(15, 2);<br \/>\nlcd.print(&#8221; &#8220;);<br \/>\nlcd.setCursor(15, 2);<br \/>\nlcd.print(&#8220;200&#8221;);<br \/>\nlcd.setCursor (18, 2);<br \/>\nlcd.print((char)223);<br \/>\nlcd.print(&#8220;C&#8221;);<br \/>\n}<br \/>\n\/\/print bargraph on lines 1 &amp; 3<\/p>\n<p>lcd.setCursor(0, 1);<\/p>\n<p>if (counterMode == 0) {<br \/>\nif (counterTemp == 0 ) {<br \/>\nlbg0.drawValue( TEMP1, 50); \/\/ &#8212; draw bar graph from the analog value readed<br \/>\ndelay(1);<br \/>\n}<br \/>\nif (counterTemp == 1 ) {<br \/>\nlbg0.drawValue( TEMP1, 100); \/\/ &#8212; draw bar graph from the analog value readed<br \/>\ndelay(1);<br \/>\n}<\/p>\n<p>if (counterTemp == 2 ) {<br \/>\nlbg0.drawValue( TEMP1, 200); \/\/ &#8212; draw bar graph from the analog value readed<br \/>\ndelay(1);<br \/>\n}<br \/>\nlcd.setCursor(0, 3);<\/p>\n<p>if (counterMode == 0) {<br \/>\nif (counterTemp == 0 ) {<br \/>\nlbg1.drawValue( TEMP2, 50); \/\/ &#8212; draw bar graph from the analog value readed<br \/>\ndelay(1);<br \/>\n}<br \/>\nif (counterTemp == 1 ) {<br \/>\nlbg1.drawValue( TEMP2, 100); \/\/ &#8212; draw bar graph from the analog value readed<br \/>\ndelay(1);<br \/>\n}<\/p>\n<p>if (counterTemp == 2 ) {<br \/>\nlbg1.drawValue( TEMP2, 200); \/\/ &#8212; draw bar graph from the analog value readed<br \/>\ndelay(1);<br \/>\n}<\/p>\n<p>\/\/saves the counterTemp value in the eeprom for the next time so that you don&#8217;t have to set the Temp every time.<br \/>\nif (counterTemp != counteroldTemp) {<br \/>\nEEPROM.write(0, counterTemp);<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/ sleep&#8230;<br \/>\ndelay(20);<\/p>\n<p>}<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>For my 23cm PA consisting of 4 PA&#8217;s I needed a temperature meter with protection in case the amplifier gets hot. The system is build <a class=\"mh-excerpt-more\" href=\"https:\/\/pa3csg.nl\/?page_id=1058\" title=\"Arduino temperature meter for solid state PA\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":1059,"parent":0,"menu_order":11,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"categories":[29],"tags":[],"_links":{"self":[{"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/pages\/1058"}],"collection":[{"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1058"}],"version-history":[{"count":4,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/pages\/1058\/revisions"}],"predecessor-version":[{"id":1064,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/pages\/1058\/revisions\/1064"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=\/wp\/v2\/media\/1059"}],"wp:attachment":[{"href":"https:\/\/pa3csg.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1058"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1058"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pa3csg.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1058"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}