Show Posts
Pages: 1 2 [3] 4
31  Using Arduino / Storage / Re: Where to put EEPROM.write to save memory cycle on: December 11, 2013, 01:33:50 pm
I am putting these option only if there is very short power failing.
For example, man sand sms to turn off water pump, it's not my problem if he forget to turn it off. My only worry is what if he turn on heat pump and shortly after that there is power fail only on second. The heat pump will stay off and he wouldnt know about it.
I dont want to put electronic for power loss detection.
32  Using Arduino / Storage / Re: Where to put EEPROM.write to save memory cycle on: December 10, 2013, 04:43:56 pm
I think I know how to put eeprom.write in void txt () but how to restore all four pins in Void setup () so in case of power loss i can restore to previous state.
Relays are used for starting up machines or heat system in house.
33  Using Arduino / Storage / Re: Where to put EEPROM.write to save memory cycle on: December 10, 2013, 04:36:53 pm
Here is my code:
Code:
#include <EEPROM.h>
// include the GSM library
#include <GSM.h>
// PIN Number for the SIM
#define PINNUMBER ""
// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;
#define gsm 9
int addr = 0;
unsigned char pins = 0;
void setup()
{
  gsmOn();
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Serial.println(F("SMS Messages Receiver"));
  // connection state
  boolean notConnected = true;

  // Start GSM connection
  while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println(F("Not connected"));
      delay(1000);
    }
  }
  sms.flush();  // delete all messages
  Serial.println(F("GSM initialized"));
  Serial.println(F("Waiting for messages"));
}
void loop()
{
  // If there are any SMSs available()
  if (sms.available())
  {
    RelaySMS();
    sms.flush();
    //Serial.println("MESSAGE DELETED");
  }
  delay(1000);
}
void gsmOn()
{
  // Takes 30 seconds to complete
  digitalWrite(gsm, HIGH);   // turn the Phone on
  delay(1000);
  digitalWrite(gsm, LOW);
  delay(5000);
}
void RelaySMS()
{
  char c;
  c=sms.read();         // procitaj sms
  if (c=='1')         // ako je prvi znak 1 uradi sledece:
  {
    txt(A3,A3);
  }
  else if (c=='2')
  {
    txt(A2,A2);
  }
  else if (c=='3')
  {
    txt(A1,A1);
  }
  else if (c=='4')
  {
    txt(A0,A0);
  }
}
/*void allstate()
 {
 String txtmsg = "";
 while(c=sms.read())
 txtmsg += c;
 //Serial.println("Sadrzaj sms-a:");
 //Serial.println(txtmsg);
 if (txtmsg.compareTo("status") == 0)
 {
 pinstate = digitalRead(A3);
 sms.remoteNumber(remoteNumber, 10);
 sms.beginSMS(remoteNumber);
 sms.print(pinstate);
 sms.endSMS();
 }
 }*/
void txt(int Relay, int pin)
{
  pinMode(Relay, OUTPUT);
  String txtmsg = "";
  int pinstate;
  char c;
  char remoteNumber[10];
  while(c=sms.read())
    txtmsg += c;
  Serial.println(F("Sadrzaj sms-a:"));
  Serial.println(txtmsg);
  if (txtmsg.compareTo("on") == 0)
  {
    digitalWrite(Relay, HIGH);
  }
  else if (txtmsg.compareTo("off") == 0)
  {
    digitalWrite(Relay, LOW);
  }
  else if (txtmsg.compareTo("status") == 0)
  {
    pinstate = digitalRead(pin);
    sms.remoteNumber(remoteNumber, 10);
    sms.beginSMS(remoteNumber);
    sms.print(pinstate);
    sms.endSMS();
  }
}
34  Using Arduino / Storage / Re: Where to put EEPROM.write to save memory cycle on: December 10, 2013, 03:33:16 pm
Do you think is better to put eeprom.writes in function for every relay or for all at once?
35  Using Arduino / Storage / Where to put EEPROM.write to save memory cycle on: December 10, 2013, 03:26:45 pm
Hi guys,
First of all I wrote a program with gsm shield to turn on and off 4 relays.
It's working ok but I want to add storing relay state so if there is a power fail all relay can turn back in previous state.
So I put eeprom.read at first palce in loop(), but I am afraid if I put eeprom.write at the end of loop after function (recieve sms) end it will soon reach maximum eeprom write.
Is it true or I am wrong.
36  Using Arduino / Programming Questions / Re: Help for code optimization on: December 05, 2013, 03:16:38 pm
Sorry people, but I am so stupid...  smiley-mad
I realize that I dont need all code that I post, all I need is:
Code:
void smsread()
{
  String txtmsg = "";
  while(c=sms.read())
    txtmsg += c;
  //Serial.println("Sadrzaj sms-a:");
  //Serial.println(txtmsg);
  if (txtmsg.compareTo("on") == 0)
  {
    digitalWrite(Relay1, HIGH);
  }
  else if (txtmsg.compareTo("off") == 0)
  {
    digitalWrite(Relay1, LOW);
  }
  else if (txtmsg.compareTo("status") == 0)
  {
    pinstate = digitalRead(A3);
    sms.remoteNumber(remoteNumber, 10);
    sms.beginSMS(remoteNumber);
    sms.print(pinstate);
    sms.endSMS();
  }
}
So I need to change pinstate = digitalRead(A3);
If first charaster is 1 c=1 than it must be A3, if it is 2 -> A2, 3 -> A1, 4 -> A0
37  Using Arduino / Programming Questions / Re: Help for code optimization on: December 05, 2013, 03:09:47 pm
And I also need help with this part:
Code:
c=sms.read();         // procitaj sms
  if (c=='1')         // ako je prvi znak 1 uradi sledece:
  {
    String txtmsg = "";
    while(c=sms.read())
      txtmsg += c;
    //Serial.println("Sadrzaj sms-a:");
    //Serial.println(txtmsg);
    if (txtmsg.compareTo("on") == 0)
    {
      digitalWrite(Relay1, HIGH);
    }
    else if (txtmsg.compareTo("off") == 0)
    {
      digitalWrite(Relay1, LOW);
    }
    else if (txtmsg.compareTo("status") == 0)
    {
      pinstate = digitalRead(A3);
      sms.remoteNumber(remoteNumber, 10);
      sms.beginSMS(remoteNumber);
      sms.print(pinstate);
      sms.endSMS();
    }
  }

How to make it 'dynamic' so to speak. How to make one function for all 4 relays?
38  Using Arduino / Programming Questions / Re: Help for code optimization on: December 05, 2013, 03:04:43 pm
I try to comment all Serial.print code. It's there for help only.
But I didn't get much more space.
I try to search for null-terminated C strings as "el_supremo" say but I dont understand very well.
I will try to optimize code in RelaySMS function so I can use same function for every relay.
39  Using Arduino / Programming Questions / Re: Help for code optimization on: December 05, 2013, 01:25:33 pm
Can you please explain me what is F() macro because I am begginer in arduino programming.
Thank you very much
40  Using Arduino / Programming Questions / Help for code optimization on: December 05, 2013, 01:02:43 pm
Hi everybody,
This is my first big project with arduino, and I need help.
Well I built arduino-gsm-relay controler and for his basic function I already manage to fill half of flash (atmega328p)
Can you help me with optimizing code, because if I want to add more functions like rs485 or ethernet I think there would be no more space for program.
Code is:
Code:
// include the GSM library
#include <GSM.h>
// PIN Number for the SIM
#define PINNUMBER ""
// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;
// Array to hold the number a SMS is retreived from
char remoteNumber[20];
int Relay1 = A3;
int Relay2 = A2;
int Relay3 = A1;
int Relay4 = A0;
int gsm = 9;
int pinstate;
char c;
String msg;
void setup()
{
  gsmOn();
  pinMode(Relay1, OUTPUT);
  //digitalWrite(Relay1, LOW);
  pinMode(Relay2, OUTPUT);
  //digitalWrite(Relay2, LOW);
  pinMode(Relay3, OUTPUT);
  //digitalWrite(Relay3, LOW);
  pinMode(Relay4, OUTPUT);
  //digitalWrite(Relay4, LOW);

  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Serial.println("SMS Messages Receiver");
  // connection state
  boolean notConnected = true;

  // Start GSM connection
  while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }
  sms.flush();  // delete all messages
  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");
}
void loop()
{
  // If there are any SMSs available()
  if (sms.available())
  {
    RelaySMS();
    // An example of message disposal
    // Any messages starting with # should be discarded
    /*    if(sms.peek()=='#')
     {
     Serial.println("Discarded SMS");
     sms.flush();
     }
     while(c=sms.read())
     Serial.print(c);
     
     Serial.println("\nEND OF MESSAGE");
     */
    // Delete message from modem memory
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }
  delay(1000);
}
void gsmOn()
{
  // Takes 30 seconds to complete
  digitalWrite(gsm, HIGH);   // turn the Phone on
  delay(1000);
  digitalWrite(gsm, LOW);
  delay(5000);
}
void RelaySMS()
{
  c=sms.read();         // procitaj sms
  if (c=='1')         // ako je prvi znak 1 uradi sledece:
  {
    String txtmsg = "";
    while(c=sms.read())
      txtmsg += c;
    Serial.println("Sadrzaj sms-a:");
    Serial.println(txtmsg);
    if (txtmsg.compareTo("on") == 0)
    {
      digitalWrite(Relay1, HIGH);
    }
    else if (txtmsg.compareTo("off") == 0)
    {
      digitalWrite(Relay1, LOW);
    }
    else if (txtmsg.compareTo("status") == 0)
    {
      pinstate = digitalRead(A3);
      sms.remoteNumber(remoteNumber, 20);
      sms.beginSMS(remoteNumber);
      sms.print(pinstate);
      sms.endSMS();
    }
  }
  else if (c=='2')
  {
    String txtmsg = "";
    while(c=sms.read())
      txtmsg += c;
    Serial.println("Sadrzaj sms-a:");
    Serial.println(txtmsg);
    if (txtmsg.compareTo("on") == 0)
    {
      digitalWrite(Relay2, HIGH);
    }
    else if (txtmsg.compareTo("off") == 0)
    {
      digitalWrite(Relay2, LOW);
    }
    else if (txtmsg.compareTo("status") == 0)
    {
      pinstate = digitalRead(A2);
      sms.remoteNumber(remoteNumber, 20);
      sms.beginSMS(remoteNumber);
      sms.print(pinstate);
      sms.endSMS();
    }
  }
  else if (c=='3')
  {
    String txtmsg = "";
    while(c=sms.read())
      txtmsg += c;
    Serial.println("Sadrzaj sms-a:");
    Serial.println(txtmsg);
    if (txtmsg.compareTo("on") == 0)
    {
      digitalWrite(Relay3, HIGH);
    }
    else if (txtmsg.compareTo("off") == 0)
    {
      digitalWrite(Relay3, LOW);
    }
    else if (txtmsg.compareTo("status") == 0)
    {
      pinstate = digitalRead(A1);
      sms.remoteNumber(remoteNumber, 20);
      sms.beginSMS(remoteNumber);
      sms.print(pinstate);
      sms.endSMS();
    }
  }
  else if (c=='4')
  {
    String txtmsg = "";
    while(c=sms.read())
      txtmsg += c;
    Serial.println("Sadrzaj sms-a:");
    Serial.println(txtmsg);
    if (txtmsg.compareTo("on") == 0)
    {
      digitalWrite(Relay4, HIGH);
    }
    else if (txtmsg.compareTo("off") == 0)
    {
      digitalWrite(Relay4, LOW);
    }
    else if (txtmsg.compareTo("status") == 0)
    {
      pinstate = digitalRead(A0);
      sms.remoteNumber(remoteNumber, 20);
      sms.beginSMS(remoteNumber);
      sms.print(pinstate);
      sms.endSMS();
    }
  }
}
41  Products / Arduino GSM Shield / GSM Library and atmega8 on: November 29, 2013, 07:46:03 am
Is there any way to change library so it can work with atmega8.
I have a working sketch with atmega328p but when I select arduino ng with atmega8 it wont compile.
42  Using Arduino / Programming Questions / Re: Help with my project for garage door arduino on: January 26, 2013, 03:13:22 pm
Yeeee
I solve the problem!!!
Function code  is below. I will post final code later..

Code:
void doorOpen()
{
  digitalWrite(relayA1Pin, LOW);
  while(digitalRead(limitA2Pin) == LOW)
  {
    delay(3000);
    digitalWrite(relayA2Pin, LOW);
    while(digitalRead(limitA1Pin) == LOW)
    {
    }   
    digitalWrite(relayA1Pin, HIGH);
  }
   digitalWrite(relayA2Pin, HIGH);
}
43  Using Arduino / Programming Questions / Re: Help with my project for garage door arduino on: January 26, 2013, 02:38:02 pm
Ok so I take your advice and repair my program.
Now when I press open on rf remote relayA1 start to open and continiue until limitA1 is open.
And then when limitA1 is close then relayA2 starts to open.
 here is new code:

Code:
// constants won't change. They're used here to
// set pin numbers:

#define limitA1Pin 2        // the number of the close door 1 safety switch
#define limitA2Pin 3        // the number of the open door 1 safety switch
#define limitB1Pin 4        // the number of the close door 2 safety switch
#define limitB2Pin 5        // the number of the open door 2 safety switch
#define rfOpenPin 6         // the number of the RF Supra input OPEN pin
#define rfClosePin 7        // the number of the RF Supra input CLOSE pin
#define relayA1Pin 8        // the number of output for door1
#define relayA2Pin 9        // the number of output for door2
#define relayB1Pin 10       // the number of output for door1
#define relayB2Pin 11       // the number of output for door2
#define ledPin 13
// variables will change:
int limitA1 = 0;
int limitA2 = 0;
int limitB1 = 0;
int limitB2 = 0;
int rfOpen = 0;
int rfClose = 0;
int relayA1 = 0;
int relayA2 = 0;
int relayB1 = 0;
int relayB2 = 0;

void setup()
{
  pinMode(limitA1Pin, INPUT);     // initialize the pin as an input:
  pinMode(limitA2Pin, INPUT);     // initialize the pin as an input:
  pinMode(limitB1Pin, INPUT);     // initialize the pin as an input:
  pinMode(limitB2Pin, INPUT);     // initialize the pin as an input:
  pinMode(rfOpenPin, INPUT);      // initialize the pin as an input:
  pinMode(rfClosePin, INPUT);     // initialize the pin as an input:
  pinMode(relayA1Pin, OUTPUT);    // initialize the pin as an output:
  pinMode(relayA2Pin, OUTPUT);    // initialize the pin as an output:
  pinMode(relayB1Pin, OUTPUT);    // initialize the pin as an output:
  pinMode(relayB2Pin, OUTPUT);    // initialize the pin as an output:
  pinMode(ledPin, OUTPUT);
}

void doorMoveA1()
{
  digitalWrite(relayA1Pin, LOW);
  while(digitalRead(limitA1Pin) == LOW)
  {
    // do nothing
  }
  digitalWrite(relayA1Pin, HIGH);
}
void doorMoveA2()
{
  digitalWrite(relayA2Pin, LOW);
  while(digitalRead(limitA2Pin) == LOW)
  {
    // do nothing
  }
  digitalWrite(relayA2Pin, HIGH);
}
void doorMoveB1()
{
  digitalWrite(relayB1Pin, LOW);
  while(digitalRead(limitB1Pin) == LOW)
  {
    // do nothing
  }
  digitalWrite(relayB1Pin, HIGH);
}
void doorMoveB2()
{
  digitalWrite(relayB2Pin, LOW);
  while(digitalRead(limitB2Pin) == LOW)
  {
    // do nothing
  }
  digitalWrite(relayB2Pin, HIGH);
}
void doorOpen()
{
    doorMoveA1();
    delay(3000);
    doorMoveA2();
}
void doorClose()
{
 
}

void loop()
{
digitalWrite(relayA1Pin, HIGH);
digitalWrite(relayA2Pin, HIGH);
digitalWrite(relayB1Pin, HIGH);
digitalWrite(relayB2Pin, HIGH);
rfOpen = digitalRead(rfOpenPin);
rfClose = digitalRead(rfClosePin);
  if (rfClose == HIGH) {     
     digitalWrite(ledPin, HIGH);
     doorOpen();   
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}
44  Using Arduino / Programming Questions / Re: Help with my project for garage door arduino on: January 26, 2013, 10:25:18 am
Thanks PaulS for the advice about names,  I will change that.
This is my first project with arduino. I was playing a little with it but nothing special.
All limit switches are made by simple button tutorial just like you said with pullup resistor.
I can make to open a doorA until limit switch is pressed, but I dont want to wait to open one wing to the end and then another.
How to make a function for exemple:

start to open wingA
Until limit switchA
Delay 3 sec
Start to open wingB
Until limit switchB
45  Using Arduino / Programming Questions / Re: Help with my project for garage door arduino on: January 26, 2013, 10:06:00 am
Maybe the hole concept I am doing is wrong?
Pages: 1 2 [3] 4