Pull Internet Password and Username from sd Card to sketch

I am working on a project that I would like to ultimately be able to run a Arduino WiFi program, from anywhere without having to mess with sketch directly. The goal here is to put the sd card in the computer to write the needed information, then the sketch will pull from that and use it.

Lately i’ve been playing around with SD examples and have learned how to store refresh rates and such in the SD card so that the arduino pulls the refresh rate from the SD card and uses it in the code.

I would like to know if the same can be done with WiFi

char ssid = “mynetwork”; // your network SSID (name)
char pass = “mypassword”; // your network password


I’ve included part of my code i’m experimenting with below, but am running into complications that I would greatly appreciate help with, and general feasibility advice as well

#include <SPI.h>
#include <WiFi.h>
#include <SD.h>         //SD Card Library
//char ssid[] = ssidName;     //  your network SSID (name)
//char pass[] = secretPassword;  // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status
String ssidName = "";
void setup() {
  //Initialize serial and wait for port to open:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
    File commandFile = SD.open("ssid.txt"); // name of file on SD card that it will read from
  if (commandFile)
    Serial.println("Reading Command File");
    // refresh rate based on number stored in SD card. 
    float decade = pow(10, (commandFile.available() - 1)); // size of number stores based on digits. ex 1000 = 1000; 500 = 100... basically 10 to the power (pow) bits in 1000 is 4 (number of digits), then minus 1 so it is 3. 
      float temp = (commandFile.read() - '0'); //minus '0' to make the programming laungage = 0
      //decade = decade/10;
      char ssid[] = temp//*decade+ssidName;
    Serial.print("SSID name is = ");
    Serial.print(char ssid[]);
    Serial.println("Could not read command file.");

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);

  String fv = WiFi.firmwareVersion();
  if ( fv != "1.1.0" )
    Serial.println("Please upgrade the firmware");

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:

  // you're connected now, so print out the data:
  Serial.print("You're connected to the network");

Ok, I got the code below to work for numbers, but it translates letters into numbers. Will someone please help me make this code for so that it brings up the proper password?

#include <SD.h>         //SD Card Library
#include <Wire.h>       //I2C Library
#include "ds3231.h"
//#include "rtc_ds3231.h"

#define BUFF_MAX 128

uint8_t time[8];
char MaxL[BUFF_MAX];
unsigned int recv_size = 0;
unsigned long prev, interval = 1000;

  int CS_pin = 4;
String pass_rate = "";

void setup()
  memset(MaxL, 0, BUFF_MAX);
  Serial.println("Initializing Card");
  //CS Pin is an output
  pinMode(CS_pin, OUTPUT);
  //Initialize Card
  if (!SD.begin(CS_pin))
      Serial.println("Card Failure");
  void loop()
  Serial.println("Card Ready");
  File PasswordFile = SD.open("Password.txt"); // name of file on SD card that it will read from
  if (PasswordFile)
    Serial.println("Reading Password File");
    float pdecade = pow(10, (PasswordFile.available() - 1));
      float pass = (PasswordFile.read() - '0');
      pass_rate = pass*pdecade+pass_rate;
      pdecade = pdecade/10;
    } Serial.print("Password is ");
    Serial.println("Could not read Password file.");

Did you ever get this working???

Yes, but the problem that I found out later on which caused me to scrap the project was the WiFi shield. If you'll load the basic wifi simple server code onto your arduino and use the webpage, the arduino will run for 6-7 minutes after you call the webpage then it will freeze and become unresponsive.

I tried many things, but couldn't figure out why using the wifi shield as a server would start a 6-7 minute timer which ultimately crashed the arduino. This was terribly frustrating to debug to find the crash wasn't my code, but the wifi shield firmware.

Try the simple wifi server example like I said and see if you get the same results.

well i am using the wifi shield to run a simple GET request when i comes in range of an access point.

I want that SSID and PSK to be changable via the sd card.

do you think you could share the way you got that to work. since i am using the wifi card as a client not a server i shouldnt run into the freeze issues you ran into.

The only thing i have noticed is even if i change the ssid and psk in the skecth the shield seems to hold the old information for a few connection ettempts before it switches. im not sure why it does that yet but its ok i just run a for statement for 3 tries with the wrong SSID then pull from the SD card to get the correect one. But i cant seem to get the info from the sd to the mySSID[] and myPSK[] fields

But i cant seem to get the info from the sd to the mySSID[] and myPSK[] fields

easy. lets say you have this up top

IPAddress ip(199,155,5,19);

I'm assuming you know how to pull the numbers from the sd card as an int. assign each number as an int.

int IP1=199;
int IP2=155;
int IP3=5;
int IP4=19;
then you have to IP format it.  
IPAddress NewIP(IP1, IP2, IP3, IP4);

That's all there is to it, I'm warning you though to save you time. I tried to use it as a client only too. I found that using it as a client only allowed the sketch to run for a few hours without problems, but it would freeze and become unresponsive within 12 hours every time once used as a client. The official arduino wifi shield is nothing but frustration.

Thank you

no problem, if you need any more help with it let me know. I would be curious if your sketch runs for a week with the wifi code being used without freezing. Right now, i'm trying to figure out how to run the arduino sketch on wordpress so I can access the server from anywhere