Another Blynk Garage Door Project needs Help!

Hi everybody!

last Weekend i soldered my Garage Door opener together an wanted so start using it.
But i got some problem with the code…

My requirements to this project are:

  1. open the Garage Door (obvious ^^)
  2. read temperature from a DHT22 Sensor and shot the Temp in Blynk
  3. upload the Temp to a thingspeak channel
  4. read the state of 2 magentic sensors

the code for task 1 – 3 works individually but when i put the whole code together i get some errors
reading the state oft he mag sensors doesn´t work for me the values in blynk changing form high to low even if there is no action…

but maybe someone can help me to put the code for task 1-3 toghter! Would be awsome :slight_smile:
here is the code i use for each task:

Task 1 open the Door:

// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>
char auth[] = "MY AUTH";

void setup()
{
Serial.begin(9600);
Blynk.begin(auth);
pinMode(D0, OUTPUT);
pinMode(D3, OUTPUT);
}

void loop()
{
Blynk.run(); 
}

Task 2 read Temp an show it in Blynk:

// This #include statement was automatically added by the Particle IDE.
#include <PietteTech_DHT.h>
// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>
char auth[] = "MY AUTH";


// system defines
#define DHTTYPE  DHT22              // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN   4               // Digital pin for communications
#define DHT_SAMPLE_INTERVAL   60000  // Sample every minute

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

// Lib instantiate
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper);

// globals
unsigned int DHTnextSampleTime;     // Next time we want to start sample
bool bDHTstarted;       // flag to indicate we started acquisition
int n;                              // counter

//this is coming from http://www.instructables.com/id/Datalogging-with-Spark-Core-Google-Drive/?ALLSTEPS
char resultstr[64]; //String to store the sensor data

char VERSION[64] = "0.04";

#define READ_INTERVAL 60000

void setup()
{
    {
Serial.begin(9600);
Blynk.begin(auth);
pinMode(D0, OUTPUT);
pinMode(D3, OUTPUT);
}

{

  Blynk.begin(auth);
 
 DHTnextSampleTime = 0;  // Start the first sample immediately
 Particle.variable("result", resultstr, STRING);

 Particle.publish("DHT22 - firmware version", VERSION, 60, PRIVATE);
 
}
}

// This wrapper is in charge of calling
// must be defined like this for the lib work
void dht_wrapper() {
    DHT.isrCallback();
}

void loop()
{
    {
Blynk.run(); 
}

{

  // Check if we need to start the next sample
  if (millis() > DHTnextSampleTime) {
      
  if (!bDHTstarted) {   // start the sample
      DHT.acquire();
      bDHTstarted = true;
  }

 if (!DHT.acquiring()) {    // has sample completed?

  float temp = (float)DHT.getCelsius();
  int temp1 = (temp - (int)temp) * 100;

  char tempInChar[32];
  sprintf(tempInChar,"%0d.%d", (int)temp, temp1);
  Particle.publish("The temperature from the dht22 is:", tempInChar, 60, PRIVATE);

  //virtual pin 1 will be the temperature
  Blynk.virtualWrite(V1, tempInChar);
 
  //google docs can get this variable
  sprintf(resultstr, "{\"t\":%s}", tempInChar);

  float humid = (float)DHT.getHumidity();
  int humid1 = (humid - (int)humid) * 100;

  sprintf(tempInChar,"%0d.%d", (int)humid, humid1);
  Particle.publish("The humidity from the dht22 is:", tempInChar, 60, PRIVATE);

  //virtual pin 2 will be the humidity
  Blynk.virtualWrite(V2, tempInChar);

  n++;  // increment counter
  bDHTstarted = false;  // reset the sample flag so we can take another
  DHTnextSampleTime = millis() + DHT_SAMPLE_INTERVAL;  // set the time for next sample
 }
  }
}
}

Task 3 upload Temp to a thingspeak channel

//Open source modified by A Hollander
//note DHT22 and DHT11 is slightly different software
//for DHT22 use 3.5V
 
#include "ThingSpeak/ThingSpeak.h"
#include "Adafruit_DHT/Adafruit_DHT.h"
 
#define DHTPIN 4     // what pin we're connected to
#define DHTTYPE DHT22              //make sure to switch back to DHT22 with other sensor
 
DHT dht(DHTPIN, DHTTYPE);
TCPClient client;
 
int sendDelay = 60000;
int led1 =A4; // led that will be used for a monitor in later version
 
unsigned int myChannelNumber = MY CHANNEL;
const char * myWriteAPIKey = "MY KEY"; //make sure it's write
void setup() {
              dht.begin();
              ThingSpeak.begin(client);
              Particle.publish("PowerON","DHT22",60,PRIVATE);
    pinMode(led1, OUTPUT);
}
 
void loop() {
    digitalWrite(led1, HIGH); //delay for led
    delay(100);
     digitalWrite(led1, LOW); //blinks led
    delay(100);
 
    
              float h = dht.getHumidity();
              float t = dht.getTempCelcius();
   ThingSpeak.setField(1,t);
  ThingSpeak.setField(2,h);
 
 
  // Write the fields that you've set all at once.
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 
    delay(sendDelay);    
}

the problem is that you didn’t read the docs before using blynk.

there you will find a part about delays & blynk. read it, understand it, then remove this from your code:

…and replace it with simple timer (blynk timer)

2 Likes

are you using wemos d1 mini as your board? I will be doing a similar project soon a but only need open/close door capability and read magnetic switch status. I can take some ideas from your project that way

@rav527 Very old topic… If you need assistance with your own project, please create your own current topic with details. Thanks. EDIT - looks like you did :+1: