0% found this document useful (0 votes)
4 views2 pages

Pump 07

The document contains an Arduino code for a smart irrigation system that uses a SIM800L module for communication, a DHT11 sensor for temperature and humidity readings, and a moisture sensor. It includes functionalities to check for incoming calls and SMS, toggle a water pump based on these inputs, and display sensor data on an LCD. The system can send SMS updates regarding the pump status, moisture level, temperature, and humidity.

Uploaded by

elmanaust
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Pump 07

The document contains an Arduino code for a smart irrigation system that uses a SIM800L module for communication, a DHT11 sensor for temperature and humidity readings, and a moisture sensor. It includes functionalities to check for incoming calls and SMS, toggle a water pump based on these inputs, and display sensor data on an LCD. The system can send SMS updates regarding the pump status, moisture level, temperature, and humidity.

Uploaded by

elmanaust
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <SoftwareSerial.

h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>

#define SIM_RX 3
#define SIM_TX 2
#define PUMP_PIN 8
#define MOISTURE_SENSOR A0
#define DHTPIN A1
#define DHTTYPE DHT11

SoftwareSerial sim800l(SIM_RX, SIM_TX);


LiquidCrystal_I2C lcd(0x27, 16, 2);
DHT dht(DHTPIN, DHTTYPE);
bool pumpStatus = false;

void setup() {
Serial.begin(9600);
sim800l.begin(9600);
dht.begin();
delay(2000);

lcd.begin(16, 2);
lcd.backlight();

pinMode(PUMP_PIN, OUTPUT);
digitalWrite(PUMP_PIN, HIGH);

sim800l.println("ATS0=0");
delay(500);
Serial.println("Testing SIM800L...");
sim800l.println("AT");
}

void loop() {
checkForCall();
checkForSMS();
displaySensorData();
}

void checkForCall() {
if (sim800l.available()) {
String callData = sim800l.readString();
Serial.println("SIM800L Data: " + callData);

if (callData.indexOf("RING") >= 0) {
delay(1000);
sim800l.println("ATH");
delay(500);
togglePump();
}
}
}

void checkForSMS() {
if (sim800l.available()) {
String smsData = sim800l.readString();
Serial.println("Received SMS: " + smsData);
if (smsData.indexOf("status") >= 0) {
sendSystemStatus();
}
}
}

void togglePump() {
pumpStatus = !pumpStatus;
digitalWrite(PUMP_PIN, pumpStatus ? LOW : HIGH);
sendSystemStatus();
}

void displaySensorData() {
int moisture = map(analogRead(MOISTURE_SENSOR), 1023, 0, 0, 100);
float temp = dht.readTemperature();
float humidity = dht.readHumidity();

lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Moist:" + String(moisture) + "% ");
lcd.setCursor(0, 1);
lcd.print("T:" + String(temp) + "C H:" + String(humidity) + "% ");

delay(2000);
}

void sendSystemStatus() {
int moisture = map(analogRead(MOISTURE_SENSOR), 1023, 0, 0, 100);
float temp = dht.readTemperature();
float humidity = dht.readHumidity();

String message = "Pump: " + String(pumpStatus ? "ON" : "OFF") +


"\nMoisture: " + String(moisture) + "%" +
"\nTemp: " + String(temp) + "C" +
"\nHumidity: " + String(humidity) + "%";
sendSMS(message);
}

void sendSMS(String msg) {


sim800l.println("AT+CMGF=1");
delay(500);
sim800l.println("AT+CMGS=\"+8801879113516\"");
delay(500);
sim800l.print(msg);
delay(500);
sim800l.write(26);
delay(2000);
}

You might also like