Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

help to fix the codes bellow to make them properly send a message and display characters correctly and not unreadable characters #include #include / /

help to fix the codes bellow to make them properly send a message and display characters correctly and not unreadable characters
#include
#include
// Setup SoftwareSerial pins
SoftwareSerial mySerial(10,11); // Change this to your correct TX and RX pins
// Initialize LCD
LiquidCrystal lcd(9,8,5,4,3,2); // RS, EN, D4, D5, D6, D7
// Moisture Sensor Pins
int area_one_moisture_sensor = A0;
int area_two_moisture_sensor = A1;
int area_three_moisture_sensor = A2;
int area_four_moisture_sensor = A3;
// Relay Pins
int area_one_relay =12;
int area_two_relay =13;
int area_three_relay =14;
int area_four_relay =15;
// LED Pins
int LED1=6; // Indicate irrigation is on
int LED2=7; // Indicate irrigation is off
// SMS configuration
const char* recipient_number ="+255627410551";
bool is_area_one_irrigating = false; // Track irrigation status
bool is_area_two_irrigating = false; // Track irrigation status
bool is_area_three_irrigating = false; // Track irrigation status
bool is_area_four_irrigating = false; // Track irrigation status
void SendSMS(const char* message){
mySerial.println("AT+CMGF=1"); // Set SMS mode to TEXT
delay(200); // Increase delay for GSM stability
mySerial.print("AT+CMGS=\"");
mySerial.print(recipient_number);
mySerial.println("\""); // Specify recipient
delay(200); // Small delay
mySerial.println(message); // SMS content
mySerial.write(26); // Send ASCII 26(Ctrl+Z) to end message
delay(200); // Wait for GSM to process
}
void setup(){
Serial.begin(9600); // Initialize Serial monitor
mySerial.begin(9600); // Initialize GSM connection
// Setup pin modes
pinMode(area_one_moisture_sensor, INPUT);
pinMode(area_two_moisture_sensor, INPUT);
pinMode(area_three_moisture_sensor, INPUT);
pinMode(area_four_moisture_sensor, INPUT);
pinMode(area_one_relay, OUTPUT);
pinMode(area_two_relay, OUTPUT);
pinMode(area_three_relay, OUTPUT);
pinMode(area_four_relay, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
// Initial LCD display
lcd.begin(16,2); // Initialize LCD
lcd.print("Precision Irrigation");
lcd.setCursor(0,1);
lcd.print("System");
delay(2000); // Display welcome message for 2 seconds
}
void displayMoistureLevels(int m1, int m2, int m3, int m4){
lcd.clear();
lcd.print("A1:");
lcd.print(m1);
lcd.print(" A2:");
lcd.print(m2);
lcd.setCursor(0,1);
lcd.print("A3:");
lcd.print(m3);
lcd.print(" A4:");
lcd.print(m4);
}
void loop(){
// Read moisture sensor values
int area_one_moisture = analogRead(area_one_moisture_sensor);
int area_two_moisture = analogRead(area_two_moisture_sensor);
int area_three_moisture = analogRead(area_three_moisture_sensor);
int area_four_moisture = analogRead(area_four_moisture_sensor);
// Display moisture levels on LCD
displayMoistureLevels(area_one_moisture, area_two_moisture, area_three_moisture, area_four_moisture);
// Relay and SMS logic for area one
if (area_one_moisture >=400){// High moisture, start irrigation
digitalWrite(area_one_relay, LOW); // Relay ON
digitalWrite(LED1, HIGH); // LED indicating irrigation is on
digitalWrite(LED2, LOW); // Off LED on
if (!is_area_one_irrigating){// If not already irrigating
SendSMS("Area One is being irrigated."); // Send SMS
is_area_one_irrigating = true; // Set flag
}
} else {// Low moisture, stop irrigation
digitalWrite(area_one_relay, HIGH); // Relay OFF
digitalWrite(LED1, LOW); // Irrigation LED off
digitalWrite(LED2, HIGH); // Off LED on
if (is_area_one_irrigating){// If was irrigating, send SMS about stopping
SendSMS("Area One has stopped irrigation."); // SMS indicating irrigation stop
is_area_one_irrigating = false; // Reset flag
}
}
delay(2000); // Delay before next loop iteration
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

b. Why were these values considered important?

Answered: 1 week ago