Problems Sensor DS18B20 with Shild LCD

I have a kit, Mega + shield LCD 16x2 + DS18B20 temperature sensor, connected to the notebook's USB.

If I use mega and the DS18B20 connected to 5v, the serial works correctly. However, when I put the LCD on, the DS18B20 stops working and always shows "-127"

Could it be that the LCD steals power causing the sensor to not work? Or is it something else?

Show us your code. We will probably be able to determine if the two items have conflicting pin assignments, or may be not - but without at least paying a little attention to:

we're unable to help at all.

Is this still your board:

If so, did you resolve the problem without further interaction?

It's not the same board, I couldn't solve the problem.

I bought another board, a common Arduino Mega 2560, without WiFi.

My code:

#include <OneWire.h>
#include <DallasTemperature.h>

namespace pin {
  const byte tds_sensor = A1;
  const byte one_wire_bus = 22; 
}

namespace device {
  float aref = 4.3;
}

namespace sensor {
  float ec = 0;
  unsigned int tds = 0;
  float waterTemp = 0;
  float ecCalibration = 1;
}

OneWire oneWire(pin::one_wire_bus);
DallasTemperature dallasTemperature(&oneWire);

void setup() {
  Serial.begin(9600);
  dallasTemperature.begin();
}

void loop() {
  readTdsQuick();
  delay(1000);
}

void readTdsQuick() {
  dallasTemperature.requestTemperatures();
  sensor::waterTemp = dallasTemperature.getTempCByIndex(0);

  float rawEc = analogRead(pin::tds_sensor) * device::aref / 1024.0; // read the analog value more stable by the median filtering algorithm, and convert to voltage value
  float temperatureCoefficient = 1.0 + 0.02 * (sensor::waterTemp - 25.0); // temperature compensation formula: fFinalResult(25^C) = fFinalResult(current)/(1.0+0.02*(fTP-25.0));
  
  sensor::ec = (rawEc / temperatureCoefficient) * sensor::ecCalibration; // temperature and calibration compensation
  sensor::tds = (133.42 * pow(sensor::ec, 3) - 255.86 * sensor::ec * sensor::ec + 857.39 * sensor::ec) * 0.5; //convert voltage value to tds value
 
  Serial.print(F("TDS:")); Serial.println(sensor::tds);
  Serial.print(F("EC:")); Serial.println(sensor::ec, 2);
  Serial.print(F("Temperature:")); Serial.println(sensor::waterTemp,2);

}

The problem is that if I connect the shield, without changing the code, the sensor stops working.

(The LCD shield is connected to port A0)

The code posted don´t show LCD code.

Post your shield image or a link for this shield.

1 Like
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>

//******* CONFIGURACAO LCD *********
#define pinBotoes A0

#define pinRs 8
#define pinEn 9
#define pinD4 4
#define pinD5 5
#define pinD6 6
#define pinD7 7
#define pinBackLight 10

#define tempoDebounce 50

LiquidCrystal lcd(pinRs, pinEn, pinD4, pinD5, pinD6, pinD7);

namespace pin {
  const byte tds_sensor = A1;
  const byte one_wire_bus = 22; // Dallas Temperature Sensor
}

namespace device {
  float aref = 4.3;
}

namespace sensor {
  float ec = 0;
  unsigned int tds = 0;
  float waterTemp = 0;
  float ecCalibration = 1;
}

OneWire oneWire(pin::one_wire_bus);
DallasTemperature dallasTemperature(&oneWire);

void setup() {
  pinMode(pinBackLight, OUTPUT);
  digitalWrite(pinBackLight, HIGH);
  Serial.begin(9600);
  lcd.begin(16, 2);
  dallasTemperature.begin();
}

void loop() {
  readTdsQuick();
  delay(1000);
}

void readTdsQuick() {
  dallasTemperature.requestTemperatures();
  sensor::waterTemp = dallasTemperature.getTempCByIndex(0);

  float rawEc = analogRead(pin::tds_sensor) * device::aref / 1024.0; // read the analog value more stable by the median filtering algorithm, and convert to voltage value
  float temperatureCoefficient = 1.0 + 0.02 * (sensor::waterTemp - 25.0); // temperature compensation formula: fFinalResult(25^C) = fFinalResult(current)/(1.0+0.02*(fTP-25.0));
  
  sensor::ec = (rawEc / temperatureCoefficient) * sensor::ecCalibration; // temperature and calibration compensation
  sensor::tds = (133.42 * pow(sensor::ec, 3) - 255.86 * sensor::ec * sensor::ec + 857.39 * sensor::ec) * 0.5; //convert voltage value to tds value
  
  lcd.clear();
  lcd.print("TDS   EC   Temp");
  lcd.setCursor(0,1); 
  lcd.print(sensor::tds); 
  lcd.setCursor(5,1); 
  lcd.print(sensor::ec, 2); 
  lcd.setCursor(11,1); 
  lcd.print(sensor::waterTemp,2); 

}



And the image or link of the shield!!!!

If your shield is the same as this one, see in the schematic below that the LCD pins are not the same as those you defined in your code.

Yes, that's my board.

However, the pins are not the same as your diagram, I checked here, and it is the same as the code. So much so that the LCD is working.

So so that we can help you, please indicate what your board is and what its schematic is.

Sorry for the delay, I had to take a break from the project.

But back to the case, I changed the board and managed to solve it, thank you everyone.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.