Compiling issues

I have an older sketch that runs three temp sensors and two Humd sensors thru a multiplexer with no issues. This winter I wanted to add a load cell, but I can't get this bad boy to compile. I'm not a coder, I don't know all the fine points but I have the following error (I think I'm having a bracket issue) but can't put my finger on it. A fresh set of eyes may help.


'weight' was not declared in this scope

#define BLYNK_PRINT Serial
#include <Wire.h>

#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>

//#include <BlynkSimpleWiFiShield101.h>
#include <Adafruit_MCP9808.h>
#include <Adafruit_Si7021.h>
#include <Q2HX711.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "zkq5H0yYd*******************";

// Set password to "" for open networks.
char ssid[] = "Skynet";
char pass[] = "*****************";

#define calibration_factor -3750.0

#define SCALE_DATA_PIN  3
#define SCALE_CLOCK_PIN  2


#define TCAADDR 0x70

#define TCAADDR       0x70
#define TEMP1_ADDR    0x18
#define TEMP2_ADDR    0x18
#define TEMP3_ADDR    0x18
#define HUM1_ADDR     0x40
#define HUM2_ADDR     0x40

// Assign unique ID to each sensor
Adafruit_MCP9808 temp1 = Adafruit_MCP9808();
Adafruit_MCP9808 temp2 = Adafruit_MCP9808();
Adafruit_MCP9808 temp3 = Adafruit_MCP9808();
Adafruit_Si7021 hum1 = Adafruit_Si7021();
Adafruit_Si7021 hum2 = Adafruit_Si7021();

float temperature1;
float temperature2;
float temperature3;

float humidity1;
float humidity2;

long int loadcell;
long int tare;

void tcaselect(uint8_t i) {
  if (i > 7) return;

  Wire.write(1 << i);

void getWeight()

{  //String weight = String(scale.get_units(1), 2);
  weight = scale.get_units(1);

// standard Arduino setup()
void setup(void)

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  //these functions do not exist. you need to implement in firmware.
  //scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  //scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0


    //setup temp sensors:
    if (!temp1.begin(0x18))
      Serial.println("Couldn't find Temp1! Check your connections and verify the address is correct.");
    while (1);

  Serial.println("Found MCP9808, Sensor 1!");

  temp1.setResolution(0); // sets the resolution mode of reading, the modes are defined in the table bellow:
  // Mode Resolution SampleTime
  //  0    0.5°C       30 ms
  //  1    0.25°C      65 ms
  //  2    0.125°C     130 ms
  //  3    0.0625°C    250 ms

  if (!temp2.begin(0x18)) {
    Serial.println("Couldn't find Temp2! Check your connections and verify the address is correct.");
    while (1);

  Serial.println("Found MCP9808, Sensor 2!");


  if (!temp3.begin(0x18)) {
    Serial.println("Couldn't find Temp3! Check your connections and verify the address is correct.");
    while (1);

  Serial.println("Found MCP9808, Sensor 2!");



void loop(void)


  temperature1 = temp1.readTempF();
  //Display the results
  Blynk.virtualWrite(V7, temperature1);

  temperature2 = temp2.readTempF();
  Blynk.virtualWrite(V6, temperature2);

  temperature3 = temp3.readTempF();
  Blynk.virtualWrite(V5, temperature3);

  humidity1 = hum1.readHumidity();
  Blynk.virtualWrite(V4, humidity1);

  humidity2 = hum2.readHumidity();
  Blynk.virtualWrite(V3, humidity2);

  Blynk.virtualWrite(V2, 3);


Well, it's true. There is no declaration of the variable weight. It probably should be declared the same as
whatever scale.get_units(1) returns.

As the error says, weight was not declared anywhere in your code. You always need to declare variables before you use them in your code.

You do have a declaration here:


void getWeight()

{  //String weight = String(scale.get_units(1), 2);
 weight = scale.get_units(1);

but for some reason you commented it out.

You could fix the error by uncommenting that line, but the code is pointless. By declaring weight inside the getWeight function, you make it local to that function. When the function exits, weight goes out of scope, so you won't be able to access the weight reading anywhere else in your code. You could fix that by either making weight global by declaring it outside the getWeight function, or else change the return type of the getWeight function to String and return weight.

Paraphrasing the error message leaves out important information. Post the entire error message. There is a "copy error message" button in the lower right of the IDE window that makes it easy.