Error while compiling - does not name a type

Just try to clean up my program code. Therefore, my classes has relocated to different files, via New Tab.

Now when I try to initialize a class from the file *.ino I get the following error message:

28: error: ‘Weather’ does not name a type
Weather myWaether(0,300000); // initialized Class Weather
exit status 1
‘Weather’ does not name a type

Here my code: Weather.ino

// DHT library
#include <DHT.h>
#include <SPI.h>

#define DHTTYPE DHT22                         // DHT11 or DHT21 or DHT22
#define DHTPIN 2                              // DataPin for the DHT Module
DHT dht(DHTPIN, DHTTYPE);                     // Create instance DHT

class Weather
  // Class Member variables
  // These are initialized at startup
    long OnTime;                                // milliseconds of on-time
    long OffTime;                               // milliseconds of off-time
    volatile unsigned long previousMillis;      // will store last time LEDs was updatted
    float temperature;                          // lokal variable to store the temperature from DHT
    float humility;                             // lokal variable to store the humility from DHT

// Constructor - creates a weather instance
// and initiliazes the member varialbles and state
    Weather(long _on, long _off)
      OnTime = _on;
      OffTime = _off;
      previousMillis = 0;

    float readDHT_temperature(unsigned long currentMillis)
      // read the temperature from the DHT Module
      if ( currentMillis - previousMillis >= OnTime)
        float temperature = dht.readTemperature();          // read temperature
        if ( isnan(temperature) )                           // check
          Serial.println("Error - Can't read temperature from DHT!");
          return -1000;
          Serial.print("Temperature: "); Serial.print(temperature); Serial.println(" °C");
          return temperature;

    float readDHT_humility(unsigned long currentMillis)
      // read the humility from the DHT Module
      if ( currentMillis - previousMillis >= OnTime)
        float humility = dht.readTemperature();               // read temperature
        if ( isnan(humility) )                                // check
          Serial.println("Error - Can't read humility from DHT!");
          return -1000;
          Serial.print("Humility: "); Serial.print(humility); Serial.println(" %");
          return humility;

and here the main program:

// Ethernet
#include <Ethernet.h>

/* Deinition for Ethernet communikation */
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };    // MAC address for ethernet controller
IPAddress ip(UUU,XXX,YYY,ZZZ);                                // IP Address for ethernet controller

Weather myWaether(0,300000);                                 // initialized Class Weather

void setup() {
  // put your setup code here, to run once:
  Ethernet.begin(mac, ip);

void loop() {
  // put your main code here, to run repeatedly:


Why is the class named “does not name a type” if it exists in the * .ino file?


you should have a Weather.h and Weather.cpp to define your class, and your sketch should be the .ino and import the .h to know about the Weather class

see how libraries offering a class are organized and do something similar

You might also want to read this short tutorial

When you compile a sketch with multiple .ino files the Arduino IDE first concatenates all the .ino files into a single file, starting with the .ino file that matches the sketch folder name, followed by the rest of the .ino files in alphabetical order. This is the same as the order of the tabs shown in the IDE. So you need to make sure that the class definition occurs before you use it in your code.

I like to break any larger sketch into multiple .ino files and I will force the order I want by naming the files, for example, A10constants.ino, A20globals.ino, A30setup.ino, A40loop.ino, A50functions.ino. Then I can later insert other tabs within that order without having to rename them all.

Then I can later insert other tabs within that order without having to rename them all.

That reminds me of programming BASIC with line numbers and leaving gaps to avoid the need to renumber the gosubs and gotos.

Yes, that's where I got the idea. It definitely brings back some hazy memories of monochrome monitors in my childhood.

I remember when I first used a version of BASIC that did not have line numbers. At first I really couldn't see how it was ever going to work.

I just saw that's a thing a few months ago. What has the world come to?

Thanks pert!

After renaming the *.ino files in 01-includes.ino, 02-init.ino, 03-...., Main.ino, all works fine.