Store data | Armazenar dados

I have some sensors (analog and digital) taking measurements of temperature, humidity, etc., and I would like to save their data on the computer (for example TIME: MINUTE - DATA). The Arduino is connected via USB. I researched some things, but I didn't find a "simple" or efficient way .. would anyone know how to help me?


Tenho alguns sensores (analógicos e digitais) fazendo medições de temperatura, umidade etc, e gostaria de salvar os dados deles no computador (por exemplo HORA:MINUTO - DADO). O Arduino fica conectado pelo USB. Pesquisei algumas coisas, mas não achei uma maneira "simples" ou eficiente.. alguém saberia me ajudar?

#include <DHT.h>;
#include <Wire.h> 
#include <OneWire.h> //INCLUSÃO DE BIBLIOTECA
#include <DallasTemperature.h> //INCLUSÃO DE BIBLIOTECA

#define DHTPIN 7 //PINO DIGITAL UTILIZADO PELO DHT22
#define DHTTYPE DHT22 //DEFINE O MODELO DO SENSOR (DHT22 / AM2302)
#define DS18B20 6 //DEFINE O PINO DIGITAL UTILIZADO PELO SENSOR

DHT dht(DHTPIN, DHTTYPE); //PASSA OS PARÂMETROS PARA A FUNÇÃO
OneWire ourWire(DS18B20); //CONFIGURA UMA INSTÂNCIA ONEWIRE PARA SE COMUNICAR COM O SENSOR
DallasTemperature sensors(&ourWire); //BIBLIOTECA DallasTemperature UTILIZA A OneWire

int UVOUT = A0; //Output from the sensor
int REF_3V3 = A1; //3.3V power on the Arduino board

void setup(){
  Serial.begin(9600); //INICIALIZA A SERIAL

  pinMode(UVOUT, INPUT); //ML8511
  pinMode(REF_3V3, INPUT); //ML8511
  
  dht.begin(); //INICIALIZA A FUNÇÃO DHT22
  sensors.begin(); //INICIA O SENSOR DS18B20
  
  delay(2000); //INTERVALO DE 2 SEGUNDO ANTES DE INICIAR
}
void loop(){
    Serial.print("DHT22: ");
    Serial.print("Umidade: "); //IMPRIME O TEXTO NA SERIAL
    Serial.print(dht.readHumidity()); //IMPRIME NA SERIAL O VALOR DE UMIDADE MEDIDO
    Serial.print("%"); //IMPRIME O TEXTO NA SERIAL 
    Serial.print(" / Temperatura: "); //IMPRIME O TEXTO NA SERIAL
    Serial.print(dht.readTemperature(), 2); //IMPRIME NA SERIAL O VALOR DE UMIDADE MEDIDO E REMOVE A PARTE DECIMAL
    Serial.println("*C"); //IMPRIME O TEXTO NA SERIAL

    Serial.print("DS18B20: ");
    sensors.requestTemperatures();//SOLICITA QUE A FUNÇÃO INFORME A TEMPERATURA DO SENSOR
    Serial.print("Temperatura: "); //IMPRIME O TEXTO NA SERIAL
    Serial.print(sensors.getTempCByIndex(0)); //IMPRIME NA SERIAL O VALOR DE TEMPERATURA MEDIDO
    Serial.println("*C"); //IMPRIME O TEXTO NA SERIAL

    Serial.print("ML8511: ");
    int uvLevel = averageAnalogRead(UVOUT);
  int refLevel = averageAnalogRead(REF_3V3);
    //Use the 3.3V power pin as a reference to get a very accurate output value from sensor
    float outputVoltage = 3.3 / refLevel * uvLevel;  
    float uvIntensity = mapfloat(outputVoltage, 0.99, 2.9, 0.0, 15.0);

    Serial.println("uvLevel=" + (String)uvLevel + " ");
    Serial.println("voltage=" + (String)outputVoltage + " ");
    Serial.println("uv=" + (String)uvIntensity + "(mW/cm^2)");
    Serial.println("------------------------------");
  
    delay(2000); //INTERVALO DE 2 SEGUNDOS * NÃO DIMINUIR ESSE VALOR (DHT22)
}

//Takes an average of readings on a given pin
//Returns the average
int averageAnalogRead(int pinToRead)
{
  byte numberOfReadings = 8;
  unsigned int runningValue = 0; 
  for(int x = 0 ; x < numberOfReadings ; x++)
    runningValue += analogRead(pinToRead);
  runningValue /= numberOfReadings;
  return(runningValue);  
}
//The Arduino Map function but for floats
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Tks!

A simple way, is to use a terminal program like Putty, and enable logging to a file.

aarg:
A simple way, is to use a terminal program like Putty, and enable logging to a file.

Can you teach me? Or at least refer me to a tutorial that you find interesting?

I already thank you for the answer and I will search on!

I doubt that there is a tutorial for what is really just a common feature of terminal programs. Just find one, and read the documentation on available options. All it does, is write whatever it receives without any modifications, to a log file of your choosing.

aarg:
I doubt that there is a tutorial for what is really just a common feature of terminal programs. Just find one, and read the documentation on available options. All it does, is write whatever it receives without any modifications, to a log file of your choosing.

Once again, thank you very much! I will do that.

If someone, in the future, wants to do something like this too, here are the two links I used. It works and is very efficient! Thanks!

Configuration explanation
ExtraPuTTY, more functions than PuTTY

I recommend ExtraPuTTY because it has a Timestamp,

Thank you aarg!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.