setting new void functions

Hello!

I am having some trouble with my code, i have a three load cells setup, I wanted to start by getting a "zero" weight on all three load cells and then constantly monitor the load cell weight. but i am unable to compile the code, could someone look at my code and tell me what i am doing wrong?

Thank you

void setup()
{
// put your setup code here, to run once:
SerialUSB.begin(9600); // initialize serial communication
}

void loop()
{
int sensorValue1 = analogRead(A0); // A0 as input from loadcell 1
int sensorValue2 = analogRead(A1); // A1 as input from loadcell 2
int sensorValue3 = analogRead(A2); // A2 as input from loadcell 3

if (SerialUSB.available() == 1);
{
zero();
}

float voltage1 = sensorValue1 * (5.0 / 3420.0);
long int W1 = (voltage1/0.01);

float voltage2 = sensorValue2 * (5.0 / 3420.0);
long int W2 = (voltage2/0.01);

float voltage3 = sensorValue3 * (5.0 / 3420.0);
long int W3 = (voltage3/0.01);

int d1 = (W1 - zW1);
int d2 = (W2 - zW2);
int d3 = (W3 - zW3);

if (d1 > 10)
{
SerialUSB.println("Watch out!"):
}
if (d2 > 10)
{
SerialUSB.println("Watch Out!"):
}
if (d3 > 10)
{
SerialUSB.println("Watch Out!"):
}
if (d1 > 20)
{
SerialUSB.println("Watch Out!, Disable motor!!"):
}
if (d2 > 20)
{
SerialUSB.println("Watch Out! Disable motor!!"):
}
if (d3 > 20)
{
SerialUSB.println("Watch Out! Disable motor!!"):
}

}

void zero()
{
// aquring weight of furnace after preform staged in furnace.
int sensorValue1 = analogRead(A0); // A0 as input from loadcell 1
int sensorValue2 = analogRead(A1); // A1 as input from loadcell 2
int sensorValue3 = analogRead(A2); // A2 as input from loadcell 3

float zVoltage1 = sensorValue1 * (5.0 / 3420.0);
long int zW1 = (zVoltage1/0.01);

float zVoltage2 = sensorValue2 * (5.0 / 3420.0);
long int zW2 = (zVoltage2/0.01);

float zVoltage3 = sensorValue3 * (5.0 / 3420.0);
long int zW3 = (zVoltage3/0.01);
}

loadcell_setup.ino (1.69 KB)

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we're trying to read your code. Do not post double spaced code.

When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages". Click that button. Paste the error in a message here using code tags.

if (SerialUSB.available() == 1);

oops

thank you for the tip did not know about the auto format tool, i got the following error after the auto format.

Arduino: 1.8.5 (Windows 7), Board: "Arduino M0"

Build options changed, rebuilding all
C:\Users\gvarghese\Documents\Arduino\loadcell\loadcell_setup\loadcell_setup.ino: In function 'void loop()':

loadcell_setup:29: error: 'zW1' was not declared in this scope

int d1 = (W1 - zW1);

^

loadcell_setup:30: error: 'zW2' was not declared in this scope

int d2 = (W2 - zW2);

^

loadcell_setup:31: error: 'zW3' was not declared in this scope

int d3 = (W3 - zW3);

^

loadcell_setup:35: error: expected ';' before ':' token

SerialUSB.println("Watch out!"):

^

loadcell_setup:39: error: expected ';' before ':' token

SerialUSB.println("Watch Out!"):

^

loadcell_setup:43: error: expected ';' before ':' token

SerialUSB.println("Watch Out!"):

^

loadcell_setup:47: error: expected ';' before ':' token

SerialUSB.println("Watch Out!, Disable motor!!"):

^

loadcell_setup:51: error: expected ';' before ':' token

SerialUSB.println("Watch Out! Disable motor!!"):

^

loadcell_setup:55: error: expected ';' before ':' token

SerialUSB.println("Watch Out! Disable motor!!"):

^

exit status 1
'zW1' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

//


void setup()
{
  // put your setup code here, to run once:
  SerialUSB.begin(9600);       // initialize serial communication
}

void loop()
{
  int sensorValue1 = analogRead(A0);         // A0 as input from loadcell 1
  int sensorValue2 = analogRead(A1);         // A1 as input from loadcell 2
  int sensorValue3 = analogRead(A2);         // A2 as input from loadcell 3


  if (SerialUSB.available() == 1);
  {
    zero();
  }

  float voltage1 = sensorValue1 * (5.0 / 3420.0);
  long int W1    = (voltage1 / 0.01);

  float voltage2 = sensorValue2 * (5.0 / 3420.0);
  long int W2    = (voltage2 / 0.01);

  float voltage3 = sensorValue3 * (5.0 / 3420.0);
  long int W3    = (voltage3 / 0.01);

  int d1 = (W1 - zW1);
  int d2 = (W2 - zW2);
  int d3 = (W3 - zW3);

  if (d1 > 10)
  {
    SerialUSB.println("Watch out!"):
    }
    if (d2 > 10)
  {
    SerialUSB.println("Watch Out!"):
    }
    if (d3 > 10)
  {
    SerialUSB.println("Watch Out!"):
    }
    if (d1 > 20)
  {
    SerialUSB.println("Watch Out!, Disable motor!!"):
    }
    if (d2 > 20)
  {
    SerialUSB.println("Watch Out! Disable motor!!"):
    }
    if (d3 > 20)
  {
    SerialUSB.println("Watch Out! Disable motor!!"):
    }


  }

  void zero()
{
  // aquring weight of furnace after preform staged in furnace.
  int sensorValue1 = analogRead(A0);         // A0 as input from loadcell 1
  int sensorValue2 = analogRead(A1);         // A1 as input from loadcell 2
  int sensorValue3 = analogRead(A2);         // A2 as input from loadcell 3

  float zVoltage1 = sensorValue1 * (5.0 / 3420.0);
  long int zW1    = (zVoltage1 / 0.01);

  float zVoltage2 = sensorValue2 * (5.0 / 3420.0);
  long int zW2    = (zVoltage2 / 0.01);

  float zVoltage3 = sensorValue3 * (5.0 / 3420.0);
  long int zW3    = (zVoltage3 / 0.01);
}

if (SerialUSB.available() == 1);Oops.

You need to broaden the scope of the variables zW from zero() to global scope.

Please also use code tags when you post warning/error messages. The reason is that the forum can mistake some parts of the text for forum markup, leading to confusion. This also makes the output easier to read because the lines are not wrapped.

gvarghese:

loadcell_setup:35: error: expected ';' before ':' token

SerialUSB.println("Watch out!"):

Statements should end in a semicolon ( ; ), not a colon ( : ).

How can i make it a global variable? i tried moving the "zero" part of the code to run inside the void loop but i am getting the same error, "zW1" is not declared.

Please read this:
https://www.arduino.cc/reference/en/language/variables/variable-scope--qualifiers/scope/

It seems a lot easier, faster less embarrassing and more resourceful to type, "was not declared in this scope" into google.