#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#define BUTTON_PIN 2 // Connect the push button to pin 2
#define GSM_TX_PIN 3 // Connect GSM module TX pin to pin 3
#define GSM_RX_PIN 4 // Connect GSM module RX pin to pin 4
#define GPS_TX_PIN 5 // Connect GPS module TX pin to pin 5
#define GPS_RX_PIN 6 // Connect GPS module RX pin to pin 6
SoftwareSerial gsmSerial(GSM_TX_PIN, GSM_RX_PIN); // Create a software serial port for GSM module
SoftwareSerial gpsSerial(GPS_TX_PIN, GPS_RX_PIN); // Create a software serial port for GPS module
TinyGPSPlus gps; // Create a TinyGPS++ object
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 columns, 2 rows
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP); // Set button pin as input with internal pull-up resistor
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
gsmSerial.begin(9600); // Start communication with GSM module
gpsSerial.begin(9600); // Start communication with GPS module
}
void loop() {
if (digitalRead(BUTTON_PIN) == LOW) { // Check if button is pressed
sendSMSWithLocation(); // If button is pressed, send SMS with location
lcd.clear();
lcd.print("Fire Detected");
} else {
lcd.clear();
lcd.print("No Fire");
}
delay(1000); // Delay for stability
}
void sendSMSWithLocation() {
while (gpsSerial.available() > 0) {
if (gps.encode(gpsSerial.read())) {
if (gps.location.isValid()) {
String message = "Fire detected! Location: http://maps.google.com/?q=" +
String(gps.location.lat(), 6) + "," +
String(gps.location.lng(), 6);
gsmSerial.println("AT+CMGF=1"); // Set SMS mode to text
delay(100);
gsmSerial.println("AT+CMGS=\"+1234567890\""); // Replace with recipient's phone number
delay(100);
gsmSerial.println(message); // Send the SMS message
delay(100);
gsmSerial.println((char)26); // End SMS transmission
delay(100);
}
}
}
}[quote="jayyxzc, post:1, topic:1251209, full:true"]
Give me a code of a push button, a GSM module, a GPS module and a LCD 16x2 I2C connected to the Arduino mega. The condition is, If the button is pressed the GSM module will send a SMS message to the recipient with a location extracted from the GPS module in a URL form, and the LCD will display fire detected if the button is pressed, and if the button is not press the GSM module will not send a SMS message but the LCD will display No fire
[/quote]
Your topic has been moved as it's not related to problems with the IDE.
That is not how it works on this forum. We try to help you to write code, analyse possible problems that you encounter and help to fix them. There is also a section for paid help.
Im so sorry i wrote the wrong questions
Do you want fries with that?
Please provide links to the modules that you use.
Test each module with some example code so you can understand how it works. Next write a basic code that does what you want it to do (e.g. send something via the GSM or read the GPS).
Next start merging the codes.
Assuming that your GPS and GSM use serial communication, make use of the additional hardware serial ports (UARTs) on the Mega, e.g. RX1/TX1 for the GPS and RX2/TX2 for the GSM.
I already test all the module and it is working but when i combined all the component in a one code it is not working at all,
The components that I used is
A push button
GSM MODULE SIM900A
GPS MODULE NEO6M
LCD I2C 16X2
the condition is when i pressed the button the GSM module will send a SMS message and the location extracted from the GPS module in a URL form but suddenly it is not working
Wow, a score of 70.84% from ZeroGPT's Ai/GPT text detector. I haven't seen a score that high in quite some time. And the prompt that generated it too. Everything except a question about what you're actually having problems with in regards to your ChatGPT generated code that isn't doing what you want it to.
PS ChatGPT and the like? They're really good at coming up with answers that look good. Not so good at coming up with answers that are actually correct. You're wasting your time with it. Unless you're already proficient in what you're asking it about, you can't tell when it's just made stuff up!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.