Code assistance

#include <LiquidCrystal.h>
liquidcrystal lcd(12,11,5,4,3,2)


#include <SoftwareSerial.h>
softwareserial myserial(9,10);//9 to Tx of gsm 1oth pin to Rx of gsm
int buttonstate=0;
int analoginput=0;
int f=6;//battery lowlevel
int a=7;//battery full
float vout=0.0;
float vin=0.0;
int value=0;
int pump1=8;//pump on and led indicator on through uln2003

int sensorvalue=A0;//to measure voltage
int moisturesensor=A1;//to measure the moisture level
float R1=6700;
float R2=200;

int count=0
void setup()
{

pinmode(a,OUTPUT);
pinmode(f,OUTPUT);
pinmode(pump 1,OUTPUT);
pinmode (analoginput,INPUT);
lcd.begin(16,2);
myserial.begin(9600);

}

void loop()

{
value=analog read(analog input);
vout=(value5.0)/1024);//measure exact value of voltage if 12v applied it measure 3v
vin=vout/(R2/(R1+R2));//converte 3v into actual battery voltage by multiplying voltage dev rule
//vin=(value
(5.0/1023.o)*10);
lcd.setcursor(0,0);
lcd print(input v= )
lcd.setcursor(9,0);
lcd.print(vin,3);

if(vin>12.45)

{

digitalWrite(a,HIGH)
else{digitalWrite(a,LOW);}

if(vin<11.80)

{
digitalWrite(f,HIGH)
else {digitalWrite(f,LOW)};

int sensor value=analog Read(moisture sensor);
serial.print("moisture sensor=");
serial.print(sensor value);
lcd.setcursor(0,1);
lcd.print in("moisture level=");
lcd.setcursor(12,1);
lcd.print(sensor value);

if (sensor>600)
}
lcd setcursor(0,1);
lcd print in("Dry pump on");
serial print in("DRY PUMP ON");

if (count=0)
{send message() }
count=count+1
digitalWrite(pump1,HIGH);//irrigation put on

else if(sensor value<=400)
{
serial.print("wet pump off");

send message();
digitalWrite(pump 1,LOW);irrigation pump off
count=0
}
delay (1000);
}
void send message()
{
myserial.print in("AT+CMGF=1");(2,1)
delay(1000);
myserial.print in("AT+CMGS=+254758089620")
delay(1000);
myserial.print("pump on") the sms u want
delay(1000)

I've fixed and optimized your code but if your looking for more specific help with your code please post your issues.

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  // Corrected the capitalization and added semicolon

#include <SoftwareSerial.h>

SoftwareSerial mySerial(9, 10);  // Corrected the capitalization and added semicolon
int buttonState = 0;
int analogInput = A0;  // Updated the pin number to A0
int batteryLowLevel = 6;
int batteryFull = 7;
float vOut = 0.0;
float vIn = 0.0;
int value = 0;
int pump1 = 8;
int sensorValue = A0;  // Updated the pin number to A0
int moistureSensor = A1;  // Updated the pin number to A1
float R1 = 6700;
float R2 = 200;
int count = 0;  // Added a semicolon

void setup() {
  pinMode(batteryFull, OUTPUT);
  pinMode(batteryLowLevel, OUTPUT);
  pinMode(pump1, OUTPUT);
  pinMode(analogInput, INPUT);
  lcd.begin(16, 2);
  mySerial.begin(9600);  // Corrected the capitalization
}

void loop() {
  value = analogRead(analogInput);
  vOut = (value * 5.0) / 1024;  // Fixed the parenthesis and added multiplication sign
  vIn = vOut / (R2 / (R1 + R2));

  lcd.setCursor(0, 0);
  lcd.print("Input V = ");  // Added quotation marks

  lcd.setCursor(9, 0);
  lcd.print(vIn, 3);

  if (vIn > 12.45) {
    digitalWrite(batteryFull, HIGH);
  } else {
    digitalWrite(batteryFull, LOW);
  }

  if (vIn < 11.80) {
    digitalWrite(batteryLowLevel, HIGH);
  } else {
    digitalWrite(batteryLowLevel, LOW);
  }

  int sensorValue = analogRead(moistureSensor);
  Serial.print("Moisture sensor = ");
  Serial.print(sensorValue);

  lcd.setCursor(0, 1);
  lcd.print("Moisture level = ");
  lcd.setCursor(14, 1);  // Updated the cursor position
  lcd.print(sensorValue);

  if (sensorValue > 600) {
    lcd.setCursor(0, 1);
    lcd.print("Dry pump on");
    Serial.println("DRY PUMP ON");
    if (count == 0) {
      sendMessage();
    }
    count = count + 1;
    digitalWrite(pump1, HIGH);
  } else if (sensorValue <= 400) {
    Serial.println("Wet pump off");
    sendMessage();
    digitalWrite(pump1, LOW);
    count = 0;
  }
  delay(1000);
}

void sendMessage() {
  mySerial.println("AT+CMGF=1");  // Corrected the command
  delay(1000);
  mySerial.println("AT+CMGS=\"+254758089620\"");  // Corrected the command and added double quotes
  delay(1000);
  mySerial.println("pump on");  // Corrected the command
  delay(1000);
}

I've fixed various issues in the code and added comments to explain the changes. Please note that the comments provided are for reference, and you should adapt the code to your specific hardware and requirements.

1 Like

thanks for the help

1 Like

#include <LiquidCrystal.h>
#include "DHT.h"

LiquidCrystal lcd(2, 3, 4, 5, 6,7);
const int relay_Pin = 8;
const int DHT11_Sesnor = 9;
const int moisture_sensor = A0;
const int rain_Sesnor = A1;

#define DHTTYPE DHT11
int moisture_sensor_value;
int rain_Sesnor_value;
float humudity_value,temprature_value;
DHT dht(DHT11_Sesnor, DHTTYPE);

void setup() {
Serial.begin(9600);
pinMode(relay_Pin, OUTPUT);
lcd.begin(16, 2);
lcd.print("Smart Irrigation ");
lcd.setCursor(0,2);
lcd.print(" SYSTEM");
digitalWrite(relay_Pin, LOW);
dht.begin();
delay(2000);
}
void loop()
{

readDTH11_Sesnor();
moisture_level_detected();
water_motor_start();
}

void readDTH11_Sesnor()
{

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
humudity_value = dht.readHumidity();
// Read temperature as Celsius (the default)
temprature_value = dht.readTemperature();

// Check if any reads failed and exit early (to try again).
if (isnan(humudity_value) || isnan(temprature_value)) {
Serial.println(("Failed to read from DHT sensor!"));
return;
}

Serial.print((" Humidity: "));
Serial.print(humudity_value);
Serial.print(("%"));
lcd.clear();
lcd.print("Humidity %: ");
lcd.setCursor(0,2);
lcd.print(humudity_value);
Serial.print("\n");
delay(1000);
Serial.print(("Temperature: "));
Serial.print(temprature_value);
Serial.print(("C "));
lcd.clear();
lcd.print("Temperature degCel");
lcd.setCursor(0,2);
lcd.print(temprature_value);
Serial.print("\n");
delay(1000);
}

void moisture_level_detected()
{

moisture_sensor_value = analogRead(moisture_sensor);
Serial.println("Moisture Level : ");
Serial.println(moisture_sensor_value);
lcd.clear();
lcd.print("Moisture Level :");
lcd.setCursor(0,2);
lcd.print(moisture_sensor_value);
delay(2000);
}

void water_motor_start()
{

rain_Sesnor_value = analogRead(rain_Sesnor);
Serial.print("rain sensor value :: ");
Serial.println(rain_Sesnor_value);
delay(1000);
if(rain_Sesnor_value > 700)
{
if(moisture_sensor_value > 700 )
{
digitalWrite(relay_Pin, HIGH);
delay(2000);
}
else
{
digitalWrite(relay_Pin, LOW);
delay(2000);
}
}
else
{
digitalWrite(relay_Pin, LOW);
delay(2000);

@coli254

  • What was the purpose of posting the above ?

  • Looks like it isn’t a complete sketch.

need assistance please

Please start your own thread.

You must tell us what you want to happen and what is not working.


Always show us a good schematic of your proposed circuit.
Show us good images of your ‘actual’ wiring.
Give links to components.


In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.

Use the < CODE / > icon from the ‘posting menu’ to attach the copied sketch.

@coli254, please do not hijack. Thread split.

Do not cross-post. Threads merged.

Your second sketch (DHT) works just fine. What is your question about the DHT sketch?
dht

2 Likes

how do i prepare such diagram by my own

Can you please name the software or website through which you have made this

@krishna_agarwal (to be clear)
Sure, as long as you promise not to flag my post to have me suspended, again.

2 Likes

@coli254 - I used your code base and adjusted the formatting to fit in the LCD as well as the Serial Monitor.

Don't worry for that @xfpd I always first read the complete reply and is it relevant to topic or if not is it useful for anyone that I never flag. I only flag spamming

Now Please tell.

I never worry. I am certain you will do well using your resources.

can i give you one so that u can edit to me

Your second sketch was good for showing the data. It did not need any corrections. I only moved the placement of the data (formatting).

Your first sketch has very many errors to be corrected.

You can post any question you have.

Why I will do that?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.