Skip to main content
Fixed typo.
Source Link
Nick Gammon
  • 38.9k
  • 13
  • 70
  • 126
int inPin_0 = A0; // choose the input pin (sensor #1)
int inPin_1 = A1; // choose the input pin (sensor #2) //ADDED FOR SECOND BUTTON/

...

  senseval=SensorVal+String(inPin_0);
  senseval=SensorVal+String(inPin_1); //ADDED FOR SECOND BUTTON//

The above is wrong because you are sending the pin numbers and not the values read from those pins. You previously read them here:

  sensorSense_0=analogRead(inPin_0);
  ...
  sensorSense_1=analogRead(inPin_1); //ADDED FOR SECOND BUTTON//

It is sensorSense_0 and sensorSense_1 that you should be sending.

Also, as Damiano Verzulli pointed out, your second assignment soto senseval clobbers the first. You want something more like:

  senseval  = SensorVal + String(analogRead(inPin_0)) + ", ";
  senseval += SensorVal + String(analogRead(inPin_1)); 

Even that may not be perfect, I didn't read your PHP side.


Looking at the PHP side now:

$query = "INSERT INTO $tablename VALUES ($senseval,now())";

That isn't going to work too well for two values. I don't know your database schema, but that won't handle two values very well. A bit of tweaking and it might, or you could do two INSERT statements.

int inPin_0 = A0; // choose the input pin (sensor #1)
int inPin_1 = A1; // choose the input pin (sensor #2) //ADDED FOR SECOND BUTTON/

...

  senseval=SensorVal+String(inPin_0);
  senseval=SensorVal+String(inPin_1); //ADDED FOR SECOND BUTTON//

The above is wrong because you are sending the pin numbers and not the values read from those pins. You previously read them here:

  sensorSense_0=analogRead(inPin_0);
  ...
  sensorSense_1=analogRead(inPin_1); //ADDED FOR SECOND BUTTON//

It is sensorSense_0 and sensorSense_1 that you should be sending.

Also, as Damiano Verzulli pointed out, your second assignment so senseval clobbers the first. You want something more like:

  senseval  = SensorVal + String(analogRead(inPin_0)) + ", ";
  senseval += SensorVal + String(analogRead(inPin_1)); 

Even that may not be perfect, I didn't read your PHP side.


Looking at the PHP side now:

$query = "INSERT INTO $tablename VALUES ($senseval,now())";

That isn't going to work too well for two values. I don't know your database schema, but that won't handle two values very well. A bit of tweaking and it might, or you could do two INSERT statements.

int inPin_0 = A0; // choose the input pin (sensor #1)
int inPin_1 = A1; // choose the input pin (sensor #2) //ADDED FOR SECOND BUTTON/

...

  senseval=SensorVal+String(inPin_0);
  senseval=SensorVal+String(inPin_1); //ADDED FOR SECOND BUTTON//

The above is wrong because you are sending the pin numbers and not the values read from those pins. You previously read them here:

  sensorSense_0=analogRead(inPin_0);
  ...
  sensorSense_1=analogRead(inPin_1); //ADDED FOR SECOND BUTTON//

It is sensorSense_0 and sensorSense_1 that you should be sending.

Also, as Damiano Verzulli pointed out, your second assignment to senseval clobbers the first. You want something more like:

  senseval  = SensorVal + String(analogRead(inPin_0)) + ", ";
  senseval += SensorVal + String(analogRead(inPin_1)); 

Even that may not be perfect, I didn't read your PHP side.


Looking at the PHP side now:

$query = "INSERT INTO $tablename VALUES ($senseval,now())";

That isn't going to work too well for two values. I don't know your database schema, but that won't handle two values very well. A bit of tweaking and it might, or you could do two INSERT statements.

Source Link
Nick Gammon
  • 38.9k
  • 13
  • 70
  • 126

int inPin_0 = A0; // choose the input pin (sensor #1)
int inPin_1 = A1; // choose the input pin (sensor #2) //ADDED FOR SECOND BUTTON/

...

  senseval=SensorVal+String(inPin_0);
  senseval=SensorVal+String(inPin_1); //ADDED FOR SECOND BUTTON//

The above is wrong because you are sending the pin numbers and not the values read from those pins. You previously read them here:

  sensorSense_0=analogRead(inPin_0);
  ...
  sensorSense_1=analogRead(inPin_1); //ADDED FOR SECOND BUTTON//

It is sensorSense_0 and sensorSense_1 that you should be sending.

Also, as Damiano Verzulli pointed out, your second assignment so senseval clobbers the first. You want something more like:

  senseval  = SensorVal + String(analogRead(inPin_0)) + ", ";
  senseval += SensorVal + String(analogRead(inPin_1)); 

Even that may not be perfect, I didn't read your PHP side.


Looking at the PHP side now:

$query = "INSERT INTO $tablename VALUES ($senseval,now())";

That isn't going to work too well for two values. I don't know your database schema, but that won't handle two values very well. A bit of tweaking and it might, or you could do two INSERT statements.