Sending push button data to cloud storage using NodeMcu

Hi, I’m working on a project where I’m counting push button presses. I want to send the count data to any cloud storage site using NodeMcu. Can you please guide me? I haven’t found any proper tutorial for this. Well, I faced another problem, every time the power supply to the Arduino was turned off and the power was supplied again, the count went back to zero. I wanted to start again from where I left. Like, if I turned off the power supply at count=6 , when I turn on the power supply, I want to start from 6. Is it possible to do this? The code for counting my push button pushes is given below:

#include <Wire.h>

#include <LiquidCrystal_I2C.h>



LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display





// this constant won't change:

const int  Up_buttonPin   = 7;    // the pin that the pushbutton is attached to

const int  Down_buttonPin = 8;


int buttonPushCounter = 0;    // counter for the number of button presses
int up_buttonState = 0;       // current state of the up button
int up_lastButtonState = 0;   // previous state of the up button

int down_buttonState = 0;         // current state of the up button
int down_lastButtonState = 0;     // previous state of the up button
bool bPress = false;


void setup()
{
  Serial.begin(9600);
  pinMode( Up_buttonPin , INPUT_PULLUP);
  pinMode( Down_buttonPin , INPUT_PULLUP);
  lcd.begin();
  lcd.setCursor(0, 0);
  lcd.print("pill dibo?");
  delay(3000);
  lcd.clear();
  lcd.print("Pills taken:");
  lcd.setCursor(2, 1);
  lcd.print(buttonPushCounter);
}
void loop()
{

 
  checkUp();
  checkDown();

  if ( bPress)
  {
    bPress = false;
    lcd.setCursor(2, 1);
    lcd.print("               ");
    lcd.setCursor(2, 1);
    lcd.print(buttonPushCounter);
  }
}
void checkUp()
{
  up_buttonState = digitalRead(Up_buttonPin);
  if (up_buttonState != up_lastButtonState)    // compare the buttonState to its previous state
  {
    if (up_buttonState == LOW)   // if the state has changed, increment the counter
    {
      bPress = true;  // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes: ");
      Serial.println(buttonPushCounter);
    }
    else {
      Serial.println("off"); // if the current state is LOW then the button went from on to off:
    }
    delay(50);  // Delay a little bit to avoid bouncing
  }

  up_lastButtonState = up_buttonState;   // save the current state as the last state, for next time through the loop
}

void checkDown()
{
  down_buttonState = digitalRead(Down_buttonPin);
  if (down_buttonState != down_lastButtonState)  // compare the buttonState to its previous state
  {
    if (down_buttonState == LOW)   // if the state has changed, increment the counter
    {
      bPress = true;
      buttonPushCounter--;  // if the current state is HIGH then the button went from off to on:
      Serial.println("on");
      Serial.print("number of button pushes: ");
      Serial.println(buttonPushCounter);
    } else {
      Serial.println("off");  // if the current state is LOW then the button went from on to off:
    }
    delay(50);            // Delay a little bit to avoid bouncing
  }
  down_lastButtonState = down_buttonState;  // save the current state as the last state, for next time through the loop

}

You can't ask Mr Cloud what the last number you sent was?

-jim lee

Hi sabit,

if you are very new to programming this project will serve you some hurdles if you adapt existing code.
Like with any other project in the same size will serve you some hurdles to overcome.
The hurdles are made of not yet understanding what the micrcontroller-code does. Adapting code is a bit more than entering a cheatcode into your keyboard for reaching the next level of a game.

You have to know some essential basics to make progress in your final project.

Learning to program

It will take some time to read this tutorial. But It will save you days of fiddling around or asking in the forum and waiting for answers.

I have some links to similar projects. But I'm posting them not yet. First thing is to learn the basics.

Storing a variables value for re-loading after power is on again: depending on how often you want to write this value using the SPIFF-memory or a FRAM-chip is suitable for this purpose.
Both things need some programming skills to implement.

best regards Stefan

Thanks a lot StefanL38