title: Arduino not reading float level switch signal
body: <p>Hey I am trying to set up a project at the moment, I have a float level switch connected to pin 2 of my Arduino board, the other end is connected to the 5v in on the arduino. </p>
  
  <p>I want to have the software display a message when the switch goes high but at the moment it goes straight to the message and I know that the switch is not set high as I have it in my hand.</p>
  
  <p>In future it will send a text message when the signal goes high, being used for flood monitoring using a float level switch.</p>
  
  <pre><code>#include "SIM900.h"
  #include &lt;SoftwareSerial.h&gt;
  #include "sms.h"
  
  SMSGSM sms;
  
  //To change pins for Software Serial, use the two lines in GSM.cpp.
  
  int numdata;    
  boolean started=false;
  char smsbuffer[160];    
  char n[20];    
  int closed=0;//Sets initial signal to 0    
  const int switchPin = 2;    
  int switchState = 0;         // current state of the button    
  int lastswitchState = 0;    // previous state of the button
  
  void setup()    
  {
    //Serial connection.    
    Serial.begin(9600);    
    Serial.println("GSM Shield for Flood Early Warning System \n");    
    pinMode(switchPin, INPUT);    
  
    //Start configuration of shield with baudrate.    
    //For http uses is recommended to use 4800 or slower.    
  }  
  
   void loop() {    
    closed=digitalRead(switchPin);    
    // compare the buttonState to its previous state    
    if (switchState != lastswitchState) {    
      // if the state has changed, increment the counter    
      if (switchState == HIGH) {    
        // if the current state is HIGH then the button    
        // wend from off to on:
  
        Serial.println("on");    
      } else {    
        // if the current state is LOW then the button    
        // wend from on to off:    
        Serial.println("off");    
      }
  
      // Delay a little bit to avoid bouncing    
      delay(50);    
    }
  
    // save the current state as the last state,    
    //for next time through the loop    
    lastswitchState = switchState;
  
  
   if (closed == HIGH) {    
     Serial.println ("Switch signal received"); 
  
    if (gsm.begin(2400)){    
      Serial.println("\n status=READY");    
      started=true;    
    }    
    else Serial.println("\n status=IDLE");
  
  
  
    if(started){
      //Enable this two lines if you want to send an SMS.
      if (sms.SendSMS("0871234567", "Arduino SMS"))//Number you wish to text and  the message to be sent
  
        Serial.println("\nSMS sent OK");//Alert for Serial monitor once sms sent
  
    }
  
   }
  
  }
  </code></pre>