/*This software is provided in an “AS IS” condition,NO WARRANTIES in any form apply to this software. picmicrolab.com 10.6.2017 *************************************************************************************************************** Arduino Thermometer with LM35 LM35 Input - A0; */ int Bit_0 = 2; int Bit_1 = 3; int Bit_2 = 4; int Bit_3 = 5; int Bit_4 = 6; int Bit_5 = 7; int Bit_6 = 8; int Bit_7 = 9; int RS = 10; int EN = 11; //------------------- int Digit3 = 0; int Digit2 = 0; int Digit1 = 0; int Digit0 = 0; //int BinaryValue = 0; int VoltageBarValue = 0; int LCD_Address = 0x80; // the setup function runs once when you press reset or power the board void setup() { // initialize I/O as output. pinMode(Bit_0, OUTPUT); //Bit_0 pinMode(Bit_1, OUTPUT); //Bit_1 pinMode(Bit_2, OUTPUT); //Bit_2 pinMode(Bit_3, OUTPUT); //Bit_3 pinMode(Bit_4, OUTPUT); //Bit_4 pinMode(Bit_5, OUTPUT); //Bit_5 pinMode(Bit_6, OUTPUT); //Bit_6 pinMode(Bit_7, OUTPUT); //Bit_7 pinMode(RS, OUTPUT); //Bit_10 pinMode(EN, OUTPUT); //Bit_11 InitLCD(); } void loop() { int analog_input = analogRead(A0);//LM35 on A0 input ConvertBinaryToBCD(analog_input * 4.87); ShowDigitsLCD(0x85,0xfe,Digit2,Digit1,0xfe);//0xfe - shows empty char on LCD delay(300); } void ShowDigitsLCD(int LCDaddress,int digit3,int digit2,int digit1,int digit0) { LCDC(LCDaddress); LCDD(digit2+0x30); LCDD(digit1+0x30); LCDD(0xdf);//Show degree symbol LCDD(0x43);//Show C } void ConvertBinaryToBCD(int number) { Digit3 = 0; Digit2 = 0; Digit1 = 0; Digit0 = 0; while(number > 0) { number=number-1000; if(number > 0) Digit3++; } number=number+1000; while(number > 0) { number=number-100; if(number > 0) Digit2++; } number=number+100; while(number > 0) { number=number-10; if(number > 0) Digit1++; } number=number+10; Digit0 = number; } void ConvertNumToBinary(int digit) { //--------------BIT_0------------ if(bitRead(digit, 0)== 1) digitalWrite(Bit_0, HIGH); if(bitRead(digit, 0)== 0) digitalWrite(Bit_0, LOW); //------------------------------- //--------------BIT_1------------ if(bitRead(digit, 1) == 1) digitalWrite(Bit_1, HIGH); if(bitRead(digit, 1) == 0) digitalWrite(Bit_1, LOW); //------------------------------- //--------------BIT_2------------ if(bitRead(digit, 2) == 1) digitalWrite(Bit_2, HIGH); if(bitRead(digit, 2) == 0) digitalWrite(Bit_2, LOW); //------------------------------- //--------------BIT_3------------ if(bitRead(digit, 3) == 1) digitalWrite(Bit_3, HIGH); if(bitRead(digit, 3) == 0) digitalWrite(Bit_3, LOW); //------------------------------- //--------------BIT_4------------ if(bitRead(digit, 4) == 1) digitalWrite(Bit_4, HIGH); if(bitRead(digit, 4) == 0) digitalWrite(Bit_4, LOW); //------------------------------- //--------------BIT_5------------ if(bitRead(digit, 5) == 1) digitalWrite(Bit_5, HIGH); if(bitRead(digit, 5) == 0) digitalWrite(Bit_5, LOW); //------------------------------- //--------------BIT_6------------ if(bitRead(digit, 6) == 1) digitalWrite(Bit_6, HIGH); if(bitRead(digit, 6) == 0) digitalWrite(Bit_6, LOW); //------------------------------- //--------------BIT_7------------ if(bitRead(digit, 7) == 1) digitalWrite(Bit_7, HIGH); if(bitRead(digit, 7) == 0) digitalWrite(Bit_7, LOW); //------------------------------- } void InitLCD() { delay(20); //ConvertNumToBinary(0x30); LCDC(0x30); delay(5); //----------------- LCDC(0x30); delay(5); //----------------- LCDC(0x30); delay(1); //----------------- //; display clear LCDC(0x01); delay(1); //----------------- // ID=1,S=0 increment,no shift 000001 ID S LCDC(0x06); delay(1); //----------------- //D=1,C=B=0 set display ,no cursor, no blinking LCDC(0x0c); delay(1); //------------------ // dl=1 ( 8 bits interface,n=12 lines,f=05x8 dots) LCDC(0x38); delay(1); //------------------ } void LCDC(int command) { //RS = 0 ;EN = 0 ; digitalWrite(RS, LOW); digitalWrite(EN, LOW); ConvertNumToBinary(command); //; EN=1,RS=0 digitalWrite(RS, LOW); digitalWrite(EN, HIGH); delay(1); //; EN=0,RS=0 digitalWrite(RS, LOW); digitalWrite(EN, LOW); delay(1); } void LCDD(int data) { //RS = 1 ;EN = 0 ; digitalWrite(RS, HIGH); digitalWrite(EN, LOW); ConvertNumToBinary(data); //; EN=1,RS=1 digitalWrite(RS, HIGH); digitalWrite(EN, HIGH); delay(1); //; EN=0,RS=1 digitalWrite(RS, HIGH); digitalWrite(EN, LOW); delay(1); }