How to sample a analog data like sine wave and send to the cloud?

I want to send a complete analog data from a function generator to a cloud like Ubidots. I tried to read the analog data without sampling and plotting it on ubidots. it is coming. but not perfectly because of not sampling. can anyone help me how to sample the data and sending it into the cloud??

Welcome to the community.

Post what code you have and we can try and help.

Secondly - searching first is always a good thing - so if you search ubidots - this great thread is there which seems to do pretty much what you want …

#include "Ubidots.h"

#ifndef TOKEN
#define TOKEN "Your_Token"  // Put here your Ubidots TOKEN
#endif

Ubidots ubidots(TOKEN, UBI_TCP); // Comment this line to use another protocol.
//Ubidots ubidots(TOKEN, UBI_HTTP); // Uncomment this line to use HTTP protocol.
//Ubidots ubidots(TOKEN, UBI_UDP); // Uncomment this line to use UDP protocol

void setup() {
  Serial.begin(115200);
  //ubidots.setDebug(true); // Uncomment this line to print debug messages.
}

void loop() {
  float value1 = analogRead(A0);

  ubidots.add("Variable_Name_One", value1); // Change for your variable name.


  bool bufferSent = false;
  bufferSent = ubidots.send(); // Will send data to a device label that matches the device Id

  if(bufferSent){
    // Do something if values were sent properly
    Serial.println("Values sent by the device");
  }

  delay(1);
}

Firstly I would increase the delay in the loop to 300. delay(1) is too short for the Ubidots system - it will only accept data at a maximum of 4 dots per second.

Please remember for the future that folks would love to help you - but you need to do your research first.

1 Like

Adding to @shanevanj comments. When you say

I want to send a complete analog data from a function generator

Can you be a bit more descriptive about this signal, what are you trying to sample? The general rule with sampling is that it must be done at least twice the frequency of the signal. The other factor is the frequency of the signal and the time it takes to read an analog. Lastly, you cannot reliably and continuously sample directly from loop() because the device OS will be swapping threads or checking for cloud connection. Thus, you may need to sample for short periods within a single thread block or at least with interrupts disabled and store the readings to an array in RAM. There are faster versions of analogRead() - check out the reference docs.

1 Like

Reading the comments and suggestions above, it sounds like you could sample and store the signal for 1 second (say 100 data points), save each measurement with it’s unix timestamp. Then spend the next 25 seconds sending that data to UbiDots, at 4 dots per second, for the 1-second time series.

1 Like