16 Οκτ 2017



Κατασκεύασε το δικό σου beescale.

Τι θα χρησιμοποιήσουμε για την κατασκευή:
-έναν μικροεπεξεργαστή Arduino uno
-arduino gsm shield και μια κεραία SMA
-αισθητήρα βάρους (load cell)
-ενισχυτή σήματος HX711
-αισθητήρα θερμοκρασίας Dallas DS1820
-αισθητήρα υγρασίας DHT11
-4 Αλκαλικές μπαταρίες σε σειρά ώστε να τροφοδοτούν στα 6 V (κάθε μπαταριά είναι 1,5 V)

Αρχικά τοποθετήστε το gsm shield στον Arduino

Τώρα μπορείτε να ανεβάσετε παραδείγματα από το περιβάλλον του Arduino IDE της βιβλιοθήκης GSM για να επιβεβαιώσετε ότι λειτουργεί.

##Αισθητήρας Βάρους

Για να συνδέσουμε τον αισθητήρα βάρους, θα χρησιμοποιήσουμε τον ενισχυτή σήματος HX711. Λάβετε υπ'όψιν σας ότι το GSM shield δεσμεύει τα digital pin 2,3 και 7.
Κύκλωμα
Σχεδιάγραμμα
Αισθητήρας Θερμοκρασίας

Εκτός του αισθητήρα θα χρειαστεί και μια αντίσταση 4,7 ΚΩ.
Κύκλωμα
Σχεδιάγραμμα

##Αισθητήρας Υγρασίας
Κύκλωμα
Σχεδιάγραμμα
Ολοκληρωμένο Κύκλωμα


Ολοκληρωμένο Σχεδιάγραμμα


Κώδικας

#include "DHT.h"
#include "HX711.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LowPower.h>

// Include the GSM library
#include <GSM.h>
//Initialize instances of the classes you're going to use. You're going to need both the GSM and GSMSMS class.
GSM gsmAccess;
GSM_SMS sms;
// PIN Number
#define PINNUMBER ""

// Array to hold the number to send sms
//char numtel[20]= "6949822676";

float therm;
float maza;
float humid;


// ************** ONE WIRE Ds1820
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 6
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);
 
void setupDS1820() {
  // Start up the library
  sensors.begin();
  
}
void readDS1820() {
  sensors.requestTemperatures(); // Send the command to get temperatures
  therm=sensors.getTempCByIndex(0);
  
}

// ************** hx711
// HX711.DOUT - pin #A4
// HX711.PD_SCK - pin #A3

HX711 scale(A4, A3);  // parameter "gain" is ommited; the default value 128 is used by the library
void setuphx711() {
  // Start up the library
// zero factor from SparkFun_HX711_Calibration by sarahalmutlaq
 //long zero_factor = scale.read_average(); //Get a baseline reading
  long zero_factor = 8510214;
  scale.set_scale(2280.f);   // this value is obtained by calibrating the scale with known weights; see the README of the library for details
 //scale.tare();   // reset the scale to 0
 scale.set_offset(zero_factor); //Zero out the scale using a previously known zero_factor for a permanent weight on the scale
}

void readhx711(){

maza= scale.get_units(10), 1;
  

  scale.power_down();           // put the ADC in sleep mode
  delay(1000);
  
}

// ************** DHT11

#define DHTPIN 8     // what pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11 
//#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);
// NOTE: For working with a faster chip, like an Arduino Due or Teensy, you
// might need to increase the threshold for cycle counts considered a 1 or 0.
// You can do this by passing a 3rd parameter for this threshold.  It's a bit
// of fiddling to find the right value, but in general the faster the CPU the
// higher the value.  The default for a 16mhz AVR is a value of 6.  For an
// Arduino Due that runs at 84mhz a value of 30 works.
// Example to initialize DHT sensor for Arduino Due:
//DHT dht(DHTPIN, DHTTYPE, 30);






void setupdht11() {
  dht.begin();
}

void readdht11() {
 Serial.println("*********** DHT11 *********");
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
 
  
  // Check if any reads failed and exit early (to try again).
  if (isnan(h)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

humid=h;
 
}




//Main Code

int wait=1;
void setup(void) {
  // start serial port
  Serial.begin(9600);
 
  //init DS1820
  setupDS1820();
  setuphx711();
  setupdht11();
}
 
void loop(void) { 

  
Serial.print("wait =");
Serial.println(wait);
  if(wait>=3){
   

  readDS1820();
  
 
  scale.power_up();
  delay(500);
  readhx711();
  
  Serial.print("maza in main is ");
  Serial.println(maza);
  
  delay(500);
  readdht11();
  
  Serial.print("humid in main is ");
  Serial.println(humid);
  
  
  
  // ************** GSM
// connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while (notConnected)
  {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }
  Serial.println("GSM initialized");
   
  
  delay(500);
  
  //----------------
  
  // sms text

 
  // send the message
  sms.beginSMS(numtel);
  sms.print("zigizei");
  sms.print(maza);
  sms.print("grammaria ");
  sms.print(" ,hum=");
  sms.print(humid);
  sms.print("%");
  sms.print(" ,temp=");
  sms.print(therm);
  sms.endSMS();
  Serial.println("\nto minima stalthike!\n");
  
//------------

  wait=1;
    }      
    delay(1000);//delay
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);   
  wait++;
  delay(500);

}
delay(10000);
}

πηγη : https://github.com

2 σχόλια: