Author Options:

Arduino code help using dtostrf() Answered

I need help with an arduino code that I can't figure out. I am really inexperienced with arduino, so sorry if this seems stupid.

I am trying to get my arduino to measure voltage of 2 analog inputs and send the data to a microSD on a shield.

I know I have to use the dtostrf() function, because a friend told me, and I trust him, but he won't tell me how to do it.

How do I get it to work like this using the dtostrf function?


Here is the void loop part of my code, with the incorrect attempt at using the function.

void loop()
String dataString = "";
  for (int analogPin = A0; analogPin < A2; analogPin++)
    int sensor = analogRead(analogPin);
    float sensorValue = ((float)(sensor) *(5.0/1023.0));
   dtostrf(sensorValue, A0, A1);
    if (analogPin < A2) {
      dataString += " ";

    File dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (dataFile) {

  else {
    Serial.println("error opening datalog.txt");