Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Arduino GSM & RF Controlled Sliding Gate

  • 21-08-2015 12:20pm
    #1
    Registered Users, Registered Users 2 Posts: 1,431 ✭✭✭




    I will do a proper schematic at some stage

    I have pieced together all the code for the Arduino by copying/pasting & modifying code to suit my needs from other projects on the web so its by no means mine and as it was freely available to me it is also freely available to you, I doubt that anyone will have full use of all the code but it may be handy for other things. The code itself is by no means perfect but it suits my needs and if anyone sees any mistakes or could offer any positive feedback then please do that.

    PLEASE NOTE: That I am no expert in coding so the terminology or lingo that I use most likely use will surely insult professionals but I hope folks get the general jist, the code does probably need a bit of tidying up but hey it works fine as is.

    The equipment list is as follows
    1. Arduino Mega 2560
    2. Sim900 Module - Connected via Serial 3
    3. DHT 22 - Reading Temp & Humidity
    4. 2 X 4 Relay Board
    5. ESP8266 - Connected via Serial 2 - Large drain on battery so connects to Wifi every three hours, powered via relay
    6. Arduino RF 433Mhz Module
    7. 2 X Limit Switches to check whether the gate is opened or closed
    8. DC DC Step down converter 3.3v(ESP8266) & 5v
    9. DC DC Step Up Boost Converter 24v to power IR beam
    10. 5 X 433Mhz Keyfob
    11. Solar charge controller
    12. 12v Worm Drive motor

    Relay configuration for controlling motor direction as it took a bit of figuring out
    2i03iir.jpg
    // Code cobbled together by Killian Mc Grath
    
    
    #include "Timer.h"
    #include "DHT.h"
    #include <RCSwitch.h>
    RCSwitch RFreciever = RCSwitch();
    
    Timer t;
    
    // Timer for checking battery
    // the timer object
    
    
    //Temp & humidity Sensor
    #define DHTTYPE DHT22 
    
    // Internet connection
    #define SSID "Your SSID"
    #define PASS "Your Password"
    #define IP "184.106.153.149"     // thingspeak.com
    #define key "Your Key"
    String response;
    boolean debug = true;
    #define esp8266 Serial2   // use esp8266 to talk to esp8266
    
    // Sim 900 Connection
    
    #define SIM900 Serial3  
    
    // constants won't change. 
    // set pin numbers:
    #define GOrelay 30// Gate Open to Relay
    #define GOrelay1 32// Gate Close to Relay
    #define GCrelay 26// Gate Open to Relay
    #define GCrelay1 28// Gate Close to Relay
    #define LsOpen 23// Limit Switch on Open Position
    #define LsClose 25// Limit Switch on Close Position
    #define irsensor 8// Connected to turn on power in the IR sensor to save power - Sensor only active while gate is closing
    #define batcheck 24// powers the relay to check battery
    #define irbeam 27// IR beam sensor
    #define Estop 2//5 Connected to the Emergency stop Button
    #define MnClose 31// Toggle switch in the cabinet to manually close the gateconst 
    #define MnOpen 33// Toggle switch in the cabinet to manually open the gate
    #define Manual 53// Toggle switch in the cabinet to manually open the gate
    #define ManChk 52// Toggle switch in the cabinet to manually check  battery status
    #define batMonPin A1// Battery monitor pin
    #define DHTPIN 22     // Temperature & Humidiy Sensor
    #define ESP 10     // Controls Transistor to turn on ESP8266
    #define RfRemote 18     // Data Pin from RF Remote
    DHT dht(DHTPIN, DHTTYPE);
    
    
    //Battery Monitor
            int val = 0;       // variable for the A/D value
            float pinVoltage = 0; // variable to hold the calculated voltage
            float batteryVoltage = 0;
            float ratio = 3.017;  // Changed to match the MEASURED ratio of the circuit
    //Battery Monitor end
    
    
      
    int var = 0; //int called var, this will be used as a time out for the relays, the a 1000ms delay each time the while loop.
    
    void setup() {
      
      // GSM Shield Setup
      SIM900power(); // Power UP Module
      Serial.begin(9600); // for serial monitor
      SIM900.begin(9600); // for GSM shield
      delay(3000);  // give time to log on to network.
      SIM900.print("AT+CMGF=1\r");  // set SMS mode to text
      delay(100);
      SIM900.print("AT+CLIP=1\r"); // turn on caller ID notification
      delay(100);
      
      // initialize the LED pin as an output:
      pinMode(GOrelay, OUTPUT);// Gate Open to Relay
      digitalWrite(GOrelay, HIGH);
      pinMode(GCrelay, OUTPUT); // Gate Close to Relay
      digitalWrite(GCrelay, HIGH);
        pinMode(GOrelay1, OUTPUT);// Gate Open to Relay
      digitalWrite(GOrelay1, HIGH);
      pinMode(GCrelay1, OUTPUT); // Gate Close to Relay
      digitalWrite(GCrelay1, HIGH);
      pinMode(batcheck, OUTPUT); 
      digitalWrite(batcheck, HIGH);
      pinMode(irsensor, OUTPUT);
    digitalWrite(irsensor, HIGH);  
      pinMode(LsOpen, INPUT); //digitalWrite(LsOpen, HIGH); 
      digitalWrite(LsOpen, HIGH); // Set LsOpen as a pull down resistor
    pinMode(Estop,INPUT_PULLUP); // Set Estop as a pull down resistor    
      pinMode(LsClose, INPUT);  
     digitalWrite(LsClose, HIGH);// Set LsClose as a pull down resistor
    pinMode(irbeam,INPUT_PULLUP); // Set irbeam as a pull down resistor
      pinMode(MnClose, INPUT);  
      digitalWrite(MnClose, HIGH);// Set manualclose as a pull down resistor
      pinMode(Manual, INPUT); 
      digitalWrite(Manual, HIGH);// Set Manual as a pull down resistor
      pinMode(ManChk, INPUT); 
      digitalWrite(ManChk, HIGH);// Set Manual as a pull down resistor
      pinMode(MnOpen, INPUT); 
      digitalWrite(MnOpen, HIGH); // Set MnOpen as a pull down resistor
      pinMode(ESP, OUTPUT); 
      digitalWrite(ESP, HIGH); // Turn Off ESP8266
      // ESP9266 Begin
    
    
    esp8266.begin(9600);
      Serial.begin(9600);
      delay(1000);
    
      Serial.println("Ready......");
      Serial.print("LS Open  ");
    Serial.println(digitalRead(LsOpen));
    Serial.print("LS Close  ");
    Serial.println(digitalRead(LsClose));
      
      long tickEvent = t.every(10800000, thingspeak);
    
      // Temperature & Humidiy Sensor
    dht.begin();
    
    //thingspeak();
    
    
    
    
    }
    
    String command;
    
    void SIM900power()
    // software equivalent of pressing the GSM shield "power" button
    {
      digitalWrite(9, HIGH);
      delay(1000);
      digitalWrite(9, LOW);
      delay(5000);
    }
    
    void loop()
    
    {
    
      
      // Enable interrupt for Rf Reciever
    RFreciever.enableReceive(5);  // Receiver on inerrupt 5 => that is pin #18
    
     t.update(); 
    
      if (SIM900.available() >0) // If there is an incoming messahe phone
      {
        char c = SIM900.read();
        if(c =='\n')
        {
          parseCommand(command);
          command = "";
        }
        
        else
        {
          command += c;
        }
      }
      if (RFreciever.available()) {
     
      long value; // Store the RF code as a long int  
        value = RFreciever.getReceivedValue();
          var = 0;
        if ((value == 555555) || (value == 5555556) || (value == 5555557) || (value == 5555558) || (value == 5555559)) {
          Serial.print("Correct Code Close ");
           Serial.println (value);
           RFreciever.resetAvailable(); // Clears value stored in RF module
           RFreciever.disableReceive(); // Disables interrupt while gate is moving
           GateClose();
        } 
        else if ((value == 44444444) || (value == 444444445) || (value == 444444446) || (value == 444444447) || (value == 444444448)) {
          Serial.print("Correct Code Open ");
           Serial.println (value);
           RFreciever.resetAvailable(); // Clears value stored in RF module
           RFreciever.disableReceive(); // Disables interrupt while gate is moving
           GateOpen();
        } 
    
         
        else if ((value == 1257475) || (value == 333333333) || (value == 3333333334) || (value == 3333333335) || (value == 3333333336)) {
          Serial.print("Correct Code Open walk ");
           Serial.println (value);
           RFreciever.resetAvailable(); // Clears value stored in RF module
           RFreciever.disableReceive(); // Disables interrupt while gate is moving
           openwalk();
        } 
    
        else if ((value == 5526320) || (value == 222222222) || (value == 2222222223) || (value == 2222222224) || (value == 2222222225)) {
          Serial.print("Correct Code Open half ");
           Serial.println (value);
           RFreciever.resetAvailable(); // Clears value stored in RF module
           RFreciever.disableReceive(); // Disables interrupt while gate is moving
           halfopen();
        } 
        
        
        else {
          Serial.print("Wwong Code ");
           Serial.println (value);
        }
    
        RFreciever.resetAvailable(); // Clears value stored in RF module
      }
      } 
    
    
    void parseCommand(String com)
    {
      String part1;
      String part2;
      String part3;
    
      
      part1 = com.substring(8, 18);  // Checks for 10 digit mobile number between characters 8 & 18
      part2 = com.substring(8, 19); // Checks for Landline +353
      part3 = com.substring(0, 6); // Check SMS for Gate Status
     command = "";
      
      if((part1.equalsIgnoreCase("08*********")) || (part1.equalsIgnoreCase("08*********")) || (part2.equalsIgnoreCase("+3530*********")))
      {
        Serial.print(com);
        Serial.println("... Is Calling");
    var = 0;
        String part1 = "";
        String part2 = "";
        delay(100); 
        openclose();
      }
    
      else if(part3.equalsIgnoreCase("Status")) //Reads incomming SMS for the word Status
      {
    
        statusmonitor();
      }
      else if(part3.equalsIgnoreCase("Batchk")) //Reads incomming SMS for the word Batchk
      {
    
        thingspeak();
      }
      else
     {
     }  
    }
    
    
    void openclose(){
    
    
    Serial.println("openclose");
    
    
    
      if((digitalRead(LsClose) == LOW)&& (var == 0)) // Pin 19 LimitSwClose
      {  
        Serial.println("LS Close is Low");   
        GateOpen();
      } 
      
    
      else if((digitalRead(LsOpen) == LOW)&& (var == 0)) // Pin 18 LimitSwOpen
      {
        Serial.println("LS Open is Low"); 
          GateClose();
      }
    
     else if (var == 0)
     {
      Serial.println("When in doubt close the gate");
      
      GateClose(); // If the gate is halfway open or closed then the gate will close
    
    }
        }
    
    /*****************************************************************
    * halfOpen() open gate 3 meter to drive through
    *****************************************************************/ 
    
     void halfopen(){
    RFreciever.resetAvailable(); // Clears value stored in RF module
    int var; //int called var, this will be used as a time out for the relays, the a 1000ms delay each time the while loop.
    var = 0;
      command = ""; //Clears the string
       Serial.println("Gate is Opening 3m");
       
       delay(2000);
    
       attachInterrupt(0,allstop,LOW); // Internal Interrupt on Pin 21 This is for Emergency Stop
    
    
    while((digitalRead(LsOpen) == HIGH) && (var < 80)) {
     digitalWrite(GOrelay, LOW);
     digitalWrite(GOrelay1, LOW);
     var = var + 1;
    delay(400);
    Serial.println(var);
    //Serial.println(LsOpen);
    }
    RFreciever.resetAvailable(); // Clears value stored in RF module
    digitalWrite(GOrelay, HIGH);
    digitalWrite(GOrelay1, HIGH);
    Serial.println("Gate is Open");
    detachInterrupt (0);
    
    loop();
    }
    
    /*****************************************************************
    * openwalk() open gate 1m to walk through
    *****************************************************************/ 
    
     void openwalk(){
    
    int var; //int called var, this will be used as a time out for the relays, the a 1000ms delay each time the while loop.
    var = 0;
      command = ""; //Clears the string
       Serial.println("Gate is Opening 1m ");
       Serial.println(var);
       Serial.println(digitalRead(LsOpen));
       delay(2000);
    
       attachInterrupt(0,allstop,LOW); // Internal Interrupt on Pin 21 This is for Emergency Stop
    
    
    while((digitalRead(LsOpen) == HIGH) && (var < 22)) {
     digitalWrite(GOrelay, LOW);
     digitalWrite(GOrelay1, LOW);
     var = var + 1;
    delay(400);
    Serial.println(var);
    //Serial.println(LsOpen);
    }
    RFreciever.resetAvailable(); // Clears value stored in RF module
    digitalWrite(GOrelay, HIGH);
    digitalWrite(GOrelay1, HIGH);
    Serial.println("Gate is Open");
    detachInterrupt (0);
    
    loop();
    }
    
    /*****************************************************************
    * GateOpen()
    *****************************************************************/ 
    
    
    void GateOpen(){
      RFreciever.resetAvailable(); // Clears value stored in RF module
    int var; //int called var, this will be used as a time out for the relays, the a 1000ms delay each time the while loop.
    var = 0;
      command = ""; //Clears the string
       Serial.println("Gate is Opening");
       
       delay(2000);
    
       attachInterrupt(0,allstop,LOW); // Internal Interrupt on Pin 21 This is for Emergency Stop
    
    
    while((digitalRead(LsOpen) == HIGH) && (var < 200)) {
     digitalWrite(GOrelay, LOW);
     digitalWrite(GOrelay1, LOW);
     var = var + 1;
    delay(400);
    Serial.println(var);
    //Serial.println(LsOpen);
    }
    RFreciever.resetAvailable(); // Clears value stored in RF module
    digitalWrite(GOrelay, HIGH);
    digitalWrite(GOrelay1, HIGH);
    Serial.println("Gate is Open");
    detachInterrupt (0);
    
     while (SIM900.available() >0) // Empties the buffer should the phone keep ringing
    {
      Serial.println("Waiting.....");
      delay(20);
      char incomingmessage = SIM900.read();
      Serial.println(incomingmessage);
    }
    delay(20);
      char incomingmessage = SIM900.read();
      Serial.println("Clearing Buffer" );
      Serial.println(incomingmessage);
      delay(20);
    Serial.println("SIM900 is clear");
    Serial.print("Var = ");
    Serial.println(var);
    
    loop();
    }
    /*****************************************************************
    * GateOpen()
    *****************************************************************/ 
    void GateClose(){
    RFreciever.resetAvailable(); // Clears value stored in RF module
    var = 0;
    command = ""; //Clears the string
       Serial.println("Gate is Closing");
    
    digitalWrite(irsensor, LOW);
    
     
     attachInterrupt(0,allstop,LOW); // Internal Interrupt on Pin 21 This is for Emergency Stop
    while((digitalRead(LsClose) == HIGH) && (var < 200)){ // If the loop takes more that 200 Var (Timer) the motor will stop
      while((digitalRead(irbeam) == LOW)){
        delay(2000);
        Serial.println("IRbeam is LOW");
        delay(2000);
        Serial.println("IRbeam is LOW 1");
        delay(2000);
        Serial.println("IRbeam is LOW 2");
        delay(2000);
        Serial.println("IRbeam is LOW 3");
      }
    digitalWrite(GCrelay, LOW);
    digitalWrite(GOrelay, LOW);
    digitalWrite(GCrelay1, LOW);
    digitalWrite(GOrelay1, LOW);
    var = var + 1;
    delay(400);
    Serial.println(var);
    //Serial.println(LsClose);
    delay(10);
    } 
    digitalWrite(GOrelay, HIGH);
    digitalWrite(GCrelay, HIGH);
    digitalWrite(GOrelay1, HIGH);
    digitalWrite(GCrelay1, HIGH);
    RFreciever.resetAvailable(); // Clears value stored in RF module
    detachInterrupt (0);
    delay(3000);
    digitalWrite(irsensor, HIGH);
    
    Serial.println("Gate is Closed");
    
     
     while (SIM900.available() >0) // Empties the buffer should the phone keep ringing
    {
      Serial.println("Waiting.....");
      delay(20);
      char incomingmessage = SIM900.read();
      Serial.println(incomingmessage);
    }
    delay(20);
      char incomingmessage = SIM900.read();
      Serial.println("Clearing Buffer" );
      Serial.println(incomingmessage);
      delay(20);
    Serial.println("SIM900 is clear");
    }
    /*****************************************************************
    * IRsense()
    *****************************************************************/ 
    
    void IRsense(){
      Serial.println("IRSnese Begin");
      delay(20);
      digitalWrite(GOrelay, HIGH);
    digitalWrite(GCrelay, HIGH);
     digitalWrite(GOrelay1, HIGH);
    digitalWrite(GCrelay1, HIGH);
    delay(1000);
    Serial.println("IRsense end loop");
     delay(20);
    }
    
    /*****************************************************************
    * allstop()
    *****************************************************************/ 
    
    void allstop() //This is when the emergency stop button is pressed
    {
      Serial.println("Emergency Stop");
      delay(20);
      digitalWrite(GOrelay, HIGH);
    digitalWrite(GCrelay, HIGH);
     digitalWrite(GOrelay1, HIGH);
    digitalWrite(GCrelay1, HIGH);
    delay(3000);
    }
    
    /*****************************************************************
    * manuallyclose()
    *****************************************************************/ 
    void manuallyclose() // Manual close activated from toggle switch in cabinet
    {
      Serial.println("Manual Close");
      while((digitalRead(MnOpen) == LOW) && (digitalRead(LsClose) == HIGH)) // As long as the Toggle switch is held on or the limit switch deos not trip then the gate will close
    {
     digitalWrite(GCrelay, LOW);
    digitalWrite(GOrelay, LOW);
     digitalWrite(GCrelay1, LOW);
    digitalWrite(GOrelay1, LOW);
    }
    digitalWrite(GOrelay, HIGH);
    digitalWrite(GCrelay, HIGH); // Turn off power to the motor
    digitalWrite(GOrelay1, HIGH);
    digitalWrite(GCrelay1, HIGH); // Turn off power to the motor
    delay(3000); // Put in this delay to allow motor to stop
    loop();
    }
    /*****************************************************************
    * manuallyopen()
    *****************************************************************/ 
    void manuallyopen() // Manual close activated from toggle switch in cabinet
    {
      Serial.println("Manual Open");
      while((digitalRead(MnClose) == LOW) && (digitalRead(LsOpen) == HIGH)){ // As long as the Toggle switch is held on or the limit switch deos not trip then the gate will open
     digitalWrite(GOrelay, LOW);
     digitalWrite(GOrelay1, LOW);
    }
    digitalWrite(GOrelay, HIGH);// Turn off power to the motor
    digitalWrite(GOrelay1, HIGH);// Turn off power to the motor
    delay(3000); // Put in this delay to allow motor to stop
    }
    
    /*****************************************************************
    * statusmonitor()
    *****************************************************************/ 
    void statusmonitor() {
      // Check the battery
      digitalWrite(batcheck, LOW); // Turn on relay for voltage circuit
      delay(3000); // Wait 3 Seconds before reading
       if(digitalRead(LsClose) == LOW) // Pin 19 Gate Closed Sensor LimitSwOpen
     {
      Serial.println("Gate is Closed");        // message to send
      Serial.println(digitalRead(LsOpen));
      SIM900.println("AT + CMGS = \"+35387******\"");                                     // recipient's mobile number
      delay(100);
      SIM900.println("Gate is Closed");        // message to send
      delay(100);
    
      delay(5000);                                     // give module time to send SMS
     }  
    else if(digitalRead(LsOpen) == LOW) //Pin 18 Gate Open Sensor LimitSwClose
    
     {
      Serial.println("Gate is Open");
      Serial.println(digitalRead(LsClose));  // message to send
      SIM900.println("AT + CMGS = \"+3538******\"");                                     // recipient's mobile number
      delay(100);
      SIM900.println("Gate is Open");        // message to send
      delay(5000);                                     // give module time to send SMS
     }   
     else
     {
      Serial.println("Gate Status Unknown");        // message to send
      SIM900.println("AT + CMGS = \"+353876864726\"");                                     // recipient's mobile number, in international format
      delay(100);
      SIM900.println("Gate Status Unknown");        // message to send
      delay(5000);                                     // give module time to send SMS
     }  
     // Check the battery
     
      val = analogRead(batMonPin);    // read the voltage on the divider  
      Serial.println(analogRead(batMonPin));
      pinVoltage = val * 0.00488;       //  Calculate the voltage on the A/D pin
                                        //  A reading of 1 for the A/D = 0.0048mV
                                        //  if we multiply the A/D reading by 0.00488 then 
                                        //  we get the voltage on the pin.                                  
                                        
                                        
      
      batteryVoltage = pinVoltage * ratio;    //  Use the ratio calculated for the voltage divider
                                              //  to calculate the battery voltage
     
    Serial.print(batteryVoltage);        // message to send
      delay(100);
      Serial.println(" Volts");        // message to send
      delay(100);
      
      SIM900.print(batteryVoltage);        // message to send
      delay(100);
      SIM900.println(" Volts");        // message to send
      delay(100);
      SIM900.println((char)26);                       // End AT command with a ^Z, ASCII code 26
      delay(100); 
      SIM900.println();
      delay(5000);                                     // give module time to send SMS
                        
      SIM900.println("AT+CMGD=1,4"); // delete all SMS on SIM
      digitalWrite(batcheck, HIGH);
    
       while (SIM900.available() >0) // Empties the buffer should the phone keep ringing
    {
      Serial.println("Waiting.....");
      delay(20);
      char incomingmessage = SIM900.read();
      Serial.println(incomingmessage);
    }
    delay(20);
      char incomingmessage = SIM900.read();
      Serial.println("Clearing Buffer" );
      Serial.println(incomingmessage);
      delay(20);
    Serial.println("SIM900 is clear");
    
      
    }
    
    /*****************************************************************
    * wifi_connect()
    *****************************************************************/ 
    boolean wifi_connect(){
      // Change wifi mode
      delay(1000);
      data_send("AT+CWMODE=1");
      delay(1000);
      response_read();
      // Sign into wifi
      String cmd="AT+CWJAP=\"";
      cmd+=SSID;
      cmd+="\",\"";
      cmd+=PASS;
      cmd+="\"";
      delay(1000);
      data_send(cmd);
      delay(7000);
      response_read();
    }
    
    /*****************************************************************
    * data_send
    *****************************************************************/
    void data_send(String cmd){
      esp8266.println(cmd);
      response = ""; 
      response_read();
    } 
    
    /*****************************************************************
    * response_read
    *****************************************************************/
    void response_read(){
      char chr;
     while(esp8266.available())
     { chr = esp8266.read(); 
       if (debug == true){Serial.write(chr);}; 
       response += chr; 
     };
    }
    
    /*****************************************************************
    thingspeak()
    *****************************************************************/
    void thingspeak(){
    digitalWrite(ESP, LOW); // Turn on ESP Transistor
      wifi_connect();
      delay(400);
    // Temperature & Humidiy Sensor
      float h = dht.readHumidity();
      float t = dht.readTemperature();
    
      // check if returns are valid, if they are NaN (not a number) then something went wrong!
      if (isnan(t) || isnan(h)) {
        Serial.println("Failed to read from DHT");
      } else {
        Serial.print("Humidity: "); 
        Serial.print(h);
        Serial.print(" %\t");
        Serial.print("Temperature: "); 
        Serial.print(t);
        Serial.println(" *C");
      }
    
      // Check the battery
      digitalWrite(batcheck, LOW); // Turn on relay for voltage circuit
      delay(3000); // Wait 3 Seconds before reading
    
     // Check the battery
     
      val = analogRead(batMonPin);    // read the voltage on the divider  
        Serial.println(analogRead(batMonPin));
      pinVoltage = val * 0.00488;       //  Calculate the voltage on the A/D pin
                                        //  A reading of 1 for the A/D = 0.0048mV
                                        //  if we multiply the A/D reading by 0.00488 then 
                                        //  we get the voltage on the pin.                                  
                                        
                                        
      
      batteryVoltage = pinVoltage * ratio;    //  Use the ratio calculated for the voltage divider
                                              //  to calculate the battery voltage
     
    Serial.print(batteryVoltage);        // message to send
      delay(100);
      Serial.println(" Volts");        // message to send
      delay(100);
      
      SIM900.print(batteryVoltage);        // message to send
    
      digitalWrite(batcheck, HIGH);
      
     
      
      /// Send info to Thingspeak
      
      
      String cmd;
      String cmd2;  
     if (debug==true){Serial.println("****************************************");};
    // Set for Multi channel
    //data_send("AT+CIPMUX=1");
    //  delay(2000);
    // Start TCP Comms 
      cmd = "AT+CIPSTART=\"TCP\",\"";
      cmd += IP;
      cmd += "\",80";
      delay(1000);
      data_send(cmd);
      delay(1000);
      response_read();
    // Output value (and preceed with string length command)
      cmd = "GET /update?key=";
      cmd += key;
      cmd += "&field1=";
      cmd += batteryVoltage;
      cmd += "&field2=";
      cmd += t;  
      cmd += "&field3=";
      cmd += h;    
    // String length
      cmd2 =  "AT+CIPSEND=";
      cmd2 += (cmd.length()+2);
      delay(1000);
      data_send(cmd2);
      delay(1000);
      response_read();
    // Data output
      delay(1000);
      data_send(cmd);
      delay(1000);
      response_read();
    
     while (SIM900.available() >0) // Empties the buffer should the phone keep ringing
    {
      Serial.println("Waiting.....");
      delay(20);
      char incomingmessage = SIM900.read();
      Serial.println(incomingmessage);
    }
    delay(20);
      char incomingmessage = SIM900.read();
      Serial.println("Clearing Buffer" );
      Serial.println(incomingmessage);
      delay(20);
    Serial.println("SIM900 is clear");
    
    digitalWrite(ESP, HIGH); // Turn off ESP Transistor
    }
    
    


    Its about sharing information to help others and the post is a little bitzy, I could put more in but then where does it stop, so if there is any questions please ask.


Comments

  • Registered Users, Registered Users 2 Posts: 883 ✭✭✭Keplar240B


    Thanks

    Why did you put a dht 22 in there is that for craic I put a dht11(cheaper version 1 euro) in one of my projects for the craic works fine accurate.

    2.Sim900 Module you have to have a sim card is this for it to work? I have NOT looked in detail at arduino and mobiles yet but the projects I glanced at keep saying android phone why is that is there some symbiotic relation between arduino and android , not just gsm but Bluetooth as well , did you consider Bluetooth for this

    3 how did it work out cost wise compared
    To what you could have brought off shelf
    I just built an arduino project for 50 euros that I could brought in shop for about 20 LOL although mine has an x factor LOL

    How did you begin to research solar power?


  • Registered Users, Registered Users 2 Posts: 1,431 ✭✭✭Big Lar


    Keplar240B.

    DHT22 just seemed to be the newer model, I actually had a BMP085 Barometric Pressure module to put in also but that was conflicting with pins on one of the libraries so I had to leave it out.

    The Sim card:
    T'was the biggest learning curve and the biggest cost @ €40.00. You have to understand that I knew nothing of arduino before I started this project and nothing of Bluetooth also, however I did build a Bluetooth controlled robot car there a little while ago but the kids showed little interest so I scrapped it. But in saying all that GSM is the way to go as I can open the gate from anywhere, say for instance if a courier was to ring.


    How did I research the solar ? Trial and error, that's why I have the 140w panel sitting in the hall:pac:

    Started off with just 1 10w panel, then I added the Wifi module so I was afraid that that was consuming too much current, then added a second panel to compensate for that, the fear then was that the second panel would over charge the batteries and damage them so I added a charge controller, the charge controller itself consumes power so I added a third panel to cover that. I then put the wifi module on a relay to only connect every three hours for 30 seconds as that was consuming almost 150ma(guestimation) constantly so that's saved a lot. The 4th 10W panel on standby and if that don't keep up the charge over winter the 140w is going in.

    Cost wise:
    I could have bought the motor kit for around €400.00 and then run a cable out which would have probably cost another €250.00.

    I had the 2X12v batteries from another project, cost €50.00 each 2nd hand.
    All the electronics around €150.00 from my friends in china, I just clicked on the link for the worm drive motor in my original post and it says £67.00 :eek: but I only paid €12.50 for mine
    4 X 10w Solar Panels €90.00, have purchased 140w panel @ €140.00 and am holding tough installing that, will see how the winter treats the charging.
    Another €100.00 for various bits like IP67 rated boxes few cables and such.

    If it cost twice or three times that its well worth it for the education of it and as you say the X-factor :)

    What did you build ?


  • Registered Users, Registered Users 2 Posts: 883 ✭✭✭Keplar240B


    Big Lar wrote: »
    ....

    What did you build ?

    L-17 MSDU (multi sensory display unit) "Omega" *

    That's all I can say for now. ;)


    *patent pending


  • Registered Users, Registered Users 2 Posts: 462 ✭✭the_blackstuff


    Nice project. Just wondering what network provider did you get the sim card to run the gsm unit from? I'm researching a project currently using a similar shield and it looks like people are having trouble with their sim cards as they are all gone 3g/4g and most of these GSM units work better on a 2g sim which seem to be no longer available.

    Thanks in advance


  • Closed Accounts Posts: 1,342 ✭✭✭Whosthis


    Nice project. Just wondering what network provider did you get the sim card to run the gsm unit from? I'm researching a project currently using a similar shield and it looks like people are having trouble with their sim cards as they are all gone 3g/4g and most of these GSM units work better on a 2g sim which seem to be no longer available.

    Thanks in advance

    Thread caught my eye so just having a read, I'm no expert. I would assume it's the same sim and just like in a mobile phone you instruct the sim to operate only on the GSM network .


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 462 ✭✭the_blackstuff


    In theory it should be I think but it seems in a lot of cases they don't work. I've read of people having to contact the provider and get the 3g option turned off. It seems to work on some networks and not on others. O2 used to be the banker but now that its under the 3 umbrella it might not work anymore.

    just checking before i part with my cash


  • Registered Users, Registered Users 2 Posts: 1,431 ✭✭✭Big Lar


    Its a vodafone PAYG sim card, topped it up with €20.00 back in February and its working away since, used to have it that I could text the gate and it would reply back with the battery voltage but I don't use that anymore since its updating it to thingspeak.

    On the power side if anyone is interested I have added an extra 10w panel bringing it up to 40w to hopefully carry me over the winter but the next six weeks will tell all. https://thingspeak.com/channels/43426


  • Registered Users, Registered Users 2 Posts: 462 ✭✭the_blackstuff


    Many thanks for the reply, this information is very useful to me. The original ADAFRUIT shield i was looking at won't work for me without a 2g simcard. I didn't want to pay out extra for a 3g shield. I will go with the Sim900 Module and a Vodafone sim.

    Thanks Again


  • Registered Users, Registered Users 2 Posts: 1,431 ✭✭✭Big Lar




  • Registered Users, Registered Users 2 Posts: 883 ✭✭✭Keplar240B


    IF ya don't keep putting credit in the Sim card would the Phone company not just cancel it eventually?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,431 ✭✭✭Big Lar


    I dunno they havent done it yet anyways :)


Advertisement