Send SMS 1 time using arduino GPRS SIM900 if iput HIGH

I ran into the problem of sending 1 SMS if the input is HIGH, and if LOW ==> there is no sending SMS, if LOW to HIGH ==> send 1 SMS. this code does not work, just sent an SMS when I turned on GPRS, and after nothing happened.

mclopez helped me, thanks, but it didn’t work :(, this is the new code that I wrote using delay () s, but the same problem.

Thank you for helping in advance.

#include <SoftwareSerial.h> #include "TimerOne.h" const int DI = 2; const int DT = 3; const int DGP1 = 4; const int DGP2 = 5; const long interval = 100000; // in microseconds int value1 = 0; int value2 = 0; int value3 = 0; int value4 = 0; int value1_old = 0; int value2_old = 0; int value3_old = 0; int value4_old = 0; boolean changed1 = false; boolean changed2 = false; boolean changed3 = false; boolean changed4 = false; SoftwareSerial SIM900 (7, 8); void SIM900power(){ digitalWrite(9, HIGH); delay(1000); digitalWrite(9, LOW); delay(5000); } void initia(){ SIM900.print("AT+CMGF=1\r"); delay(100); SIM900.println("AT + CMGS = \"xxxxxxxxxx\""); delay(100); } void Send_SMS(){ SIM900.println((char)26); delay(100); SIM900.println(); delay(5000); } void isr_timer(){ if (changed2) { initia(); SIM900.println("Station 85: Defaut electrique"); delay(100); Send_SMS(); value2_old = value2; changed2 = false; } if (changed3) { initia(); SIM900.println("Station 85: DefautGP1"); delay(100); Send_SMS(); value3_old = value3; changed3 = false; } if (changed4) { initia(); SIM900.println("Station 85:DD>1000"); delay(100); Send_SMS(); value4_old = value4; changed4 = false; } } void setup() { pinMode(DI, INPUT); pinMode(DT, INPUT); pinMode(DGP1, INPUT); pinMode(DGP2, INPUT); SIM900.begin(19200); Timer1.initialize(interval); Timer1.attachInterrupt(isr_timer); } void loop() { value1 = digitalRead (DI); value2 = digitalRead (DT); value3 = digitalRead (DGP1); value4 = digitalRead (DGP2); if (value1 != value1_old && value1 == HIGH) changed1 = true; if (value2 != value2_old && value2 == HIGH) changed2 = true; if (value3 != value3_old && value3 == HIGH) changed3 = true; if (value4 != value4_old && value4 == HIGH) changed4 = true; value1_old = value1; value2_old = value2; value3_old = value3; value4_old = value4; } 
0
source share
1 answer

Try to slow the interrupt interval. It is possible that due to several if working under isr_timer() , the main loop may be blocked. I have a suspicious suspicion that you are trying to do too much!

Be careful when trying to perform an interruption that is too complex at too high a frequency, or the processor will never be able to enter the main loop and your program will close. Link

Saying this and checking that your main loop is actually running, why not add a simple debug file to the bottom of the main loop() to enable the flash drive on board.

 int onBoardLED = 13; void setup() { pinMode(onBoardLED, OUTPUT); // And all the rest } void loop() { // Doing stuff if (onBoardLED == LOW) digitalWrite(ledPin, HIGH); else digitalWrite(ledPin, LOW); } 

At least then you will find out if the main loop() is actually executing. Obviously, it starts once when you receive one SMS, but in fact, there is no other way to tell him the assumption after that ...

If everything looks good, try adding a few extra flags around the place to see what is being done and what is not. Other than this offer, I cannot find anything else, but it is interesting to know! Good luck.

Update
Just dug this link from my bookmarks. You may find this helpful. - Nick Gammon - Interrupts

0
source

Source: https://habr.com/ru/post/985413/


All Articles