Ubidots Community

[SOLVED] Counter with button and ubidots lose information

Hi everyone,
I´m new in ubidots and I have found a problem that I hope someone could help me.
I need to make a counter with a push button and send the number to ubidots. When I push the botton I have a delay and some pulses are missing. If I disable the send to ubidots the scketch works well with the serial port.

I would like to know if there are any solution or what I’m doing wrong.

// this constant won't change:
const int  buttonPin = 2;    // the pin that the pushbutton is attached to

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

#include <Ethernet.h>
#include <SPI.h>
#include <UbidotsEthernet.h>
#define ID  "XXXXXXXX"  // Put here your Ubidots variable ID
//#define ID2 "Your_variable_ID2_here"
#define TOKEN  "XXXXXXXXX"  // Put here your Ubidots TOKEN

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 0, 177);

Ubidots client(TOKEN);

void setup() {
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  // give the Ethernet shield a second to initialize:
void loop() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      Serial.print("number of button pushes:  ");
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
    // Delay a little bit to avoid bouncing
  // save the current state as the last state,
  //for next time through the loop
  lastButtonState = buttonState;

void sendtoubidots() {
  client.add(ID, buttonPushCounter);

Hello @manman,

Sorry but I’m not able to reply your issue. I made a test with your code, I sent 100 pulses to Ubidots without missing one. Take a look of the images below:

Maybe, is an issue with your network!