Strange behaviour Arduino removing comment and Serial.Print

Hello

I'm having a problem with my code

#include <idDHT11.h>
#include <LiquidCrystal.h>

//TEMP
int idDHT11pin = 2; //Digitale pin voor verbindingen
int idDHT11intNumber = 0; //interrupt nummer (Moet gebruikt worden om de pin toe te wijzen(opzoeken in de tabel. Voor Uno = 0)
//TEMP

//LCD
LiquidCrystal lcd(7, 8, 9, 10, 11 , 12);
//LCD

const int RELAIS = 13;
const int KNOP1 = 6 ;
const int KNOP2 = 5 ;
const int KNOPLICHT = 4;
const int SCHERM = 3;

char btLezen;

int opstart = 1;
int starttemp = 26;
int gewenst;
int temp;
int val1 = 0;
int val2 = 0;
int oudtemp = 0;
int oudgewenst = 0;
int lichtknop = 0;
int lichtscherm = 1 ;

//declaration
void dht11_wrapper(); // must be declared before the lib initialization

// Lib instantiate
idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper);

void setup()
{
  Serial.begin(9600);
  Serial.println("Test programma, Glenn Vanspauwen");
  Serial.print("LIB versie: ");
  Serial.println(IDDHT11LIB_VERSION);
  Serial.println("---------------");
  pinMode(RELAIS, OUTPUT);
  pinMode(SCHERM, OUTPUT);
  pinMode(KNOP1,INPUT);
  pinMode(KNOP2,INPUT);
  pinMode(KNOPLICHT,INPUT);
  Serial.println("OK1"); 



}

// Deze wrapper dient om het op te roepen 
// Moet zo geschreven worden om de lib. te laten werken van de DHT11
void dht11_wrapper() {
  DHT11.isrCallback();
}
void loop(){

  //bluetooth
  btLezen = Serial.read();

  Serial.println("serialBT");
  Serial.println(btLezen);
  //bluetooth


  if(DHT11.getCelsius() < gewenst){
    digitalWrite(RELAIS,LOW);
    Serial.print("Relais uit");

  }
  else{
    digitalWrite(RELAIS,HIGH);
    Serial.print("Relais aan");
  }

  val1 = digitalRead(KNOP1);
  Serial.print(val1);
  val2 = digitalRead(KNOP2);
  Serial.print(val2);


  Serial.print("\nInformatie ontvangen van sensor: ");
  Serial.print("Sensor gegevens: ");
  //delay(100);
  DHT11.acquire();
  while (DHT11.acquiring());
  int result = DHT11.getStatus();
  switch (result)
  {
  case IDDHTLIB_OK: 
    Serial.println("OK"); 
    break;
  case IDDHTLIB_ERROR_CHECKSUM: 
    Serial.println("Fout\n\r\tChecksum fout"); 
    break;
  case IDDHTLIB_ERROR_TIMEOUT: 
    Serial.println("Fout\n\r\tTime out fout"); 
    break;
  case IDDHTLIB_ERROR_ACQUIRING: 
    Serial.println("Error\n\r\tAcquiring"); 
    break;
  case IDDHTLIB_ERROR_DELTA: 
    Serial.println("Error\n\r\tVerschil in tijd te klein"); 
    break;
  case IDDHTLIB_ERROR_NOTSTARTED: 
    Serial.println("Error\n\r\tNiet gestart"); 
    break;
  default: 
    Serial.println("Onbekende fout"); 
    break;
  }
  Serial.print("Luchtvochtigheid (%): ");
  Serial.println(DHT11.getHumidity(), 2);

  Serial.print("Temp (oC): ");
  Serial.println(DHT11.getCelsius(), 2);

  Serial.print("Dauwpunt (oC): ");
  Serial.println(DHT11.getDewPoint());

  Serial.print("Traag Dauwpunt (oC): ");
  Serial.println(DHT11.getDewPointSlow());


  //opstarten
  if (opstart == 1){
    starttemp = DHT11.getCelsius();
    gewenst = starttemp;
    opstart = opstart + 10;
    temp = DHT11.getCelsius();
    Serial.println(DHT11.getCelsius(),2);
    Serial.println("OKif");
    digitalWrite(SCHERM,HIGH);
    //welkom boodschap
    lcd.begin(16, 2);
    lcd.setCursor(0,0);
    lcd.print("Welkom, Glenn !");
    delay(1500);
    //welkom boodschap
  }
  else{
  }
  temp = DHT11.getCelsius();              
  //opstarten
  Serial.print("Start temperatuur :"); 
  Serial.println(starttemp);
  Serial.print("Gewenste :"); 
  Serial.println(gewenst);

  //LCD

  if (val1 == HIGH){
    gewenst = gewenst+1;
  }
  else{
  }
  if (val2 == HIGH){
    gewenst = gewenst-1;
  }
  else{
  }

  //Bluetooth
  switch (btLezen) {
  case 1:
    gewenst = gewenst+1;
    break;
  case 2:
    gewenst = gewenst-1;
    break;
  default:

    break;
  }


  //Bluetooth

  if ((gewenst != oudgewenst)|| (temp !=oudtemp)){
    lcd.begin(16, 2);
    lcd.setCursor(0,0);
    lcd.print("Temperatuur ");
    lcd.setCursor(12, 0);
    lcd.print(temp);
    lcd.setCursor(14, 0);
    lcd.print((char)223);
    lcd.setCursor(15, 0);
    lcd.print("C");
    lcd.setCursor(0, 1);
    lcd.print("Gewenst ");
    lcd.setCursor(8, 1);
    lcd.print(gewenst);
    lcd.setCursor(10, 1);
    lcd.print((char)223);
    lcd.setCursor(11, 1);
    lcd.print("C");
    oudgewenst = gewenst;
    oudtemp = (DHT11.getCelsius());
  }
  else{
  }

  //LCD

  //SCHERM LICHT
  Serial.println(lichtscherm);
  Serial.println(lichtknop);
  lichtknop = digitalRead(KNOPLICHT);

  if ( (lichtknop == 1)||(btLezen ==3)) {
    if (lichtscherm == 1) {
      lcd.noDisplay();
      lichtscherm = 0;
      digitalWrite(SCHERM,LOW);
    } 
    else{
      lcd.display();
      lichtscherm = 1;
      digitalWrite(SCHERM,HIGH);
    }
  }
  else{
  }

}

If I remove any Serial.Print or Serial.Println that has to do with the DHT 11 my LCD will show strange symbols, The temprature on the LCD will freeze or I can't change the values with my buttons.

Any idea what could be the problem?
Tried to find solutions but nothing works.

I just need to get rid of the Serial.print* because I need to send one value to my Android phone with bluetooth and not a full log of information.

Thanks for your help !

Any idea what could be the problem?

The indenting in your code is horrid. There is a reason why there is a Tools menu, with an Auto Format option. Learn what that reason is.

You have a lot of string literals in your print statements, with no F() macro use to keep them out of SRAM. I'm guessing that you are out of memory.

Serial.print(F("Relais uit"));

Didn't know that tool. I've changed it.

I don't think it's memory. It's working with all the code.
Just not when I delete all the serial.print* lines.

  else{
  }

Why? If there is nothing to do, you don't need an else clause.

  else{
  }

Ditto.

  else{
  }

And again. And then twice more...

It's working with all the code.
Just not when I delete all the serial.print* lines.

Well, we have no idea what your definition of "working" is. Or, "not working". Nor, do we know what your code looks like without all the Serial.print()s.

DO you have a link to this library - #include <idDHT11.h> ?

#include <idDHT11.h>
#include <LiquidCrystal.h>

int idDHT11pin = 2; 
int idDHT11intNumber = 0; 

LiquidCrystal lcd(7, 8, 9, 10, 11 , 12);

const int RELAIS = 13;
const int KNOP1 = 6 ;
const int KNOP2 = 5 ;
const int KNOPLICHT = 4;
const int SCHERM = 3;

char btLezen;

int opstart = 1;
int starttemp = 26;
int gewenst;
int temp;
int val1 = 0;
int val2 = 0;
int oudtemp = 0;
int oudgewenst = 0;
int lichtknop = 0;
int lichtscherm = 1 ;
void dht11_wrapper(); 

idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper);

void setup(){
  Serial.begin(9600);
  pinMode(RELAIS, OUTPUT);
  pinMode(SCHERM, OUTPUT);
  pinMode(KNOP1,INPUT);
  pinMode(KNOP2,INPUT);
  pinMode(KNOPLICHT,INPUT);
}

void dht11_wrapper() {
  DHT11.isrCallback();
}

void loop(){

  btLezen = Serial.read();

  if(DHT11.getCelsius() < gewenst){
    digitalWrite(RELAIS,LOW);
  }

  else{
    digitalWrite(RELAIS,HIGH);
  }

  val1 = digitalRead(KNOP1);
  val2 = digitalRead(KNOP2);

  DHT11.acquire();
  while (DHT11.acquiring());


  if (opstart == 1){
    starttemp = DHT11.getCelsius();
    gewenst = starttemp;
    opstart = opstart + 10;
    temp = DHT11.getCelsius();
    digitalWrite(SCHERM,HIGH);
    lcd.begin(16, 2);
    lcd.setCursor(0,0);
    lcd.print("Welkom, Glenn !");
    delay(1500);
  }

  temp = DHT11.getCelsius();              

  if (val1 == HIGH){
    gewenst = gewenst+1;
  }

  if (val2 == HIGH){
    gewenst = gewenst-1;
  }

  switch (btLezen) {
  case 1:
    gewenst = gewenst+1;
    break;
  case 2:
    gewenst = gewenst-1;
    break;
  default:
    break;
  }

  Serial.println(gewenst);

  if ((gewenst != oudgewenst)|| (temp !=oudtemp)){
    lcd.begin(16, 2);
    lcd.setCursor(0,0);
    lcd.print("Temperatuur ");
    lcd.setCursor(12, 0);
    lcd.print(temp);
    lcd.setCursor(14, 0);
    lcd.print((char)223);
    lcd.setCursor(15, 0);
    lcd.print("C");
    lcd.setCursor(0, 1);
    lcd.print("Gewenst ");
    lcd.setCursor(8, 1);
    lcd.print(gewenst);
    lcd.setCursor(10, 1);
    lcd.print((char)223);
    lcd.setCursor(11, 1);
    lcd.print("C");
    oudgewenst = gewenst;
    oudtemp = (DHT11.getCelsius());
  }

  lichtknop = digitalRead(KNOPLICHT);

  if ( (lichtknop == 1)||(btLezen ==3)) {
    if (lichtscherm == 1) {
      lcd.noDisplay();
      lichtscherm = 0;
      digitalWrite(SCHERM,LOW);
    } 
    else{
      lcd.display();
      lichtscherm = 1;
      digitalWrite(SCHERM,HIGH);
    }
  }
}

The code what I want. Just only a serial.println for my "gewenst".

But after 2 lines printing (Serial Monitor) the code freezes (see 2 lines of "gewenst")
and I can't change the value with the buttons I've connected (Knop1,knop2 and knoplicht).
Also no reaction on the lcd screen.

robtillaart:
DO you have a link to this library - #include <idDHT11.h> ?

idDHT11.h :

/*
	FILE: 		idDHT11.h
	VERSION: 	0.1
	PURPOSE: 	Interrupt driven Lib for DHT11 with Arduino.
	LICENCE:	GPL v3 (http://www.gnu.org/licenses/gpl.html)
	DATASHEET: http://www.micro4you.com/files/sensor/DHT11.pdf
	
	Based on DHT11 library: http://playground.arduino.cc/Main/DHT11Lib
*/


#ifndef idDHT11_H__
#define idDHT11_H__

#if defined(ARDUINO) && (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif

#define IDDHT11LIB_VERSION "0.1"

// state codes
#define IDDHTLIB_OK				0
#define IDDHTLIB_ACQUIRING		1
#define IDDHTLIB_ACQUIRED		2
#define IDDHTLIB_RESPONSE_OK	3

// error codes
#define IDDHTLIB_ERROR_CHECKSUM		-1
#define IDDHTLIB_ERROR_TIMEOUT		-2
#define IDDHTLIB_ERROR_ACQUIRING	-3
#define IDDHTLIB_ERROR_DELTA		-4
#define IDDHTLIB_ERROR_NOTSTARTED	-5

#define IDDHT11_CHECK_STATE		if(state == STOPPED)													\
									return status;													\
								else if(state != ACQUIRED)				\
									return IDDHTLIB_ERROR_ACQUIRING;
									
class idDHT11
{
public:
	idDHT11(int pin, int intNumber,void (*isrCallback_wrapper)());
    void init(int pin, int intNumber,void (*isrCallback_wrapper)());
	void isrCallback();
	int acquire();
	int acquireAndWait();
	float getCelsius();
	float getFahrenheit();
	float getKelvin();
	double getDewPoint();
	double getDewPointSlow();
	float getHumidity();
	bool acquiring();
	int getStatus();
	
private:
	
	void (*isrCallback_wrapper)(void);
	
	enum states{RESPONSE=0,DATA=1,ACQUIRED=2,STOPPED=3,ACQUIRING=4};
	volatile states state;
	volatile int status;
	volatile byte bits[5];
	volatile byte cnt;
	volatile byte idx;
	volatile int us;
	int intNumber;
	int pin;
	volatile float hum;
	volatile float temp;
};
#endif // idDHT11_H__

idDHT11.cpp :

/*
	FILE: 		idDHT11.cpp
	VERSION: 	0.1
	PURPOSE: 	Interrupt driven Lib for DHT11 with Arduino.
	LICENCE:	GPL v3 (http://www.gnu.org/licenses/gpl.html)
	DATASHEET: http://www.micro4you.com/files/sensor/DHT11.pdf
	
	Based on DHT11 library: http://playground.arduino.cc/Main/DHT11Lib
*/

#include "idDHT11.h"
#define DEBUG_IDDHT11

idDHT11::idDHT11(int pin, int intNumber,void (*callback_wrapper)()) {
	init(pin, intNumber,callback_wrapper);
}

void idDHT11::init(int pin, int intNumber, void (*callback_wrapper) ()) {
	this->intNumber = intNumber;
	this->pin = pin;
	this->isrCallback_wrapper = callback_wrapper;
	hum = 0;
	temp = 0;
	pinMode(pin, OUTPUT);
	digitalWrite(pin, HIGH);
	state = STOPPED;
	status = IDDHTLIB_ERROR_NOTSTARTED;
}

int idDHT11::acquire() {
	if (state == STOPPED || state == ACQUIRED) {
		
		//set the state machine for interruptions analisis of the signal
		state = RESPONSE;
		
		// EMPTY BUFFER and vars
		for (int i=0; i< 5; i++) bits[i] = 0;
		cnt = 7;
		idx = 0;
		hum = 0;
		temp = 0;
	
		// REQUEST SAMPLE
		pinMode(pin, OUTPUT);
		digitalWrite(pin, LOW);
		delay(18);
		digitalWrite(pin, HIGH);
		delayMicroseconds(40);
		pinMode(pin, INPUT);
		
		// Analize the data in an interrupt
		us = micros();
		attachInterrupt(intNumber,isrCallback_wrapper,FALLING);
		
		return IDDHTLIB_ACQUIRING;
	} else
		return IDDHTLIB_ERROR_ACQUIRING;
}
int idDHT11::acquireAndWait() {
	acquire();
	while(acquiring())
		;
	return getStatus();
}
void idDHT11::isrCallback() {
	int newUs = micros();
	int delta = (newUs-us);
	us = newUs;
	if (delta>6000) {
		status = IDDHTLIB_ERROR_TIMEOUT;
		state = STOPPED;
		detachInterrupt(intNumber);
		return;
	}
	switch(state) {
		case RESPONSE:
			if(delta<25){
				us -= delta;
				break; //do nothing, it started the response signal
			} if(125<delta && delta<190) {
				state = DATA;
			} else {
				detachInterrupt(intNumber);
				status = IDDHTLIB_ERROR_TIMEOUT;
				state = STOPPED;
			}
			break;
		case DATA:
			if(delta<10) {
				detachInterrupt(intNumber);
				status = IDDHTLIB_ERROR_DELTA;
				state = STOPPED;
			} else if(60<delta && delta<135) { //valid in timing
				if(delta>90) //is a one
					bits[idx] |= (1 << cnt);
				if (cnt == 0) {  // whe have fullfilled the byte, go to next
						cnt = 7;    // restart at MSB
						if(idx++ == 4) {      // go to next byte, if whe have got 5 bytes stop.
							detachInterrupt(intNumber);
							// WRITE TO RIGHT VARS
							// as bits[1] and bits[3] are allways zero they are omitted in formulas.
							hum    = bits[0]; 
							temp = bits[2]; 
							uint8_t sum = bits[0] + bits[2];  
							if (bits[4] != sum) {
								status = IDDHTLIB_ERROR_CHECKSUM;
								state = STOPPED;
							} else {
								status = IDDHTLIB_OK;
								state = ACQUIRED;
							}
							break;
						}
				} else cnt--;
			} else {
				detachInterrupt(intNumber);
				status = IDDHTLIB_ERROR_TIMEOUT;
				state = STOPPED;
			}
			break;
		default:
			break;
	}
}
bool idDHT11::acquiring() {
	if (state != ACQUIRED && state != STOPPED)
		return true;
	return false;
}
int idDHT11::getStatus() {
	return status;
}
float idDHT11::getCelsius() {
	IDDHT11_CHECK_STATE;
	return temp;
}

float idDHT11::getHumidity() {
	IDDHT11_CHECK_STATE;
	return hum;
}

float idDHT11::getFahrenheit() {
	IDDHT11_CHECK_STATE;
	return temp * 1.8 + 32;
}

float idDHT11::getKelvin() {
	IDDHT11_CHECK_STATE;
	return temp + 273.15;
}

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double idDHT11::getDewPoint() {
	IDDHT11_CHECK_STATE;
	double a = 17.271;
	double b = 237.7;
	double temp_ = (a * (double) temp) / (b + (double) temp) + log( (double) hum/100);
	double Td = (b * temp_) / (a - temp_);
	return Td;
	
}
// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm 
double idDHT11::getDewPointSlow() {
	IDDHT11_CHECK_STATE;
	double A0= 373.15/(273.15 + (double) temp);
	double SUM = -7.90298 * (A0-1);
	SUM += 5.02808 * log10(A0);
	SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
	SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
	SUM += log10(1013.246);
	double VP = pow(10, SUM-3) * (double) hum;
	double T = log(VP/0.61078);   // temp var
	return (241.88 * T) / (17.558-T);
}
// EOF

Link : GitHub - niesteszeck/idDHT11: Interrupt driven DHT11 library

thanks

Could it be that the problem is inside the library?
I checked my code and can't understand why it doesn't keep running...