My coding is showing the error of complitation error :exit status 1. I am new about this, please help me

#include<LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0*27,16,2);
int sensor_pin = A0;
int relay_pin =7;


void setup()
{
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.backlight();
  lcd.setBacklight(HIGH);
  pinMode (sensor_pin, INPUT);
  pinMode (relay_pin, OUTPUT);


void loop();
   int sensor_data =analogRead(sensor_pin);
  Serial.print("Sensor_data:");
  Serial.print(sensor_data);
  Serial.print("\t |");


 if(sensor_data > 950)
{
  Serial.println("No moisture, Soil is dry");
  digitalWrite(relay_pin, HIGH);
  lcd.setCursor(0,0);
  lcd.print("Soil Dry");
  lcd.setCursor(0,1);
  lcd.print("Motor ON");

}
else if(sensor_data>=400&& sensor_data<=949)
{
  Serial.println("There is some moisture, Soil is in medium condition");
  digitalWrite(relay_pin, LOW);
  lcd.setCursor(0,0);
  lcd.print("Soil Medium");
  lcd.setCursor(0,1);
  lcd.print("Motor OFF");
}
else if(sensor_data < 400)
{
  Serial.println("Soil is wet");
  digitalWrite(relay_pin, LOW);
  lcd.setCursor(0,0);
  lcd.print("Soil Wet");
  lcd.setCursor(0,1);
  lcd.print("Motor OFF");
}
 delay(100);
}

The errors are not showing on your post. Did you forget to include them?

Welcome to the forum

Where did you get the code from ?

This line

LiquidCrystal_I2C lcd(0*27,16,2);

looks wrong

EDIT

    void loop();

The semicolon should not be there and there is no opening brace for the loop() function or a closing brace on the setup() function

You copied some real garbage code, try again.

1 Like
#include<LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0*27,16,2);
int sensor_pin = A0;
int relay_pin =7;


void setup()
{
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.backlight();
  lcd.setBacklight(HIGH);
  pinMode (sensor_pin, INPUT);
  pinMode (relay_pin, OUTPUT);


void loop();
   int sensor_data =analogRead(sensor_pin);
  Serial.print("Sensor_data:");
  Serial.print(sensor_data);
  Serial.print("\t |");


 if(sensor_data > 950)
{
  Serial.println("No moisture, Soil is dry");
  digitalWrite(relay_pin, HIGH);
  lcd.setCursor(0,0);
  lcd.print("Soil Dry");
  lcd.setCursor(0,1);
  lcd.print("Motor ON");

}
else if(sensor_data>=400&& sensor_data<=949)
{
  Serial.println("There is some moisture, Soil is in medium condition");
  digitalWrite(relay_pin, LOW);
  lcd.setCursor(0,0);
  lcd.print("Soil Medium");
  lcd.setCursor(0,1);
  lcd.print("Motor OFF");
}
else if(sensor_data < 400)
{
  Serial.println("Soil is wet");
  digitalWrite(relay_pin, LOW);
  lcd.setCursor(0,0);
  lcd.print("Soil Wet");
  lcd.setCursor(0,1);
  lcd.print("Motor OFF");
}
 delay(100);
}

C:\Users\PC\AppData\Local\Temp\ccX02ItK.ltrans0.ltrans.o: In function `main':
C:\Users\PC\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\cores\arduino/main.cpp:46: undefined reference to `loop'
collect2.exe: error: ld returned 1 exit status

exit status 1

Compilation error: exit status 1

ok thanks :tired_face:

ya sorry and thanks for reminder

I get the code at here

Hi! Welcome to the Forum.

Try the version below (untested, only checked typo errors):

#include<LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);
int sensor_pin = A0;
int relay_pin =7;


void setup() {
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.backlight();
  lcd.setBacklight(HIGH);
  pinMode (sensor_pin, INPUT);
  pinMode (relay_pin, OUTPUT);
}


void loop(){
  int sensor_data =analogRead(sensor_pin);
  Serial.print("Sensor_data:");
  Serial.print(sensor_data);
  Serial.print("\t |");


 if(sensor_data > 950) {
  Serial.println("No moisture, Soil is dry");
  digitalWrite(relay_pin, HIGH);
  lcd.setCursor(0,0);
  lcd.print("Soil Dry");
  lcd.setCursor(0,1);
  lcd.print("Motor ON");
 }
 else if(sensor_data>=400&& sensor_data<=949) {
  Serial.println("There is some moisture, Soil is in medium condition");
  digitalWrite(relay_pin, LOW);
  lcd.setCursor(0,0);
  lcd.print("Soil Medium");
  lcd.setCursor(0,1);
  lcd.print("Motor OFF");
 }
 else if(sensor_data < 400) {
  Serial.println("Soil is wet");
  digitalWrite(relay_pin, LOW);
  lcd.setCursor(0,0);
  lcd.print("Soil Wet");
  lcd.setCursor(0,1);
  lcd.print("Motor OFF");
 }
 delay(100);
}

Learn to press crl T to format your code. This error would have been obvious if you did.

Thanks!!! The code is functioning!!!

Ok thank you :grinning:

sorry to ask one more question :sweat_smile:. May I know why the led sreen is not showing anything? and also the water pump is still running while the soil in moist condition? Is it my material problem or coding problem? Tq!!!

I assume that the relay turn the water pump on and off. Does the pump run when you write LOW to the relay pin or when you write HIGH to the relay pin ?

Do you see anything printed in the Serial monitor and, if so, do the messages match the actual soil condition ?

yes the pump is still running while the relay pin is LOW

Do you mean your lcd display?
Show us how everything is connected... AND

the links to the tech info of the sensor, the board you are using and relay.

the message is match with the actual soil condition but the pump is not running as I expect....

Relay modules used with Arduino boards are usually configured to be active LOW, ie the relay turns on when its input pin is LOW

If that is the cause of your problem then you can fix it in one of two ways

Method 1 : Change the program to output LOW when you want the relay to turn on and HIGH when you want it to turn off

Method 2 : change how the pump is wired to the relay so that power is supplied to the pump when required. The relay will almost certainly have a Normally Open (NO) and normally Closed (NC) contact and a Common contact to allow you to do this

!
Uploading: 17358346844613777213349911010651.jpg…
17358343433607643854948741683481|375x500





ok I will try to do it