I want my arduino to reset itself when it is powered

I was working on an A6 GSM/GPRS module(A6 GSM/GPRS module is a miniature GSM modem, which can be integrated into a great number of IoT projects. You can use this module to accomplish almost anything a normal cell phone can; SMS text messages, make or receive phone calls, connecting to the internet through GPRS, TCP/IP)and I want it to reset the Arduino when it is powered up. but I want it to reset itself once when it is powered.
here is the code:

#include <SoftwareSerial.h>

//Create software serial object to communicate with A6
SoftwareSerial mySerial(3, 2); //A6 Tx & Rx is connected to Arduino #3 & #2

void setup()
{

//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);

//Begin serial communication with Arduino and A6
mySerial.begin(9600);

Serial.println(“Initializing…”);
delay(1000);

mySerial.println(“AT”); //Once the handshake test is successful, it will back to OK
updateSerial();

mySerial.println(“AT+CMGF=1”); // Configuring TEXT mode
updateSerial();
mySerial.println(“AT+CMGS=”+ZZxxxxxxxxx"");//change ZZ with country code and xxxxxxxxxxx with phone number to sms
updateSerial();
mySerial.print(“last minute”); //text content
updateSerial();
mySerial.write(26);
}

void loop()
{
}

void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(mySerial.available())
{
Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
}
}

I want it to reset itself once when it is powered.

Why ?

I wanted to make an alarm system that sends an SMS when something happens but the Arduino should be rested so that it can send the message again and again

musiba:
I wanted to make an alarm system that sends an SMS when something happens but the Arduino should be rested so that it can send the message again and again

Take your alarm/GSM code from setup()and move it to loop(). You do not need to reset the board to perform this function.

Sorry about the misunderstanding I wanted the Arduino to send an SMS when it is powered up

musiba:
Sorry about the misunderstanding I wanted the Arduino to send an SMS when it is powered up

If you put the code to send the message into setup() won't it do that automatically?

...R

Actually I tried but sometimes it won't and sometimes it does but it takes a lot of time

musiba:
Actually I tried but sometimes it won't and sometimes it does but it takes a lot of time

You need to post the program so we can see in detail what you tried. Maybe a small change would solve the problem.

And if you can't get it to work from setup() I can't see how you could get it work any other way.

...R

#include <SoftwareSerial.h>
int rst = 12;

//Create software serial object to communicate with A6
SoftwareSerial mySerial(3, 2); //A6 Tx & Rx is connected to Arduino #3 & #2

void reset()
{
digitalWrite(rst,HIGH);
pinMode(rst,OUTPUT);
delay(200);
digitalWrite (rst,LOW);
}

void loop()
{

//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);

//Begin serial communication with Arduino and A6
mySerial.begin(9600);

Serial.println(“Initializing…”);
delay(1000);

mySerial.println(“AT”); //Once the handshake test is successful, it will back to OK
updateSerial();

mySerial.println(“AT+CMGF=1”); // Configuring TEXT mode
updateSerial();
mySerial.println(“AT+CMGS=”+ZZxxxxxxxxx"");//change ZZ with country code and xxxxxxxxxxx with phone number to sms
updateSerial();
mySerial.print(“test”); //text content
updateSerial();
mySerial.write(26);
delay(60000);
}

void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(mySerial.available())
{
Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
}
}

Where do you ever call the reset() function?

#include <SoftwareSerial.h>
int rst = 12;

//Create software serial object to communicate with A6
SoftwareSerial mySerial(3, 2); //A6 Tx & Rx is connected to Arduino #3 & #2

void reset()
{
digitalWrite(rst,HIGH);
pinMode(rst,OUTPUT);
delay(200);
digitalWrite (rst,LOW);
}

OK, but where do you call it ?

Why do you write to rst before setting its pinMode() ?

@musiba, you need to answer the question in reply #1.

Because the Arduino should be rested because the code runs once and if you close and opened the serial monitor it will send the message that's why

if you close and opened the serial monitor it will send the message

That is because opening the Serial monitor resets the Arduino. Your latest post sounds like you think that is a bad thing but the title of the topic seems to indicate that you want the Arduino to reset when powered up, which is what it does

Can we please have a simple statement of your requirements ?

I’m surprised this has not come up yet:

Read “How To Use This Forum”

in particular, 7. If you are posting code or error messages, use “code” tags

This is what happens when you do not

if you have a module that is not working, do not say “A GPS” or “the fingerprint sensor”. Show us a link to the particular sensor, and a link to the datasheet if available

musiba:
but I want it to reset itself once when it is powered.

musiba:
Because the Arduino should be rested because the code runs once and if you close and opened the serial monitor it will send the message that's why

Do you really mean (by the first piece I have quoted) that you want the Arduino to reset itself while the power is on.

I (and I think everyone else) thought you meant that you want it to reset when the power is turned on - which is what it normally does.

And if you really do want the Arduino to reset itself while the power is on then there is still the question "why". You can leave an Arduino happily running for years.

If you just want a piece of code to run occasionally - perhaps every time someone presses a button, or at regular time intervals - that can be easily done without resetting the Arduino.

...R