Flood Detection System

Hello guys, I am new to arduino and I develop a system that can detect a flood coming using float switch. The concept are, if the water level have risen, it will send the data of 1 if not it will remain 0. But, the data i get only 0. Can i know what are the problems? And how can i solve it?

Here are my sketch, kindly help me with the code.

/********************************
 * Libraries included
 *******************************/
#include <Ethernet.h>
#include <SPI.h>
#include <UbidotsEthernet.h>

/********************************
 * Constants and objects
 *******************************/
/* Assigns the Ubidots parameters */
char const * TOKEN = "Here-Are-My-Ubidots-Token"; // Assign your Ubidots TOKEN
char const * VARIABLE_LABEL_1 = "sensor"; // Assign the unique variable label to send the data


/* 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 };

/* initialize the instance */
Ubidots client(TOKEN);

/********************************
 * Main Functions
 *******************************/
 int floatswitch = 7;
void setup() {
  Serial.begin(9600);
  pinMode(floatswitch, INPUT);
  //client.setDebug(true);// uncomment this line to visualize the debug message
  /* start the Ethernet connection */
  Serial.print(F("Starting ethernet..."));
  if (!Ethernet.begin(mac)) {
    Serial.println(F("failed"));
  } else {
    Serial.println(Ethernet.localIP());
  }
  /* Give the Ethernet shield a second to initialize */
  delay(2000);
  Serial.println(F("Ready"));
}

void loop() {

  Ethernet.maintain();

  /* Sensors readings */
  int x = digitalRead(floatswitch);

  /* Sending values to Ubidots */
  client.add(VARIABLE_LABEL_1, x);

 
  client.sendAll();
  delay(5000);

}

How is the input wired ?
Any pullup or pulldown resistors in place ?
What do you see if you print x (a truly awful name for a variable, by the way) after reading the input ?

This, I'd say, is a good example of where you should do things in steps.

I'd start with a sketch doing nothing but reading the pin where the float's connected and writing its value to the monitor.

That way, I'd know that the float is connected correctly and that I'm reading it properly. Then later when I add three libraries and other cr@p, if it doesn't work I can reasonably assume that what I just did broke it, and I can back the changes out until it works again.

Hi,
I'd plan the developpment either one way or another:

arduino -> sensors way: simulate the sensors input in a short routine of your software. Do ignore the rest of the -software- project and isolate the program portion that warns if the flooding sensors are sending 1,1,1, ... . Ignore the transmission hardware too (by the moment).

sensors -> arduino way: Make sure that the sensors do give "1" when they should. Mount them close to your lab and actuate them by hand in the first steps. Do check the "1" and "0" on the transmission input screws equipment.

Once you have solved those steps, you can check the transmission (once again do isolate the software and simulate everithing else) software/hardware.

And, then, connect everything and cross your fingers ...

Good luck

Regards

UKHeliBob:
How is the input wired ?
Any pullup or pulldown resistors in place ?
What do you see if you print x (a truly awful name for a variable, by the way) after reading the input ?

i already figure it out. Turn out my switch are broke. I replace the float switch with a simple button and it gave me the output i want. Now, i do not know how to send my raw data (1 or 0) to php script for processing and send it to my mysql database. I already find many example(most of it use temperature sensors) but do not understand the code.