I’m using this code I created copying, pasting and modifying accordingly to my schematics.
It features control of 2 relays for front door and gate, an emergency button that opens the front door (in case internet down) a dallas DS18B20 and a Lm35, so I can have internal and ext temperatures display.
It worked perfectly until I changed it and added a bmp120 in place of the lm35.
Now it connects, but after a few minutes I lose connection
Could you please check it? I’ts currently taking 91% of my arduino uno space.
#define BLYNK_PRINT Serial
#include <SimpleTimer.h>
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <Wire.h>
#include <SFE_BMP180.h>
//BMP180
SFE_BMP180 bmp180;
int Altitude = 155; //current altitude in meters
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";
#define W5100_CS 10
#define SDCARD_CS 4
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 3
OneWire ourWire(ONE_WIRE_BUS);
DallasTemperature sensors(&ourWire);
//BUTTON
const int buttonPin = 5; // The number of the Pushbutton pin
int buttonState = 0; // Variable for reading the pushbutton status
// Variables will change:
long previousMillis = 0; // will store last time LED was updated
long interval = 7000; // interval at which to blink (milliseconds)
long currentValue;
float Dtemp;
void setup()
{
Blynk.begin(auth);
// Debug console
Serial.begin(9600);
//BMP180
bool success = bmp180.begin();
if (success) {
Serial.println("BMP180 init success");
}
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
// set initial state of gate to 1(Closed)
digitalWrite(7, HIGH);
//DALLAS
delay(1000);
sensors.begin();
//REDBUTTON EMERGENCY
// initialize the digital pin as an output for LED.
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
}
void loop()
{
Blynk.run();
Serial.println();
sensors.requestTemperatures();
Dtemp = sensors.getTempCByIndex(0);
Blynk.virtualWrite(10, Dtemp);
//REDBUTTON EMERGENCY
previousMillis = millis();
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
//The button is pushed
while (buttonState == HIGH) {
currentValue = millis() - previousMillis;
if (currentValue > interval)
{
// save the last time you blinked the LED
previousMillis = millis();
digitalWrite(6, HIGH);
delay(4000);
digitalWrite(6, LOW);
}
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
}
//BMP180
char status;
double T, P;
bool success = false;
status = bmp180.startTemperature();
if (status != 0) {
delay(1000);
status = bmp180.getTemperature(T);
if (status != 0) {
status = bmp180.startPressure(3);
if (status != 0) {
delay(status);
status = bmp180.getPressure(P, T);
if (status != 0) {
float comp = bmp180.sealevel(P, Altitude);
Blynk.virtualWrite(9, comp);
Blynk.virtualWrite(8, T);
}
}
}
}
}