Store sensor data in DB?

Hey, I just got my arduino a few days ago so my knowledge is still very limited both when it comes to programming and to the arduino itself, im trying to store some data to a db i have so i later on can show this information in php webpage. How am i doing this the easiest way?

This is the code im using, it detects temperature, moist, light, lets say i want to insert the value of these to my localhost DB once every 30 min, how am i doing this ? Any good beginners guides you can reccomend? having a hard time to find any simple enough.

(Im on windows 10)

const int temperaturePin = 0; int lightPin = A1; int lightValue = 0; int moistPin = A2; int moistValue = 0;

void setup() {

Serial.begin(9600); } void loop() { lightValue = analogRead(lightPin); moistValue = analogRead(moistPin); float voltage, degreesC, degreesF; voltage = getVoltage(temperaturePin); degreesC = (voltage - 0.5) * 100.0; degreesF = degreesC * (9.0/5.0) + 32.0;

Serial.print(" Temperatur: "); Serial.print(degreesC); Serial.println(" C"); Serial.print(" Ljus: "); Serial.println(lightValue); Serial.print(" Fukt: "); Serial.println(moistValue); Serial.println();

delay(2000); }

float getVoltage(int pin) { return (analogRead(pin) * 0.004882814);

}

Serial.print out to python.

http://pyserial.sourceforge.net/

Use python to format as a .csv file ready for something like a PHP graph plotting module.

Use the python script to upload the .csv to the web-server via FTP when you need a "refresh".

Use the various PHP graphing modules to plot the .csv data.

This is one way. Other ways could include a lot of database hell maybe...but I generally seem to have a fear about them ha!

This is one way. Other ways could include a lot of database hell maybe...but I generally seem to have a fear about them ha!

Databases are like anything else. Nothing to be afraid of when you know what you are doing.

OP: Most people that want to store data in a database use an Ethernet shield, and make a GET request to a script (often a php script) that actually does the work of getting the data from the name=value pairs in the GET request, and putting the data in the database.

rillzp: How am i doing this the easiest way? having a hard time to find any simple enough.

If, instead of

  Serial.print("  Temperatur: ");
  Serial.print(degreesC);
  Serial.println(" C");
  Serial.print("  Ljus: ");
  Serial.println(lightValue);
  Serial.print("  Fukt: ");
  Serial.println(moistValue);
  Serial.println();

You use something more realistic like

  Serial.print(degreesC);
  Serial.print(",");
  Serial.print(lightValue);
  Serial.print(", ");
  Serial.println(moistValue);

and, instead of the serial monitor, you send this to a proper terminal programme like RealTerm you can record the data therein as a CSV file for subsequent use however you want. Why you would ever want to go through a lot of Python hell to do a simple job like that is beyond me. Note that RealTerm is also able to use the PC clock to add time and or date to every line, which is something you will probably find useful.

If you use an older version of Excel, you can send the same data thereto using PLX-DAQ, which is a freebie macro which essentially turns Excel into a terminal. This means you can display graphs and/or data in real time. Again, Excel can provide the timestamping.

Or you can send the same data to Livegraph for much the same result, but I prefer PLX.

Similarly, you could record the same data to an on-board SD card for subsequent downloading, but this probably means you would also need to record the time from an on-board clock.