Can someone share code about send data from sensor to google sheet?

I’m doing some project IOT, but i dont know code send data from sensor to google sheet when using blynk app. can someone mine for share it?
sorry for my bad english

Maybe this will help get you started …

//-----------------------------------------------
//This sketch is combined from Adafruit DHT sensor and tdicola
//for dht.h library
//Along with some  esp8266 NodeMCU specifics from teos009    
// https://learn.adafruit.com/dht/overview
// https://gist.github.com/teos0009/acad7d1e54b97f4b2a88
//other Authors Arduino and associated Google Script:
//Aditya Riska Putra
//Ahmed Reza Rafsanzani
//Ryan Eko Saputro
//See Also
//http://jarkomdityaz.appspot.com/
//
//ELINS UGM
//
//Modified for Hackster.io project to the ESP8266 from
//a Ethernet Sheild project
//by Stephen Borsay
//Since Arduino can't handle https, we need to use Pushingbox API
//(uses http)to run 
//the Google Script (uses https).


#include "ESP8266WiFi.h"
#include "DHT.h"
#define DHTPIN 2    // what digital pin we're connected to
                    //pin2 to D4 on esp board

// Uncomment whatever DHT sensor type you're using!
#define DHTTYPE DHT11  // DHT 11
//#define DHTTYPE DHT21  // DHT 21
//#define DHTTYPE DHT22  // DHT 22

DHT dht(DHTPIN,DHTTYPE);


const char WEBSITE[] = "api.pushingbox.com"; //pushingbox API server
const String devid = "<YOUR_Devid_HERE>"; //device ID from Pushingbox 

const char* MY_SSID = "<YOUR_WIFI_NAME_HERE";
const char* MY_PWD =  "<YOUR_WIFI_PASSWORD_HERE>";


void setup()
{
  Serial.begin(115200);
  dht.begin();
  Serial.print("Connecting to "+*MY_SSID);
  WiFi.begin(MY_SSID, MY_PWD);
  Serial.println("going into wl connect");

  while (WiFi.status() != WL_CONNECTED) //not connected,..waiting to connect
    {
      delay(1000);
      Serial.print(".");
    }
  Serial.println("wl connected");
  Serial.println("");
  Serial.println("Credentials accepted! Connected to wifi\n ");
  Serial.println("");
}


void loop()
{
  
  //Wait between measurements longer then normal to slow donwn
  //google sheet populate, as We dont want to exceed free service quota
  delay(10000); //10 seconds, (sampling rate vs. service call quota)

  float humidityData = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float celData = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float fehrData = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(humidityData) || isnan(celData) || isnan(fehrData))
  {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index in Celsius (isFahreheit = false)
  float hicData = dht.computeHeatIndex(celData, humidityData, false);
  // Compute heat index in Fahrenheit (the default)
  float hifData = dht.computeHeatIndex(fehrData, humidityData);

  //Print to Serial monitor or Terminal of your chocice at 115200 Baud
  Serial.print("Humidity: ");
  Serial.print(humidityData);
  Serial.print(" %\t");
  Serial.print("Temperature in Cel: ");
  Serial.print(celData);
  Serial.print(" *C ");
  Serial.print("Temperature in Fehr: ");
  Serial.print(fehrData);
  Serial.print(" *F\t");
  Serial.print("Heat index in Cel: ");
  Serial.print(hicData);
  Serial.print(" *C ");
  Serial.print("Heat index in Fehr: ");
  Serial.print(hifData);
  Serial.print(" *F\n");
    
  WiFiClient client;  //Instantiate WiFi object

    //Start or API service using our WiFi Client through PushingBox
    if (client.connect(WEBSITE, 80))
      { 
         client.print("GET /pushingbox?devid=" + devid
       + "&humidityData=" + (String) humidityData
       + "&celData="      + (String) celData
       + "&fehrData="     + (String) fehrData
       + "&hicData="      + (String) hicData
       + "&hifData="      + (String) hifData
         );

      client.println(" HTTP/1.1"); 
      client.print("Host: ");
      client.println(WEBSITE);
      client.println("User-Agent: ESP8266/1.0");
      client.println("Connection: close");
      client.println();
      }
}

Thanks, btw when i run it and put blynk code my connection to blynk app was terminated, i can’t control anyting from blynk. Any idea?

@Gunner isn’t this where you step in? :wink:

@Shadeyman Haha :smile: … you started it :stuck_out_tongue:

Oh well… @Newbie1 We help you learn Blynk, not teach you how to program :wink: What you want to do is not a simple drop-in solution.

I suggest you click on the links at the top of this page (scroll up if you can’t see them) to the nearest Documents, Help Center and Sketch Builder pages, wherein you can to learn how Blynk works… This is a requirement in order to understand how to properly merge other code into functional Blynkified control.

As you learn about Blynk, we can assist… the rest is up to you.

1 Like

i already build some project using blynk to controlling or send notification, i only need one more thing, storing data from sensor to database or google sheet. I already test local server blynk but not work, stuck in PostgreSQL

You could have led with that :stuck_out_tongue_winking_eye:

Blynk uses it in the Local Server, but we (the community) don’t “support” or teach how it works… for that you need to go to…

PostgreSQL: Support

Is there are anyone have try use this? Using pushingbox to send data from sensor to google sheet

is there are any way to activated webhook not by button but when sensor active?

Your questions are related to this topic, so please don’t keep creating new topics.

You can send a webhook via button, slider, timer, function or whatever other method you chose via your code.

http://docs.blynk.cc/#widgets-other-webhook

Of course.

@Costas can you give me example of that? in BLYNK WRITE() or Blynk virtualWrite()?
Thank you

Have you got the basic push button Webhook working?
Which sensor are you going to be using?

Yes

I’m using raindrop sensor with analog input

Assuming Webhook is on V0.

With BlynkTimer read the raindrop sensor at say 10s intervals.

Create the function that reads the sensor, like the PUSH DATA example, and do a virtualWrite() of the value to V0.

Got it, Thanks

Is there are any way to change the interval time Blynk push notification? Right now every 15s i get notification

15s is the minimum frequency for PUSH and email notifications.

You need to add code if you want it less frequently but you can’t have it more frequent.

Need add code in arduino ? I try to find in blynk doc but i can’t find anything about that

Yes in the section where you check the sensor reading. Set a flag and a timeout for the frequency of notifications.