user27618: I'm new with Arduino (and I'm not very good at English). Recently with Arduino Nano I have tested:

Control water pump based on soil moisture (using relay) (1)
Display soil moiture (in percent) on a Nokia 5110 LCD   (2)

Now I'm combining 2 codes to control water pump while always displaying moisture value (in percent) on LCD. However, after I have uploaded the code an Arduino Nano, the LCD showed nothing. 
When I touched the sensor (changed moisture value) the first time, the LCD showed up, but when I touched the sensor the second time (changed moisture value again), the LCD went blank. The relay and pump still work fine, so I think the problem comes from LCD's code.
Here's my code (1):
const int VAL_PROBE = 0; 
int RELAY1 = A1;
const int MOISTURE_LEVEL = 250; 

void setup() 
{
  Serial.begin(9600);
  pinMode (2, INPUT);
  pinMode(A0, INPUT);
  pinMode(RELAY1, OUTPUT);
}

void loop() 
{
  int moisture = analogRead(VAL_PROBE);
  Serial.print("Moisture = ");
  Serial.println(moisture);

  if(moisture < MOISTURE_LEVEL)
  {
    digitalWrite(RELAY1,0);           // turn on relay
    Serial.println("Light ON");
  }
  else 
  {
    digitalWrite(RELAY1,1);          // turn off relay
    Serial.println("Light OFF");
  }
}

The code (2)(got it from the Internet):
    //////////////////////////////////////////////
   //        Arduino Soil Moisture Sensor      //
  //            with NOKIA 5110 LCD           //
 //           http://www.educ8s.tv           //
//////////////////////////////////////////////


#include <LCD5110_Graph.h> // THE LIBRARY I AM USING IS THIS:  http://www.rinkydinkelectronics.com/library.php?id=47

LCD5110 lcd(8,9,10,12,11);

extern unsigned char BigNumbers[];
extern uint8_t ui[];

int sensorPin = A0;  
int sensorValue = 0;  
int percent = 0;
String percentString ="0";
int stringLength = 0;

void setup() {
  lcd.InitLCD();
  lcd.setFont(BigNumbers);
  delay(1000);
}

void loop() {
  lcd.clrScr();
  lcd.drawBitmap(0, 0, ui, 84, 48);
  sensorValue = analogRead(sensorPin);
  percent = convertToPercent(sensorValue);
  percentString = String(percent);
  stringLength = percentString.length();
  displayPercent(stringLength);

  lcd.update();
  delay(1000);
}

int convertToPercent(int value)
{
  int percentValue = 0;
  percentValue = map(value, 1023, 350, 0, 100);
  if(percentValue>100)
    percentValue = 100;
  return percentValue;
}

void displayPercent(int length)
{
  switch(length)
  {
    case 1:  lcd.print(percentString,38,19); break;
    case 2:  lcd.print(percentString,24,19); break;
    case 3:  lcd.print(percentString,10,19); break;
    default:  lcd.print(percentString,0,19); break;
  }
}

And my combined code:
const int VAL_PROBE = 0;
int RELAY1 = A1;
const int MOISTURE_LEVEL = 250; // Mức độ ẩm cố định là 250
#include <LCD5110_Graph.h>

LCD5110 lcd(8,9,10,12,11);

extern unsigned char BigNumbers[];
extern uint8_t ui[];

int sensorPin = A0;  
int MoistureValue = 0;  
int percent = 0;
String percentString ="0";
int stringLength = 0;


void setup() 
{
  Serial.begin(9600);//Mở cổng Serial ở mức 9600
  pinMode (2, INPUT);
  pinMode(A0, INPUT);
  pinMode (12, OUTPUT);
  pinMode(RELAY1, OUTPUT);
  lcd.InitLCD();
  lcd.setFont(BigNumbers);
  delay(1000);
}

void loop() 
{
  lcd.clrScr();
  lcd.drawBitmap(0, 0, ui, 84, 48); // hiển thị giao diện màn hình
  MoistureValue = analogRead(sensorPin); // đọc giá trị từ cảm biến

  percent = convertToPercent(MoistureValue);
  percentString = String(percent);
  stringLength = percentString.length();
  displayPercent(stringLength);

  lcd.update(); // cập nhật màn hình
  delay(1000); // mỗi 1 giây

  int moisture = analogRead(VAL_PROBE);
  Serial.print("Moisture = ");
  Serial.println(moisture);

  if(moisture < MOISTURE_LEVEL)
  {
    digitalWrite(12,HIGH);
    digitalWrite(RELAY1,0);           // bật relay
    Serial.println("Light ON");
  }
  else 
  {
    digitalWrite(12,LOW);
    digitalWrite(RELAY1,1);          // tắt relay
    Serial.println("Light OFF");
  }
}

int convertToPercent(int value) // đổi giá trị cảm biến sang phần trăm
{
  int percentValue = 0;
  percentValue = map(value, 1023, 350, 0, 100);
  if(percentValue>100)
    percentValue = 100;
  return percentValue;
}

void displayPercent(int length) // hiển thị phần trăm ra màn hình
{
  switch(length)
  {
    case 1:  lcd.print(percentString,38,19); break;
    case 2:  lcd.print(percentString,24,19); break;
    case 3:  lcd.print(percentString,10,19); break;
    default:  lcd.print(percentString,0,19); break;
  }
}

Any advice?

user2881: I think the problem is with
digitalWrite(12,HIGH);

and
digitalWrite(12,LOW);

Pin 12 is used by the LCD. Changing it's output will reset the LCD. I'm not sure why you put it there to begin with, as it wasn't part of any of the two sketches.

27618: <p>I'm new with Arduino (and I'm not very good at English). Recently with Arduino Nano I have tested:</p>

<ul>
<li>Control water pump based on soil moisture (using relay) (1)</li>
<li>Display soil moiture (in percent) on a Nokia 5110 LCD   (2)</li>
</ul>

<p>Now I'm combining 2 codes to control water pump while always displaying moisture value (in percent) on LCD. However, after I have uploaded the code an Arduino Nano, the LCD showed nothing. </p>

<p>When I touched the sensor (changed moisture value) the first time, the LCD showed up, but when I touched the sensor the second time (changed moisture value again), the LCD went blank. The relay and pump still work fine, so I think the problem comes from LCD's code.</p>

<p>Here's my code (1):</p>

<pre><code>const int VAL_PROBE = 0; 
int RELAY1 = A1;
const int MOISTURE_LEVEL = 250; 

void setup() 
{
  Serial.begin(9600);
  pinMode (2, INPUT);
  pinMode(A0, INPUT);
  pinMode(RELAY1, OUTPUT);
}

void loop() 
{
  int moisture = analogRead(VAL_PROBE);
  Serial.print("Moisture = ");
  Serial.println(moisture);

  if(moisture &lt; MOISTURE_LEVEL)
  {
    digitalWrite(RELAY1,0);           // turn on relay
    Serial.println("Light ON");
  }
  else 
  {
    digitalWrite(RELAY1,1);          // turn off relay
    Serial.println("Light OFF");
  }
}
</code></pre>

<p>The code (2)(got it from the Internet):</p>

<pre><code>    //////////////////////////////////////////////
   //        Arduino Soil Moisture Sensor      //
  //            with NOKIA 5110 LCD           //
 //           http://www.educ8s.tv           //
//////////////////////////////////////////////


#include &lt;LCD5110_Graph.h&gt; // THE LIBRARY I AM USING IS THIS:  http://www.rinkydinkelectronics.com/library.php?id=47

LCD5110 lcd(8,9,10,12,11);

extern unsigned char BigNumbers[];
extern uint8_t ui[];

int sensorPin = A0;  
int sensorValue = 0;  
int percent = 0;
String percentString ="0";
int stringLength = 0;

void setup() {
  lcd.InitLCD();
  lcd.setFont(BigNumbers);
  delay(1000);
}

void loop() {
  lcd.clrScr();
  lcd.drawBitmap(0, 0, ui, 84, 48);
  sensorValue = analogRead(sensorPin);
  percent = convertToPercent(sensorValue);
  percentString = String(percent);
  stringLength = percentString.length();
  displayPercent(stringLength);

  lcd.update();
  delay(1000);
}

int convertToPercent(int value)
{
  int percentValue = 0;
  percentValue = map(value, 1023, 350, 0, 100);
  if(percentValue&gt;100)
    percentValue = 100;
  return percentValue;
}

void displayPercent(int length)
{
  switch(length)
  {
    case 1:  lcd.print(percentString,38,19); break;
    case 2:  lcd.print(percentString,24,19); break;
    case 3:  lcd.print(percentString,10,19); break;
    default:  lcd.print(percentString,0,19); break;
  }
}
</code></pre>

<p>And my combined code:</p>

<pre><code>const int VAL_PROBE = 0;
int RELAY1 = A1;
const int MOISTURE_LEVEL = 250; // Mức độ ẩm cố định là 250
#include &lt;LCD5110_Graph.h&gt;

LCD5110 lcd(8,9,10,12,11);

extern unsigned char BigNumbers[];
extern uint8_t ui[];

int sensorPin = A0;  
int MoistureValue = 0;  
int percent = 0;
String percentString ="0";
int stringLength = 0;


void setup() 
{
  Serial.begin(9600);//Mở cổng Serial ở mức 9600
  pinMode (2, INPUT);
  pinMode(A0, INPUT);
  pinMode (12, OUTPUT);
  pinMode(RELAY1, OUTPUT);
  lcd.InitLCD();
  lcd.setFont(BigNumbers);
  delay(1000);
}

void loop() 
{
  lcd.clrScr();
  lcd.drawBitmap(0, 0, ui, 84, 48); // hiển thị giao diện màn hình
  MoistureValue = analogRead(sensorPin); // đọc giá trị từ cảm biến

  percent = convertToPercent(MoistureValue);
  percentString = String(percent);
  stringLength = percentString.length();
  displayPercent(stringLength);

  lcd.update(); // cập nhật màn hình
  delay(1000); // mỗi 1 giây

  int moisture = analogRead(VAL_PROBE);
  Serial.print("Moisture = ");
  Serial.println(moisture);

  if(moisture &lt; MOISTURE_LEVEL)
  {
    digitalWrite(12,HIGH);
    digitalWrite(RELAY1,0);           // bật relay
    Serial.println("Light ON");
  }
  else 
  {
    digitalWrite(12,LOW);
    digitalWrite(RELAY1,1);          // tắt relay
    Serial.println("Light OFF");
  }
}

int convertToPercent(int value) // đổi giá trị cảm biến sang phần trăm
{
  int percentValue = 0;
  percentValue = map(value, 1023, 350, 0, 100);
  if(percentValue&gt;100)
    percentValue = 100;
  return percentValue;
}

void displayPercent(int length) // hiển thị phần trăm ra màn hình
{
  switch(length)
  {
    case 1:  lcd.print(percentString,38,19); break;
    case 2:  lcd.print(percentString,24,19); break;
    case 3:  lcd.print(percentString,10,19); break;
    default:  lcd.print(percentString,0,19); break;
  }
}
</code></pre>

<p>Any advice?</p>
 2881: <p>I think the problem is with</p>

<pre><code>digitalWrite(12,HIGH);
</code></pre>

<p>and</p>

<pre><code>digitalWrite(12,LOW);
</code></pre>

<p>Pin 12 is used by the LCD. Changing it's output will reset the LCD. I'm not sure why you put it there to begin with, as it wasn't part of any of the two sketches.</p>
