Need help with smart blind stick project with gps and gsm module

Hello there, currently im developing an arduino project about Smart Blind Sticks with gps and gsm modules. I want it to be rechargeable with a power bank kit. So my current components are a powerbank kit, 3.7V 120mAh battery, hcsr04 ultrasonic sensor, Sim800L gsm module, Neo 6M GPS module, Arduino nano, 4x4 pin tact switches, buzzer, arduino vibration motor. It has 3 alert modes which can be choosed by 3 buttons i placed on circuit. And also i want to integrate gsm and gps module with a button so that when i press the button it will send the desired phone number a sms with the coordinates of the disabled person. Ultrasonic sensor will calculate the distance and when a obstacle is closer then 100 cm it will alert the user. I present you my current code;
` #include <SoftwareSerial.h>
#include <TinyGPS++.h>

#define button1 2 // Button for Alarm mode
#define button2 3 // Button for Alarm and Vibration modes
#define button3 4 // Button for Vibration mode
#define button4 5 // Button for GPS location

#define buzzer 6 // Buzzer pin for alarm
#define motor 7 // Vibration motor pin

#define echopin 8 // Echo pin of the ultrasonic sensor
#define trigpin 9 // Trigger pin of the ultrasonic sensor

#define gsmSerialTxPin 10 // Serial data output pin of GSM module
#define gsmSerialRxPin 11 // Serial data input pin of GSM module

SoftwareSerial gsmSerial(gsmSerialTxPin, gsmSerialRxPin); // Serial port definition for GSM module

TinyGPSPlus gps; // Object for reading GPS data

int Alarm = 1, Vibrator = 1; // Default: Alarm and Vibration modes are enabled
int cm; // Distance value

void setup() {
Serial.begin(9600); // Start serial communication
gsmSerial.begin(9600); // Start GSM module

pinMode(button1, INPUT_PULLUP); // Set button 1 as input
pinMode(button2, INPUT_PULLUP); // Set button 2 as input
pinMode(button3, INPUT_PULLUP); // Set button 3 as input
pinMode(button4, INPUT_PULLUP); // Set button 4 as input

pinMode(buzzer, OUTPUT); // Set buzzer pin as output
pinMode(motor, OUTPUT); // Set vibration motor pin as output

pinMode(trigpin, OUTPUT); // Set trigger pin of ultrasonic sensor as output
pinMode(echopin, INPUT); // Set echo pin of ultrasonic sensor as input
}

void loop() {
if (digitalRead(button1) == 0) Alarm = 1, Vibrator = 0; // Only Alarm mode
if (digitalRead(button2) == 0) Alarm = 1, Vibrator = 1; // Alarm and Vibration modes
if (digitalRead(button3) == 0) Alarm = 0, Vibrator = 1; // Only Vibration mode
if (digitalRead(button4) == 0) sendGPSLocation(); // Send GPS location

digitalWrite(trigpin, LOW); // Send low signal to trigger pin
delayMicroseconds(2);
digitalWrite(trigpin, HIGH); // Send high signal
delayMicroseconds(10); // Wait for 10 microseconds
digitalWrite(trigpin, LOW); // Send low signal to trigger pin

long ultra_time = pulseIn(echopin, HIGH); // Measure duration of high signal on echo pin
cm = ultra_time / 29 / 2; // Calculate distance

if (cm >= 20 && cm <= 100) {
int d = map(cm, 20, 100, 20, 2000); // Map the distance
if (Alarm == 1) digitalWrite(buzzer, HIGH); // Turn on buzzer
if (Vibrator == 1) digitalWrite(motor, HIGH); // Turn on vibration motor
delay(100);
digitalWrite(buzzer, LOW); // Turn off buzzer
digitalWrite(motor, LOW); // Turn off vibration motor
delay(d);
}
if (cm < 20) {
if (Alarm == 1) digitalWrite(buzzer, HIGH); // Turn on buzzer
if (Vibrator == 1) digitalWrite(motor, HIGH); // Turn on vibration motor
}
if (cm > 100) {
digitalWrite(buzzer, LOW); // Turn off buzzer
digitalWrite(motor, LOW); // Turn off vibration motor
}
delay(10); // Wait for 10 milliseconds
}

void sendGPSLocation() {
if (gps.location.isValid()) {
String latitude = String(gps.location.lat(), 6);
String longitude = String(gps.location.lng(), 6);
String message = "Location: Google Maps" + latitude + "," + longitude;

gsmSerial.println("AT+CMGF=1"); // Set SMS text mode
delay(100);
gsmSerial.println("AT+CMGS=\"+905555555555\""); // Enter recipient's phone number
delay(100);
gsmSerial.println(message); // Send message

} `
And the question is; is there any missing points in my code and any advices to improve it ? Also if you can help me with the connections and circuit diagram i couldn't appriciate it more. Thank you for helping fellow developers!

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

That should be:

if (digitalRead(button1) == 0) {   // Only Alarm mode
    Alarm = 1; 
    Vibrator = 0;
} 

If you keep abusing the comma operator you're going to end up with errors you don't understand.

1 Like

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