Error and can't find the problem

I’m venturing into the world of wifi and controlling “stuff”. The portion of code for wifi works fine it’s own and the relay part works fine on it’s own.Something is giving the error -‘oneWire’ was not declared in this scope. For the life of me I can’t see where it is. Here’s the code - hopefully someone here can give me another set of eye’s on it. Thanks in advance.

#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>        // Include the Wi-Fi library

#define ONE_WIRE_BUS D16        //pin D0 on Nano
OneWire (ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

float Celcius = 0;
float Fahrenheit = 0;
int buttonClick = 0;
int last_ButtonClick - 0;

const char* ssid = "Jorgensen home";         // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = "Bonzo4321";     // The password of the Wi-Fi network


pinMode(D4, OUTPUT);        //marked D2 on Nano
pinMode(D5, OUTPUT);        //marked D1 on Nano
pinMode(D12, OUTPUT);       //marked D6 on Nano
pinMode(D13, OUTPUT);       //marked D7 on Nano
------------------------------------ -
digitalWrite(D4, HIGH);
digitalWrite(D5, HIGH);
digitalWrite(D12, HIGH);
digitalWrite(D13, HIGH);

void setup(void)
{
  const char* ssid = "Jorgensen home";         // The SSID (name) of the Wi-Fi network you want to connect to
  const char* password = "Bonzo4321";     // The password of the Wi-Fi network
  delay(10);
  Serial.println('\n');

  WiFi.begin(ssid, password);             // Connect to the network
  Serial.print("Connecting to ");
  Serial.print(ssid); Serial.println(" ...");

  int i = 0;
  while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
    delay(1000);
    Serial.print(++i); Serial.print(' ');

    Serial.println('\n');
    Serial.println("Connection established!");
    Serial.print("IP address:\t");
    Serial.println(WiFi.localIP());         // Send the IP address of the ESP8266 to the computer
  }

  void loop() { }

  Serial.begin(115200);
  sensors.begin();

  void loop(void)
  {
    if (Serial.available())
    {
      char  data = Serial.read();
      Serial.println(data);
      switch (data)
      {
        case '1':
          if {Fahrenheit < 32} digitalWrite(D4, D5, LOW); //turns heater on
          if {Fahrenheit > 35} digitalWrite(D4, D5, HIGH); //tuns heater off
          break;
        case '2':
          if {Fahrenheit < 68} digitalWrite(D12, D13, LOW); //turns heater on
          if {Fahrenheit > 72} digitalWrite(D12, D13, HIGH); //tuns heater off
          break;
      }
      sensors.requestTemperatures();
      Celcius = sensors.getTempCByIndex(0);
      Fahrenheit = sensors.toFahrenheit(Celcius);
      //Serial.print(" C  ");
      //Serial.print(Celcius);
      //Serial.print(" F  ");
      //Serial.println(Fahrenheit);
      delay(1000);
    }
  }

If you auto format your code (IDE Ctrl-T), you will see that all your function definitions after setup() are intended. This implies you are missing a closing '}' (which you are).

Also, you are not allowed to have two functions called loop() in your code.

Found the missing (}). Also deleted the extra loop (). But the error persists.

#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>        // Include the Wi-Fi library

#define ONE_WIRE_BUS D16        //pin D0 on Nano
OneWire (ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

float Celcius = 0;
float Fahrenheit = 0;
int buttonClick = 0;
int last_ButtonClick - 0;

const char* ssid = "Jorgensen home";         // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = "Bonzo4321";     // The password of the Wi-Fi network


pinMode(D4, OUTPUT);        //marked D2 on Nano
pinMode(D5, OUTPUT);        //marked D1 on Nano
pinMode(D12, OUTPUT);       //marked D6 on Nano
pinMode(D13, OUTPUT);       //marked D7 on Nano
------------------------------------ -
digitalWrite(D4, HIGH);
digitalWrite(D5, HIGH);
digitalWrite(D12, HIGH);
digitalWrite(D13, HIGH);

void setup(void)
{
  const char* ssid = "Jorgensen home";         // The SSID (name) of the Wi-Fi network you want to connect to
  const char* password = "Bonzo4321";     // The password of the Wi-Fi network
  delay(10);
  Serial.println('\n');

  WiFi.begin(ssid, password);             // Connect to the network
  Serial.print("Connecting to ");
  Serial.print(ssid); Serial.println(" ...");

  int i = 0;
  while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
    delay(1000);
    Serial.print(++i); Serial.print(' ');
    Serial.println('\n');
    Serial.println("Connection established!");
    Serial.print("IP address:\t");
    Serial.println(WiFi.localIP());         // Send the IP address of the ESP8266 to the computer
  }
}

void loop() { }

Serial.begin(115200);
sensors.begin();
{
  if (Serial.available())
  {
    char  data = Serial.read();
    Serial.println(data);
    switch (data)
    {
      case '1':
        if {Fahrenheit < 32} digitalWrite(D4, D5, LOW); //turns heater on
        if {Fahrenheit > 35} digitalWrite(D4, D5, HIGH); //tuns heater off
        break;
      case '2':
        if {Fahrenheit < 68} digitalWrite(D12, D13, LOW); //turns heater on
        if {Fahrenheit > 72} digitalWrite(D12, D13, HIGH); //tuns heater off
        break;
    }
    sensors.requestTemperatures();
    Celcius = sensors.getTempCByIndex(0);
    Fahrenheit = sensors.toFahrenheit(Celcius);
    //Serial.print(" C  ");
    //Serial.print(Celcius);
    //Serial.print(" F  ");
    //Serial.println(Fahrenheit);
    delay(1000);
  }
}

Try…

#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>        // Include the Wi-Fi library

#define ONE_WIRE_BUS D16        //pin D0 on Nano
OneWire (ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

float Celcius = 0;
float Fahrenheit = 0;
int buttonClick = 0;
int last_ButtonClick - 0;

const char* ssid = "Jorgensen home";         // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = "Bonzo4321";     // The password of the Wi-Fi network


pinMode(D4, OUTPUT);        //marked D2 on Nano
pinMode(D5, OUTPUT);        //marked D1 on Nano
pinMode(D12, OUTPUT);       //marked D6 on Nano
pinMode(D13, OUTPUT);       //marked D7 on Nano
------------------------------------ -
digitalWrite(D4, HIGH);
digitalWrite(D5, HIGH);
digitalWrite(D12, HIGH);
digitalWrite(D13, HIGH);

void setup(void)
{
  const char* ssid = "Jorgensen home";         // The SSID (name) of the Wi-Fi network you want to connect to
  const char* password = "Bonzo4321";     // The password of the Wi-Fi network
  delay(10);
  Serial.println('\n');

  WiFi.begin(ssid, password);             // Connect to the network
  Serial.print("Connecting to ");
  Serial.print(ssid); Serial.println(" ...");

  int i = 0;
  while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
    delay(1000);
    Serial.print(++i); Serial.print(' ');
    Serial.println('\n');
    Serial.println("Connection established!");
    Serial.print("IP address:\t");
    Serial.println(WiFi.localIP());         // Send the IP address of the ESP8266 to the computer
  }
}

void loop() { /////////////////} 

Serial.begin(115200);
sensors.begin();
///////////////////////////////////{
  if (Serial.available())
  {
    char  data = Serial.read();
    Serial.println(data);
    switch (data)
    {
      case '1':
        if {Fahrenheit < 32} digitalWrite(D4, D5, LOW); //turns heater on
        if {Fahrenheit > 35} digitalWrite(D4, D5, HIGH); //tuns heater off
        break;
      case '2':
        if {Fahrenheit < 68} digitalWrite(D12, D13, LOW); //turns heater on
        if {Fahrenheit > 72} digitalWrite(D12, D13, HIGH); //tuns heater off
        break;
    }

    sensors.requestTemperatures();
    Celcius = sensors.getTempCByIndex(0);
    Fahrenheit = sensors.toFahrenheit(Celcius);
    //Serial.print(" C  ");
    //Serial.print(Celcius);
    //Serial.print(" F  ");
    //Serial.println(Fahrenheit);
    delay(1000);
  }
}

Change...

OneWire (ONE_WIRE_BUS);

To...

OneWire oneWire(ONE_WIRE_BUS);

Neither one of those suggestions have worked. Any other ideas?

Any other ideas?

Put on your glasses and go through your code carefully. It is a jumbled mess without a proper setup() and loop().

It is a long way from compiling and the error fixed with this change is only the start.

OneWire oneWire(ONE_WIRE_BUS);

There are many other syntax errors like instances of {} when there should be () and many other errors.

untested, but at least it has a proper setup() and loop()

#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>        // Include the Wi-Fi library

#define ONE_WIRE_BUS D16        //pin D0 on Nano
OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

float Celcius = 0;
float Fahrenheit = 0;
int buttonClick = 0;
int last_ButtonClick - 0;

const char* ssid = "Jorgensen home";         // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = "Bonzo4321";     // The password of the Wi-Fi network


pinMode(D4, OUTPUT);        //marked D2 on Nano
pinMode(D5, OUTPUT);        //marked D1 on Nano
pinMode(D12, OUTPUT);       //marked D6 on Nano
pinMode(D13, OUTPUT);       //marked D7 on Nano
------------------------------------ -
digitalWrite(D4, HIGH);
digitalWrite(D5, HIGH);
digitalWrite(D12, HIGH);
digitalWrite(D13, HIGH);

void setup(void)
{
  Serial.begin(115200);
  sensors.begin();

  const char* ssid = "Jorgensen home";         // The SSID (name) of the Wi-Fi network you want to connect to
  const char* password = "Bonzo4321";     // The password of the Wi-Fi network
  delay(10);
  Serial.println('\n');

  WiFi.begin(ssid, password);             // Connect to the network
  Serial.print("Connecting to ");
  Serial.print(ssid); Serial.println(" ...");

  int i = 0;
  while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
    delay(1000);
    Serial.print(++i); Serial.print(' ');
  }
  Serial.println('\n');
  Serial.println("Connection established!");
  Serial.print("IP address:\t");
  Serial.println(WiFi.localIP());         // Send the IP address of the ESP8266 to the computer
}


void loop()
{
  if (Serial.available())
  {
    char  data = Serial.read();
    Serial.println(data);
    switch (data)
    {
      case '1':
        if {Fahrenheit < 32} digitalWrite(D4, D5, LOW); //turns heater on
        if {Fahrenheit > 35} digitalWrite(D4, D5, HIGH); //tuns heater off
        break;
      case '2':
        if {Fahrenheit < 68} digitalWrite(D12, D13, LOW); //turns heater on
        if {Fahrenheit > 72} digitalWrite(D12, D13, HIGH); //tuns heater off
        break;
    }
    sensors.requestTemperatures();
    Celcius = sensors.getTempCByIndex(0);
    Fahrenheit = sensors.toFahrenheit(Celcius);
    //Serial.print(" C  ");
    //Serial.print(Celcius);
    //Serial.print(" F  ");
    //Serial.println(Fahrenheit);
    delay(1000);
  }
}

I’ve worked my way through the code and fixed quite a bit. I’m stuck on the if statements in the case area. If I comment out the “If”’ statements it will compile. Here’s the code. ERROR message follows.

#include <OneWire.h>
#include <DallasTemperature.h>
#include <ESP8266WiFi.h>        // Include the Wi-Fi library

#define ONE_WIRE_BUS 12        //pin D0 on Nano
OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

float Celcius = 0;
float Fahrenheit = 0;
int buttonClick = 0;
int last_ButtonClick = 0;

void setup()
{
  Serial.begin(115200);
  sensors.begin();

  const char* ssid = "Jorgensen home";         // The SSID (name) of the Wi-Fi network you want to connect to
  const char* password = "Bonzo4321";     // The password of the Wi-Fi network
  delay(10);
  Serial.println('\n');

  WiFi.begin(ssid, password);             // Connect to the network
  Serial.print("Connecting to ");
  Serial.print(ssid); Serial.println(" ...");

  int i = 0;
  while (WiFi.status() != WL_CONNECTED)  // Wait for the Wi-Fi to connect
  {
    delay(1000);
    Serial.print(++i); Serial.print(' ');
  }
  Serial.println('\n');
  Serial.println("Connection established!");
  Serial.print("IP address:\t");
  Serial.println(WiFi.localIP());         // Send the IP address of the ESP8266 to the computer

  pinMode(4, OUTPUT);        //marked D2 on Nano
  pinMode(5, OUTPUT);        //marked D1 on Nano
  pinMode(12, OUTPUT);       //marked D6 on Nano
  pinMode(13, OUTPUT);       //marked D7 on Nano
  //------------------------------------ -
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(12, HIGH);
  digitalWrite(13, HIGH);

}


void loop()
{
  if (Serial.available())
  {
    char  data = Serial.read();
    Serial.println(data);
    switch (data)
    {
      case 1:
        //if {Fahrenheit < 32) digitalWrite(4, 5, LOW);  //turns heater on
        //if {Fahrenheit > 35} digitalWrite(4, 5, HIGH); //tuns heater off
        break;
      case 2:
        //if {Fahrenheit < 68} digitalWrite(12, 13, LOW);  //turns heater on
        if {Fahrenheit > 72} digitalWrite(12, 13, HIGH); //tuns heater off
        break;
    }

    sensors.requestTemperatures();
    Celcius = sensors.getTempCByIndex(0);
    Fahrenheit = sensors.toFahrenheit(Celcius);
    //Serial.print(" C  ");
    //Serial.print(Celcius);
    //Serial.print(" F  ");
    Serial.println(Fahrenheit);
    delay(1000);
  }
}

ERROR code.

Arduino: 1.8.9 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"

C:\Users\16414\Desktop\Arduno code\garage_heat\garage_heat.ino: In function 'void loop()':

garage_heat:68:12: error: expected '(' before '{' token

         if {Fahrenheit > 72} digitalWrite(12, 13, HIGH); //tuns heater off

            ^

garage_heat:68:55: error: too many arguments to function 'void digitalWrite(uint8_t, uint8_t)'

         if {Fahrenheit > 72} digitalWrite(12, 13, HIGH); //tuns heater off

                                                       ^

In file included from sketch\garage_heat.ino.cpp:1:0:

C:\Users\16414\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\cores\esp8266/Arduino.h:179:6: note: declared here

 void digitalWrite(uint8_t pin, uint8_t val);

      ^

exit status 1
expected '(' before '{' token

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

Thanks for taking a look.

//if {Fahrenheit > 72}
if (Fahrenheit > 72)

This was mentioned in reply #6

There are many other syntax errors like instances of {} when there should be () and many other errors.

It think you are inputting a 1 or 2 from the Serial monitor to use in the switch case statement. Use single ' ' around the value to let the compiler know it is character '1' instead of numerical value 1.

char  data = Serial.read();
    Serial.println(data);
    switch (data)
    {
      case '1':
        break;
      case '2':
        break;
    }

Hi

A couple of thing to fix here:-

    switch (data)
    {
      case 1:
        //if {Fahrenheit < 32) digitalWrite(4, 5, LOW);  //turns heater on
        //if {Fahrenheit > 35} digitalWrite(4, 5, HIGH); //tuns heater off
        break;
      case 2:
        //if {Fahrenheit < 68} digitalWrite(12, 13, LOW);  //turns heater on
        if {Fahrenheit > 72} digitalWrite(12, 13, HIGH); //tuns heater off
        break;
    }
  1. Using { instead of ( in the conditions of the if statement.

  2. digitalWrite() only takes two variables not 3. If you want to set more than one pin you need more than one statement.

e.g.

      case 1:
        if (Fahrenheit < 32) {
            digitalWrite(4, LOW);  //turns heater on
            digitalWrite(5, LOW);
        }
        if (Fahrenheit > 35) {
            digitalWrite(4, HIGH); //tuns heater off
            digitalWrite(5, HIGH);
        }
        break;

Thanks guys.

I was using the Arduino IDE and the { & ( look the same on this computer. I setup Visual Studio as the IDE and it’s much better!!! Every thing’s working now.

Cattledog - you are right that I will pass the variables for the case statements. I’m making an App with VS to pass the variables.