Getting more than 1 sensor to work with Elegoo Mega2560 clone

Hi all,

I'm hoping this is a PEBCAK error, even though I'm just not seeing it. I'm also hoping this is just a lack of familiarity with Arduino IDE and Arduino software design.

I've poked around on the board and googled in general, and I get lots of great info about single sensors not working, but I didn't find anything where the individual components worked fine alone, but ran into trouble when trying to run multiple sensors off the same board.

Gear:
Elegoo clone of Arduino Mega 2560 board
Elegoo 37 Sensor kit (only using a couple of sensors, but wanted to note where they're from)
DHT11 sensor (from above kit) - Temp and Humidity
DS18B20 sensor (from above kit) - Temp only
NTC MF52 3950 sensor (from above kit) - Temp only, but has both Analog and Digital inputs. Only have the Analog hooked up atm. Also, it's wired in, but I've removed it from the code, but listing it as the leads are still attached.
LCD 1602 (from above kit) - Display

From Arduino IDE Board Info:
BN: Arduino Mega or Mega 2560

Problem:
I can get each of the above to work just fine all by themselves. No problem at all, so the sensors themselves are good. Same for the wiring, though I've tried to move them around some as part of the troubleshooting thus far.

The issue comes in when I'm trying to get more than 1 sensor to work at the same time.

The 2560 is powered by a 9v DC PSU that plugs into the power barrel connector. I thought it may be a draw issue when I was using only the USB for power.

Wiring pics are attached.

The issue here other than getting bad readouts is that I get random compiling errors based on the order in which I'm listing the devices. I've tried to comment to clearly define what each segment is covering though.

Right now, it's erroring on:
E:\Projects\EFS\Arduino\Functional_EFS_System.ino\Functional_EFS_System.ino.ino: In function 'void loop()':
Functional_EFS_System.ino:59:11: error: 'DHT11' was not declared in this scope
int chk = DHT11.read(DHT11PIN);
^~~~~
However, if I run this exact code (listed below as "exact code") by itself, it works fine.

Combo code that's having a wobbly-

/***********************************
Include libraries
***********************************/
#include <LiquidCrystal.h>                                // LCD
#include <OneWire.h>                                      // DS18B20 temperature module
#include <DallasTemperature.h>                            // DS18B20 temperature module
#include <dht11.h>                                        // DHT 11 temp/humidity module

/***********************************
Pre-Void Setup for LCD
***********************************/
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);                  // Set up pins 8 - 13

/***********************************
Pre-Void Setup for DS18B20 temperature module
***********************************/
#define ONE_WIRE_BUS 30                                    // Set up pin 30
/* Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)*/
OneWire oneWire(ONE_WIRE_BUS);
/*Pass our oneWire reference to Dallas Temperature. */ 
DallasTemperature sensors(&oneWire);

/***********************************
Pre-Void Setup for DHT11 temp/humidity module
***********************************/
#define DHT11PIN 40

void setup() {
/***********************************
Void General Setup
***********************************/
Serial.begin(9600);

/***********************************
Void Setup for LCD
***********************************/
// set up the LCD's number of columns and rows: 
lcd.begin(16, 2);
// Print a statis message to the LCD starting at row 0, position 0
lcd.print("Testing ");

/***********************************
Void Setup for DS18B20 temperature module
***********************************/  
sensors.begin ();

/***********************************
Void Setup for DHT temperature module
***********************************/
// None - Defined above with Serial.begin(9600);
} // End of void setup()

void loop() {
/***********************************
Void Loop for DHT temperature module
***********************************/
Serial.println();
int chk = DHT11.read(DHT11PIN);
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);
Serial.print("Temperature (C): ");
Serial.println((float)DHT11.temperature, 2);

/***********************************
Void Loop DS18B20 temperature module
***********************************/
/* call sensors. Request Temperatures () to issue a global temperature */
/*request to all devices on the bus*/ 
float floatDS18B20Temp;
// Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); /*Send the command to get temperatures*/ 
// Serial.println("DONE");
/*We use the function ByIndex, and as an example get the temperature from the first sensor only.*/ 
Serial.println(sensors.getTempCByIndex(0));

}

Exact code that works fine

#include <dht11.h>
#define DHT11PIN 40
dht11 DHT11;
void setup()
{
  Serial.begin(9600);
 }
void loop()
{
  Serial.println();
  int chk = DHT11.read(DHT11PIN);
  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);
  Serial.print("Temperature (C): ");
  Serial.println((float)DHT11.temperature, 2);
  delay(2000);
}

Output from above when it's ONLY the DHT code running:
22:32:25.958 -> Humidity (%): 46.00
22:32:25.958 -> Temperature (C): 24.00

Output from above when it's multiple sensor code running, and output has been limited to just the DHT output:
22:35:08.992 -> 0.0
22:35:08.992 -> 675283008.0

0% humidity with a temp of 675283008.0 C seems a little off to me.

Any help or hints would be greatly appreciated.

I recommend you using the DHT library from Adafruit. See how to use the DHT library with DHT sensor

You don’t have “dht11 DHT11;” in your combo code, try it now. What does “Pre-Void” mean?

/***********************************
Include libraries
***********************************/
#include <LiquidCrystal.h>                                // LCD
#include <OneWire.h>                                      // DS18B20 temperature module
#include <DallasTemperature.h>                            // DS18B20 temperature module
#include <dht11.h>                                        // DHT 11 temp/humidity module

/***********************************
Pre-Void Setup for LCD
***********************************/
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);                  // Set up pins 8 - 13

/***********************************
Pre-Void Setup for DS18B20 temperature module
***********************************/
#define ONE_WIRE_BUS 30                                    // Set up pin 30
/* Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)*/
OneWire oneWire(ONE_WIRE_BUS);
/*Pass our oneWire reference to Dallas Temperature. */
DallasTemperature sensors(&oneWire);

/***********************************
Pre-Void Setup for DHT11 temp/humidity module
***********************************/
#define DHT11PIN 40
dht11 DHT11;             //<<<<<<<<<<<<<<<<<<<<<<<<<<<

void setup() {
/***********************************
Void General Setup
***********************************/
Serial.begin(9600);

/***********************************
Void Setup for LCD
***********************************/
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a statis message to the LCD starting at row 0, position 0
lcd.print("Testing ");

/***********************************
Void Setup for DS18B20 temperature module
***********************************/ 
sensors.begin ();

/***********************************
Void Setup for DHT temperature module
***********************************/
// None - Defined above with Serial.begin(9600);
} // End of void setup()

void loop() {
/***********************************
Void Loop for DHT temperature module
***********************************/
Serial.println();
int chk = DHT11.read(DHT11PIN);
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);
Serial.print("Temperature (C): ");
Serial.println((float)DHT11.temperature, 2);

/***********************************
Void Loop DS18B20 temperature module
***********************************/
/* call sensors. Request Temperatures () to issue a global temperature */
/*request to all devices on the bus*/
float floatDS18B20Temp;
// Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); /*Send the command to get temperatures*/
// Serial.println("DONE");
/*We use the function ByIndex, and as an example get the temperature from the first sensor only.*/
Serial.println(sensors.getTempCByIndex(0));

}

JCA34F:
You don’t have “dht11 DHT11;” in your combo code, try it now. What does “Pre-Void” mean?

/***********************************

Include libraries
***********************************/
#include <LiquidCrystal.h>                                // LCD
#include <OneWire.h>                                      // DS18B20 temperature module
#include <DallasTemperature.h>                            // DS18B20 temperature module
#include <dht11.h>                                        // DHT 11 temp/humidity module

/***********************************
Pre-Void Setup for LCD
***********************************/
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);                  // Set up pins 8 - 13

/***********************************
Pre-Void Setup for DS18B20 temperature module
**********************************/
#define ONE_WIRE_BUS 30                                    // Set up pin 30
/
Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)*/
OneWire oneWire(ONE_WIRE_BUS);
/*Pass our oneWire reference to Dallas Temperature. */
DallasTemperature sensors(&oneWire);

/***********************************
Pre-Void Setup for DHT11 temp/humidity module
***********************************/
#define DHT11PIN 40
dht11 DHT11;             //<<<<<<<<<<<<<<<<<<<<<<<<<<<

void setup() {
/***********************************
Void General Setup
***********************************/
Serial.begin(9600);

/***********************************
Void Setup for LCD
***********************************/
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Print a statis message to the LCD starting at row 0, position 0
lcd.print("Testing ");

/***********************************
Void Setup for DS18B20 temperature module
***********************************/
sensors.begin ();

/***********************************
Void Setup for DHT temperature module
***********************************/
// None - Defined above with Serial.begin(9600);
} // End of void setup()

void loop() {
/***********************************
Void Loop for DHT temperature module
***********************************/
Serial.println();
int chk = DHT11.read(DHT11PIN);
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);
Serial.print("Temperature (C): ");
Serial.println((float)DHT11.temperature, 2);

/***********************************
Void Loop DS18B20 temperature module
**********************************/
/
call sensors. Request Temperatures () to issue a global temperature */
/request to all devices on the bus/
float floatDS18B20Temp;
// Serial.print(“Requesting temperatures…”);
sensors.requestTemperatures(); /Send the command to get temperatures/
// Serial.println(“DONE”);
/We use the function ByIndex, and as an example get the temperature from the first sensor only./
Serial.println(sensors.getTempCByIndex(0));

}

Thank you, I shall try that!
Pre-Void is for anything I stick into the area which includes the #includes, but before the void setup() portion. It’s there to help me more quickly ID which of the 3 sections of code I’m working in. It’s easy enough to keep track when I’m only doing a single sensor, but as I start to load in more and more sensors, it gets harder to track. Adding in “pre-void setup”, “void setup” and “void loop” into the comments makes it easy to see exactly where I am in the code at every step.
Makes it WAAAY easier to see where I am at a glance.

IoT_hobbyist:
I recommend you using the DHT library from Adafruit. See how to use the DHT library with DHT sensor

I shall. I have that, but hadn't starting trying it yet as I'm not using an Adafruit board. I shall try it today. Thank you for the info!