Hello i'm having the following issue.
My arduino halts (both the lcd and the serial monitor) when it reads the temperature from two DS18B20. When i read only the one, is stable as rock.When i connect the second one, after 2-3 loops it halts. Already tried a bunch of delays in random points.
My code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define LED_G 9 // The pin the LED is connected to
#define LED_Y 11 // The pin the LED is connected to
#define LED_R 10 // The pin the LED is connected to
#define ONE_WIRE_BUS 6
LiquidCrystal_I2C lcd(0x27, 16, 2);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int cr_flag=0;
int tflag=0;
void setup()
{
Serial.begin(9600);
pinMode(LED_G, OUTPUT); // Declare the LED as an output
pinMode(LED_Y, OUTPUT); // Declare the LED as an output
pinMode(LED_R, OUTPUT); // Declare the LED as an output
lcd.begin();
for(int i=0; i<140; i++){
analogWrite(LED_G, i);
delay(2);
}
lcd.backlight();
lcd.clear();
lcd.setCursor(1,0);
lcd.print("RTelemetry");
for(int i=0; i<255; i++){
analogWrite(LED_Y, i);
delay(2);
}
lcd.setCursor(1,1);
lcd.print("Version 1.2");
for(int i=0; i<255; i++){
analogWrite(LED_R, i);
delay(2);
}
for(int i=255; i>0; i--){
analogWrite(LED_R, i);
delay(2);
}
digitalWrite(LED_R,LOW);
for(int i=255; i>0; i--){
analogWrite(LED_Y, i);
delay(2);
}
digitalWrite(LED_Y,LOW);
for(int i=140; i>0; i--){
analogWrite(LED_G, i);
delay(2);
}
digitalWrite(LED_G,LOW);
sensors.begin();
Serial.begin(9600);
}
void loop()
{
if (cr_flag==0)
{
if (tflag==0)
{
lcd.clear();
lcd.setCursor(2,0);
lcd.print("TEMPERATURE");
delay(1000);
lcd.setCursor(6,1);
lcd.print("MODE");
delay(2000);
tflag++;
temperature();
}
else{
temperature();
}
}
}
void temperature()
{ sensors.requestTemperatures();
int t1= sensors.getTempCByIndex(0);
delay(1200);
int t2= sensors.getTempCByIndex(1);
lcd.clear();
lcd.setCursor(1,0);
lcd.print("temp1");
lcd.setCursor(8,0);
lcd.print(t1);
lcd.setCursor(1,1);
lcd.print("temp2");
lcd.setCursor(8,1);
lcd.print(t2);
if ((t1+t2)/2<25)
{
analogWrite(LED_G, (5-(25-(t1+t2)/2))*28.8);
}
else if ((t1+t2)/2>25|(t1+t2)/2<30 ){
analogWrite(LED_G,144);
analogWrite(LED_Y, (5-(30-(t1+t2)/2))*28.8);
}
delay(100);
Serial.println(t1);
Serial.println(t2);
}
And my cables are kind like that:
Custom made PCB with two rows of 3 pins, common ground and +5V from arduino and common data wire with 4.7k resistor. Simple as that. What can i change?

