c - send SMS for 1 time with arduino GPRS SIM900 if an iput is HIGH -


i faced problem send 1 sms if input high,and if low==> no sms send,if low high==> send 1 sms. code not working,just sent sms when turn gprs on,and after nothing happened.

mclopez helped me,thank you,but not working :( , new code wrote delay()s,but same problem.

thank 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;   } 

try slowing down interval on interrupt. possible due several if statements running under isr_timer()that main loop may locking up. have sneaking suspicion trying much!

be careful trying execute complicated of interrupt @ high of frequency, or cpu may never enter main loop , program 'lock up'. reference

saying , check main loop running why not add simple debug @ bottom of main loop() flash on board led..

int onboardled = 13;  void setup()  {     pinmode(onboardled, output);      // , rest  }   void loop()  {     // doing stuff      if (onboardled == low) digitalwrite(ledpin, high);     else digitalwrite(ledpin, low);  } 

at least know if main loop() executing. runs once getting single sms through no other way of telling guess after that...

if looks try adding further flags around place see whats getting executed , not. other suggestion cant spot further interested find out! best of luck

update
dug link out of bookmarks. may find useful.
- nick gammon - interrupts


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -