My code doesn't work anymore (Arduino ,multiple ds18b20,htu21d,bmp180,i2clcd )

so i had to switch from arduino uno to arduino mega and i belive this is the code that worked on uno im not sure why it doesn’t work maybe because i updated arduino ide or maybe i updated some libraries i have no idea and m asking for help beacuse u don’t know much about programing so any help i appreciated
thanx!

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#include <Ethernet.h>
#include <SPI.h>
#include <SFE_BMP180.h>
#include <Wire.h>
#include "HTU21D.h"
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>


#define ALTITUDE 50                   
#define ONE_WIRE_BUS 7


void setup();
void readHumidity();
void readLDR();
void readTemp();
void readPressure();
void loop();

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensorsA(&oneWire);
DallasTemperature sensorsB(&oneWire);
DallasTemperature sensorsC(&oneWire);
LiquidCrystal_I2C lcd(0x27, 20, 4);
SFE_BMP180 pressure;
HTU21D myHumidity;
SimpleTimer timer;

char auth[] = "xxxxx";
int LDR = A0;



void setup()
{
  Blynk.begin(auth);
  pinMode(LDR, INPUT);
  sensorsA.begin();
  sensorsB.begin();
  sensorsC.begin();
  pressure.begin();
  lcd.init();                                           
  lcd.backlight();
  myHumidity.begin();

  timer.setInterval(1000, readTemp);
  timer.setInterval(1000, readLDR);
  timer.setInterval(1000L, readPressure);
  timer.setInterval(1000L, readHumidity);
}

void readHumidity()
{
  float humd = myHumidity.readHumidity();
  float temp = myHumidity.readTemperature();


  Blynk.virtualWrite(5, humd);

  lcd.setCursor(0, 3);
  lcd.print("H:");
  lcd.print(humd);
  lcd.print("%");

}

void readLDR()
{
  LDR = analogRead(LDR);
                                
}

void readTemp()
{
  sensorsA.requestTemperatures();
  sensorsB.requestTemperatures();
  sensorsC.requestTemperatures();


  float floatTempA = sensorsA.getTempCByIndex(0);
  char A_buffer[15];
  dtostrf(floatTempA, 8, 9, A_buffer);
  Blynk.virtualWrite(1, A_buffer);


  float floatTempB = sensorsB.getTempCByIndex(1);
  char B_buffer[15];
  dtostrf(floatTempB, 8, 9, B_buffer);
  Blynk.virtualWrite(2, B_buffer);


  float floatTempC = sensorsC.getTempCByIndex(2);
  char C_buffer[15];
  dtostrf(floatTempC, 8, 9, C_buffer);
  Blynk.virtualWrite(3, C_buffer);


  sensorsA.requestTemperatures();
  lcd.setCursor(0, 0);
  lcd.print("Sensor #1:");
  lcd.print(sensorsA.getTempCByIndex(0));
  lcd.print((char)223);
  lcd.print("C");
  sensorsA.requestTemperatures();
  lcd.setCursor(0, 1);
  lcd.print("Sensor #2:");
  lcd.print(sensorsB.getTempCByIndex(1));
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0, 2);
  lcd.print("Sensor #3:");
  lcd.print(sensorsC.getTempCByIndex(2));
  lcd.print((char)223);
  lcd.print("C");
}
void readPressure()
{
  char status;
  static double T, P, p0, a;

    
  status = pressure.startTemperature();
  if (status != 0)
  {
                                            
    delay(status);

      
    status = pressure.getTemperature(T);
    if (status != 0)
    {
                                      
       
      status = pressure.startPressure(3);
      if (status != 0)
      {
                                                
        delay(status);

                                                       
         
        status = pressure.getPressure(P, T);
        if (status != 0)
        {
                                                                                      
               
          p0 = pressure.sealevel(P, ALTITUDE);                                      
                                                                                                 
                
          a = pressure.altitude(P, p0);
        }
                                                                        
      }
                                                                    
    }
                                                                       
  }
                                                                   
  Blynk.virtualWrite(V4, int(p0));
         
  lcd.setCursor(10, 3);
  lcd.print("P:");
  lcd.print(int(p0));
  lcd.print(" hPa");
}
void loop()
{
  Blynk.run();
  timer.run();

}

you really need to give some more information.

can’t connect to blynk server plus lcd doesn’t display any data

you should use some debugging in there!!!

why dont you use:

#define BLYNK_PRINT Serial //this is the debugging for Blynk
//#define BLYNK_DEBUG        // Optional, this enables 'full' debugging with detailed prints

you have to add

Serial.begin(9600);

in setup

i did that , and it doesnt dispaly anything

is the Ethernet working?

and there is no output to the serial monitor?

are there any errors when i complies?

Im using ethernet shield,leds show that its connected to internet .no errors compiling , just to add I tried every component using examples and everything is working so there’s no problem with connection

and how do you know you are not connected to the Blynk server?

what does the LCD do? any action?

are you sure the pins are correct?

I know I’m not connected to blink server because in app when I press on square icon on top right corner(Android)and after that I press triangle (to exit settings) it says that Arduino Uno is not connected to internet
LCD doesn’t do anything just lightly dimmed square pixels on line 0&3
Pins are connected the way they should be. Ds18b20 pin7 ,LCD ,bmp180 & htu21d connected to pin 20$21 (scl&sda) on Arduino mega ,as I mentioned before I tried examples for every sensor plus LCD and it works fine

i thought you said you were using a Arduino Mega now? not Uno???

Why does it even compile? You do a delay(status) which requires an int, but you put in a char variable type. Also, delays should be avoided.

I am using mega now I forgot to switch from Uno to mega on Android app.

Made changes and that didn’t help anything

You probably gonna have to get rid of that delay() anyway since there is not really a way of knowing how long it will take. You need to make a SimpleTimer timeout() function for that.

Can you guide me a little bit I know very little about programming

You already know how to use the basic things of SimpleTimer, so that’s good. There is a lot of documentation here: http://playground.arduino.cc/Code/SimpleTimer

The idea of a timeout is to just repeat a task once. Of course you can run the task again, but it’s not repeated like a “regular” timer.

Is it possible that I upgraded library and it doesn’t work anymore?

only if you didnt upgrade your IDE and App at the same time…

Sketch working just fine .i found out that there’s a problem with a network switch that my Arduino was connected to.i using 3 ds18b20’s. One close to Arduino (#1)and other two around 30’ away. I had 4.7k resistor connected right by Arduino. When I disconnect other two sensors sensor#1 works fine but when I connect them back it gives me -127°C. I have noticed that when I connect second 4.7k resistor on the other end where sensor 2&3 is everything works fine. I don’t know if this is allowed and I don’t know why but everything was working before with one resistor.
Any clue what went wrong ?

Fixed it had to change 4.7k resistor to 3.9k everything works fine now . Just one question I have noticed that ds18b20 displaying temperature at 9bits how do I change it to 12bits?

1 Like