Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Petrache Valentin
Published © GPL3+

Beekeeping with Arduino

Beekeeping (or apiculture, from Latin: apis "bee") is the maintenance of honey bee colonies, commonly in hives, by humans.

IntermediateWork in progress2 days19,143
Beekeeping with Arduino

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
×1
SparkFun hx711 amplifier board
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×2
Resistor 10k ohm
Resistor 10k ohm
×2
Resistor 2.21k ohm
Resistor 2.21k ohm
×1
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×1
load scale sensor
×1
Li-Ion Battery 1000mAh
Li-Ion Battery 1000mAh
×1

Hand tools and fabrication machines

dremel

Story

Read more

Schematics

schematic

Code

ArduinoBeehive.ino

C/C++
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <dht.h>
#include "HX711.h"
#include <SPI.h>
#include <WiFi101.h>


char ssid[] = "yourNetwork";      // your network SSID (name)
char pass[] = "secretPassword";   // your network password
int keyIndex = 0;                 // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

WiFiServer server(80);

// HX711.DOUT	- pin #A1
// HX711.PD_SCK	- pin #A0

HX711 scale(A1, A0);	


#define DHT21_PIN 10

dht DHT;


int buttonState1 = 0;
const int But2 = 11; 
 
int buttonState = 0; 
const int But1 = 12; 

byte termometru[8] = {B00100, B01010, B01010, B01110, B01110, B11111, B11111, B01110};

byte picatura[8] = {B00100, B00100, B01010, B01010, B10001, B10001, B10001, B01110,};

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); 
 
void setup()
{	//Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  server.begin();
  // you're connected now, so print out the status:
  printWifiStatus();
	scale.set_scale(2280.f);         
	scale.tare();				     
	lcd.begin(20,2);
	lcd.backlight();
	lcd.clear(); 
	lcd.createChar(1,termometru);
	lcd.createChar(2,picatura);
	pinMode(But1, INPUT);
	pinMode(But2, INPUT);
	Serial.begin(19200); 
 }

void display()
{
  lcd.setCursor(2,0); 
  lcd.print(scale.get_units(20),1);  //does an average of 20 readings from scale and displays on the lcd
  lcd.setCursor(12, 0);
  lcd.print("Kg");  
 
  lcd.setCursor(0, 1);
  lcd.write(1); 
  lcd.setCursor(2,1); 
  lcd.print(DHT.temperature, 1); 
  lcd.setCursor(6, 1);
  lcd.print(" ");
  lcd.setCursor(7, 1);
  lcd.print((char)223); 
  lcd.print("C"); 
   
  lcd.setCursor(10, 1);
  lcd.write(2); 
  lcd.setCursor(12, 1);
  lcd.print(DHT.humidity, 1); 
  lcd.setCursor(14, 1);
  lcd.print(" "); 
  lcd.setCursor(15,1);
  lcd.print("%"); 
 } 
 
void wifi() { // listen for incoming clients
  WiFiClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int i = 0; i < 6; i++) {
			client.print("Weight: ");
			client.print(scale.get_units(20),1);
			client.println("kg");
			client.print("Humidity: ");
			client.print(DHT.humidity, 1);
			client.println("%");
			client.print("Temperature: ");			
			client.print(DHT.temperature, 1); 			
			client.println("Celsius");
          }
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);

    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}
 
void buton()
{
buttonState = digitalRead(But1);
     delay(10); 
    if (buttonState == HIGH) 
        { lcd.backlight(); }
        else {
        lcd.noBacklight(); 
        }}
		
void resetScale()
{
buttonState1 = digitalRead(But2);
     delay(10); 
    if (buttonState1 == HIGH) 
        {scale.tare();}
        else {
       
        }}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

		
void loop() 
{
	int chk = DHT.read21(DHT21_PIN);
	display(); 
	resetScale();
	buton();
	wifi();
	Serial.print("T: ");
	Serial.println(DHT.temperature));
	Serial.print("H: ");
	Serial.println(DHT.humidity);
	Serial.print("W: ");
	Serial.println(scale.get_units(20),1);
  
}

HX711 library

Credits

Petrache Valentin

Petrache Valentin

4 projects • 26 followers
Electronic engineer and hobbyist, during my life I have worked with all known embedded motherboards and shields. I'm looking to improve life with great ideas.

Comments