Jump to content
ELFORUM - Forumul electronistilor
piratu2ro

Problema cantar la iesirea din deep sleep

Recommended Posts

Nu este un copy/paste de pe net, nu ma pricep la programarea, dar am incercat si am reusit cat de cat singur cu ajutorul unui coleg de pe forum si uitanduma pe youtube cum v-am spus. conditia cu "millis" la care era 10 sec. era pusa ca sa trimita din 10 in 10 sec. si era inainte sa sa aflu ca ESP-ul il pot baga la somn , acum pot renunta la ea.

Acum sa descriu ce vreau sa fac:

un sistem de monitorizare care sa imi cantareasca un stup, sa monitorizeze temperatura, presiunea atmosferica, umiditatea si bateria, datele colectate le trimite care un site unde le pot vedea,

mai atasez odata codul unde nu este implementata functia de somn

ca senzor de temperatura si umezeala folosesc un AM2302, pentru presiune atmosferica un BMP280, iar pentru alimentare un acumulator Li-ion de 3.7v 3500mAh cu stabilizator de 3v si cu dvizor de rezistente pentru citirea tensiunii bateriei.

#include <dht.h>
#include "HX711.h"
#include <SoftwareSerial.h>
#include <Adafruit_BMP280.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#include <SPI.h>
#include <ESP8266WiFi.h>

const int LOADCELL_DOUT_PIN = D5;
const int LOADCELL_SCK_PIN = D6;

#define DEBUG true

HX711 scale; // working

dht DHT;
Adafruit_BMP280 barometru;

int k = 0;
int offset = -200; // corectie citire tensiune baterie
char diviziune;

#include "UbidotsMicroESP8266.h"
#define TOKEN  "BBFF-Ii7WT6576bf3pKFdnTc9T4h5IuX9JB0"  // Put here your Ubidots TOKEN
#define WIFISSID "9888O"
#define PASSWORD "p988888966"

Ubidots client(TOKEN);
unsigned long lastMillis = 0;

void setup() {

  Serial.begin(115200);
  delay(10);
  client.wifiConnection(WIFISSID, PASSWORD);

  if (! barometru.begin(0x76 )) {
    Serial.println("Lipsa senzor BMP280, Verifica cablaj!");
    while (1);
  }

  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  scale.read();                 // print a raw reading from the ADC
  scale.read_average(20);       // print the average of 20 readings from the ADC
  scale.get_value(5);           // print the average of 5 readings from the ADC minus the tare weight (not set yet)
  scale.get_units(5), 1;        // print the average of 5 readings from the ADC minus tare weight (not set) divided
  scale.set_scale(393.95f);     // corectie celula greutate

  scale.tare();                 // resetare cantar 0
  scale.read();                 // print a raw reading from the ADC
  scale.read_average(20);       // print the average of 20 readings from the ADC

}

int kg = 0;


void loop() {

  int volt = analogRead(A0);  // pin citire tensiune
  double voltage = map(volt, 0, 1023, 0, 2500) + offset; // map 0-1023 la 0-2500 si factor de corectie
  voltage /= 100;                                       // mv --> V

  float diviziune = (3.7 - 2.5) / 100  ;
  float procent = (voltage - 2.5) / diviziune;
  procent = constrain(procent, 0, 100);

  float weight = scale.get_units(10);
  kg = 0;
  
     if (millis() - lastMillis > 10000) {  ///every 10s
    int readData = DHT.read22(D7);
    float UmiditateExterioara = DHT.humidity;
    float TemperaturaExterioara = DHT.temperature;
    float PresiuneAtmosferica = barometru.readPressure() / 100;

    lastMillis = millis();
    client.add("UmiditateExterioara",UmiditateExterioara );
    client.add("TemperaturaExterioara", TemperaturaExterioara );
    client.add("PresiuneAtmosferica", PresiuneAtmosferica );
    client.add("procent", procent );
    client.add("weight", weight );


    client.sendAll(true);

  }

}

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines