Kirjoittaja Aihe: Mehiläispesän painon tarkkailu  (Luettu 18429 kertaa)

Mikaim

  • *
  • Viestejä: 2
Mehiläispesän painon tarkkailu
« : Huhtikuu 24, 2013, 04:30:16 ap »
Tässä threadissa olisi tarkoitus seurata minun ja 2 muun opiskelijan tiedonkeruuprojektia ja samalla kirjoitella ohjetta samanlaisen järjestelmän rakentamiseen kiinnostuneille.

Aluksi vähän taustaa:
Meille annettiin projektiksi kasata mehiläispesän painoa autonomisesti tarkkaileva systeemi mahdollisimman alhaisin kustannuksin.
Projektin ensimmäisenä päivänä käyttöömme annettiin henkilövaaka, Arduino Mega 2560 ja raaka suunnitelma siiitä, miten voisimme toimia. Tarkoitus olisi siis liittää Arduino jotenkin henkilövaakaan, kerätä sen mittaama paino ja lähettää se eteenpäin.

Tällä hetkellä järjestelmä toimii vaihtelevasti, mutta aiemmat versiot ovat olleet melko luotettavia. Liitteenä 4. toukokuuta käynnissä oleva mittaus.

Inspiraatiota projektiin olemme saaneet Dušan Stojkovićin blogista, jossa hän rakentaa järjestelmän, joka lukee vaa'an lcd-näyttöä.
http://quo.vadis.stojkovic.ch/hacking-a-weighing-scale/
« Viimeksi muokattu: Helmikuu 27, 2016, 02:46:56 ip kirjoittanut qwerty »

Mikaim

  • *
  • Viestejä: 2
Vs: Mehiläispesän painon tarkkailu
« Vastaus #1 : Huhtikuu 24, 2013, 05:32:01 ap »
Tämänhetkinen järjestelmä sisältää
Colinen henkilövaaka http://www.clasohlson.com/fi/Henkil%C3%B6vaaka-Coline/Pr341551000
Arduino Mega 2560 http://arduino.cc/en/Main/ArduinoBoardMega2560
Transistori
Pari vanerilevyä

Tarkoituksemme on siis lukea arduinon avulla henkilövaa'an mittaamia arvoja ja mielestämme helpoin ratkaisu on lukea lcd-näytölle meneviä signaaleja, samalla tavoin kuin Dušan Stojković teki blogissaan. Siirtämällä piirilevyn ja näytön välissä olevaa kontaktiliuskaa saimme määriteltyä mitkä levyn pinneistä vaikuttivat mihinkin näytön segmenttiin.



Onneksemme piirilevyssä oli testipaikat jokaiselle näyttöön menevälle pinnille, joten "vakoilujohdot" oli helppo juottaa kiinni. Juotimme kaikkiaan 19 johtoa vaa'an piirilevyyn: 15 johtoa näytön lukemiseen, 2 johtoa syöttääksemme virtaa ja 2 johtoa vaa'an kontrolloimiseen. Antureilta tulevat johdot oli tehdasjuotettu melko heikosti, joten niitä piti jatkuvasti korjailla. Varovaisuudella säästää aikaa :)
Testatessamme järjestelmää, huomasimme että vaa'an yksiköiden vaihtamiseen tarkoitettu nappi myös pakottaa vaa'an päälle. Laitoimme transistorin napin paikalle jotta pystyisimme kontrolloimaan vaakaa arduinolla.






Johdot liitettiin arduinoon siten, että segmenttipinnit menevät digitaalipaikkoihin 23 - 45, taustasignaalit analogipaikkoihin 0, 1 ja 2, transistori analogipaikkaan 4 ja virtajohdot omille paikoilleen.

Ohjelma lukee näytölle meneviä signaaleja, tulkitsee niiden perusteella näytöllä lukevan arvon ja lähettää sen seriaalia käyttäen eteenpäin tietokoneelle, jossa Seriot lähettää tiedon eteenpäin thingspeakiin. Koodi on tehty arduoinon omalla ohjelmalla.

Koodia: [Valitse]

// Näytön pinnissä 6 vika. kymmenissä ysistä tulee kolmonen.
//
//25.6 KG --> Vaaka vaihtaa LB:hin!
//
//


#include <SoftwareSerial.h>


// Determination of waiting times
const long wtime = 51200; // Waiting time when the measurement is done correctly (in milliseconds, 30min = 1800000ms) Program cycle is about 8,7 seconds.
const long ctime = 891100;   // Waiting time when measurement errors, zeroes etc., occur (milliseconds)               
//291300 5min
//891300 15min
//1791300 30min
//
// Creating variables
int lcdA=0,lcdB=0,lcdC=0;
bool lcd1,lcd2,lcd3,lcd4,lcd5,lcd6,lcd7,lcd8,lcd9,lcd10,lcd11,lcd12;
bool a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12;
bool b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12;
bool c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12;
bool lb,st,kg, kalat;
bool pin3;
unsigned int x[6], y[6], z[6], c[5];
int dec, ones, tens, hund;
float weight;
float weight0;
float weight1;
float weight2;
float weight3;
float weight4;
float tester[10];

// Creating a serial connection
void setup() {
  Serial.begin(57600);   
}

// A check to ensure that the scale is using the correct unit (kg)
void Kilos() {
  while (pin3 == false) {
    while (kalat == 0) {
      lcdA  = analogRead(A0);
      lcdB  = analogRead(A1);
      lcdC  = analogRead(A2);
      lcd3  = digitalRead(41);

      if (lcdA>200 && lcdB>200 && lcdC<100) {
        pin3=lcd3;
        kalat=1;
      }
    }
    if (pin3 == false) {
      digitalWrite(A3, HIGH);
      delay(200);
      digitalWrite(A3, LOW);
      delay(1000);
      kalat=0;         
    }

  }
}


// Measuring program
void Measure() {
  for (int i=0; i<6; i++){

    // Zeroing the pin values
    lcdA  = 0;
    lcdB  = 0;
    lcdC  = 0;
    lcd1  = 0;
    lcd2  = 0;
    lcd3  = 0;
    lcd4  = 0;
    lcd5  = 0;
    lcd6  = 0;
    lcd7  = 0;
    lcd8  = 0;
    lcd9  = 0;
    lcd10 = 0;
    lcd11 = 0;
    lcd12 = 0;

    // Reading the pins of the lcd
    lcdA  = analogRead(A0);
    lcdB  = analogRead(A1);
    lcdC  = analogRead(A2);
    lcd1  = digitalRead(45);
    lcd2  = digitalRead(43);
    lcd3  = digitalRead(41);
    lcd4  = digitalRead(39);
    lcd5  = digitalRead(37);
    lcd6  = digitalRead(35);
    lcd7  = digitalRead(33);
    lcd8  = digitalRead(31);
    lcd9  = digitalRead(29);
    lcd10 = digitalRead(27);
    lcd11 = digitalRead(25);
    lcd12 = digitalRead(23);

    // Saving A-level segments into variables a1-a12
    if (lcdA<100 && lcdB>200 && lcdC>200) {
      a1=lcd1;
      a2=lcd2;
      a3=lcd3;
      a4=lcd4;
      a5=lcd5;
      a6=lcd6;
      a7=lcd7;
      a8=lcd8;
      a9=lcd9;
      a10=lcd10;
      a11=lcd11;
      a12=lcd12;
    }

    // Saving B-level segments into variables b1-b12
    if (lcdA>200 && lcdB<100 && lcdC>200) {
      b1=lcd1;
      b2=lcd2;
      b3=lcd3;
      b4=lcd4;
      b5=lcd5;
      b6=lcd6;
      b7=lcd7;
      b8=lcd8;
      b9=lcd9;
      b10=lcd10;
      b11=lcd11;
      b12=lcd12;
    }

    // Saving C-level segments into variables c1-c12
    if (lcdA>200 && lcdB>200 && lcdC<100) {
      c1=lcd1;
      c2=lcd2;
      c3=lcd3;
      c4=lcd4;
      c5=lcd5;
      c6=lcd6;
      c7=lcd7;
      c8=lcd8;
      c9=lcd9;
      c10=lcd10;
      c11=lcd11;
      c12=lcd12;
    }

    // Checking the number in the decimal
    // if ( a1 &&  a2 ==  true &&  b1 && !b2 && b3 == true &&  c1 &&  c2 ==  true) x[i]=0;
    if ( a1 && !a2 ==  true &&  b1 && !b2 ==  true && !c1 && !c2 ==  true) x[i]=1;
    if ( a1 &&  a2 ==  true && !b1 &&  b2 ==  true &&  c1 &&  c2 ==  true) x[i]=2;
    if ( a1 &&  a2 ==  true &&  b1 &&  b2 && !b3 == true &&  c1 && !c2 ==  true) x[i]=3;
    if ( a1 && !a2 ==  true &&  b1 &&  b2 ==  true && !c1 && !c2 ==  true) x[i]=4;
    if (!a1 &&  a2 ==  true &&  b1 &&  b2 ==  true &&  c1 && !c2 ==  true) x[i]=5;
    if (!a1 &&  a2 ==  true &&  b1 &&  b2 ==  true &&  c1 &&  c2 ==  true) x[i]=6;
    if ( a1 &&  a2 ==  true &&  b1 && !b2 && !b3==  true && !c1 && !c2 ==  true) x[i]=7;
    if ( a1 &&  a2 ==  true &&  b1 &&  b2 ==  true &&  c1 &&  c2 ==  true) x[i]=8;
    if ( a1 &&  a2 ==  true &&  b1 &&  b2 &&  b3 == true &&  c1 && !c2 ==  true) x[i]=9;

    // Checking the number in ones
    if ( a4 &&  a5 ==  true &&  b4 && !b5 && b6 == true &&  c4 &&  c5 ==  true) y[i]=0;
    if ( a4 && !a5 ==  true &&  b4 && !b5 ==  true && !c4 && !c5 ==  true) y[i]=1;
    if ( a4 &&  a5 ==  true && !b4 &&  b5 ==  true &&  c4 &&  c5 ==  true) y[i]=2;
    if ( a4 &&  a5 ==  true &&  b4 &&  b5 && !b6 == true &&  c4 && !c5 ==  true) y[i]=3;
    if ( a4 && !a5 ==  true &&  b4 &&  b5 ==  true && !c4 && !c5 ==  true) y[i]=4;
    if (!a4 &&  a5 ==  true &&  b4 &&  b5 ==  true &&  c4 && !c5 ==  true) y[i]=5;
    if (!a4 &&  a5 ==  true &&  b4 &&  b5 ==  true &&  c4 &&  c5 ==  true) y[i]=6;
    if ( a4 &&  a5 ==  true &&  b4 && !b5 && !b6 ==  true && !c4 && !c5 ==  true) y[i]=7;
    if ( a4 &&  a5 ==  true &&  b4 &&  b5 ==  true &&  c4 &&  c5 ==  true) y[i]=8;
    if ( a4 &&  a5 ==  true &&  b4 &&  b5 &&  b6 == true &&  c4 && !c5 ==  true) y[i]=9;

    // Checking the number in tens
    if ( a7 &&  a8 ==  true &&  b7 && !b8 && b9 == true &&  c7 &&  c8 ==  true) z[i]=0;
    if ( a7 && !a8 ==  true &&  b7 && !b8 ==  true && !c7 && !c8 ==  true) z[i]=1;
    if ( a7 &&  a8 ==  true && !b7 &&  b8 ==  true &&  c7 &&  c8 ==  true) z[i]=2;
    if ( a7 &&  a8 ==  true &&  b7 &&  b8 && !b9 == true &&  c7 && !c8 ==  true) z[i]=3;
    if ( a7 && !a8 ==  true &&  b7 &&  b8 ==  true && !c7 && !c8 ==  true) z[i]=4;
    if (!a7 &&  a8 ==  true &&  b7 &&  b8 ==  true &&  c7 && !c8 ==  true) z[i]=5;
    if (!a7 &&  a8 ==  true &&  b7 &&  b8 ==  true &&  c7 &&  c8 ==  true) z[i]=6;
    if ( a7 &&  a8 ==  true &&  b7 && !b8  && !b9 ==  true && !c7 && !c8 ==  true) z[i]=7;
    if ( a7 &&  a8 ==  true &&  b7 &&  b8 ==  true &&  c7 &&  c8 ==  true) z[i]=8;
    if ( a7 &&  a8 ==  true &&  b7 &&  b8 &&  b9 == true &&  c7 && !c8 ==  true) z[i]=9;

    // Checking hundreds
    if ( a10 && !a11 ==  true &&  b10 && !b11 && !b12  ==  true && !c10 && !c11 ==  true) c[i]=1;

    delay(3); //default 5. 4 WORKS better (3-6 ?)

  } // End of for-loop

  // Analysis of decimals
  if ( x[3] == x[4] ) dec = x[4];

  // Analysis of ones
  if ( y[3] == y[4] ) ones = y[4];

  // Analysis of tens
  if ( z[3] == z[4] ) tens = z[4];

  // Analysis of hundreds
  //if ( c[1] == c[4] ) hund = c[4];

                                     /*
                                    // DEBUGGING PART
                                    Serial.print(z[0]);
                                    Serial.print(" ");
                                    Serial.print(z[1]);
                                    Serial.print(" ");
                                    Serial.print(z[2]);
                                    Serial.print(" ");
                                    Serial.print(z[3]);
                                    Serial.print(" ");
                                    Serial.print(z[4]);
                                    Serial.print(" ");
                                    Serial.print(z[5]);
                                    Serial.print("   ");
                                    Serial.print(y[0]);
                                    Serial.print(" ");
                                    Serial.print(y[1]);
                                    Serial.print(" ");
                                    Serial.print(y[2]);
                                    Serial.print(" ");
                                    Serial.print(y[3]);
                                    Serial.print(" ");
                                    Serial.print(y[4]);
                                    Serial.print(" ");
                                    Serial.print(y[5]);
                                    Serial.print("   ");
                                    Serial.print(x[0]);
                                    Serial.print(" ");
                                    Serial.print(x[1]);
                                    Serial.print(" ");
                                    Serial.print(x[2]);
                                    Serial.print(" ");
                                    Serial.print(x[3]);
                                    Serial.print(" ");
                                    Serial.print(x[4]);
                                    Serial.print(" ");
                                    Serial.print(x[5]);
                                    Serial.print("   ");                                   
                                    // DEBUGGING END
                                    */
 
  delay(50); //default 30
}    // End of the measuring program


void reset() {

  // Zeroes all used variables
  x[0] = 0;
  x[1] = 0;
  x[2] = 0;
  x[3] = 0;
  x[4] = 0;
  y[0] = 0;
  y[1] = 0;
  y[2] = 0;
  y[3] = 0;
  y[4] = 0;
  z[0] = 0;
  z[1] = 0;
  z[2] = 0;
  z[3] = 0;
  z[4] = 0;
  x[5] = 0;
  y[5] = 0;
  z[5] = 0;
  a1=a2=a3=a4=a5=a6=a7=a8=a9=a10=a11=a12=0;
  b1=b2=b3=b4=b5=b6=b7=b8=b9=b10=b11=b12=0;
  c1=c2=c3=c4=c5=c6=c7=c8=c9=c10=c11=c12=0;
  dec = 0;
  ones = 0;
  tens = 0;
  weight = 0;
  weight = 0.0;
  pin3=0;
  tester[0] = 0;
  tester[1] = 0;
  tester[2] = 0;
  tester[3] = 0;
  tester[4] = 0;
  tester[5] = 0;
  tester[6] = 0;
  tester[7] = 0;
  tester[8] = 0;
  tester[9] = 0;
  tester[10] = 0;
}

void rassi() {

  // Zeroes all used variables
  x[0] = 0;
  x[1] = 0;
  x[2] = 0;
  x[3] = 0;
  x[4] = 0;
  y[0] = 0;
  y[1] = 0;
  y[2] = 0;
  y[3] = 0;
  y[4] = 0;
  z[0] = 0;
  z[1] = 0;
  z[2] = 0;
  z[3] = 0;
  z[4] = 0;
  x[5] = 0;
  y[5] = 0;
  z[5] = 0;
  a1=a2=a3=a4=a5=a6=a7=a8=a9=a10=a11=a12=0;
  b1=b2=b3=b4=b5=b6=b7=b8=b9=b10=b11=b12=0;
  c1=c2=c3=c4=c5=c6=c7=c8=c9=c10=c11=c12=0;
  dec = 0;
  ones = 0;
  tens = 0;
  weight = 0;
  weight = 0.0;
}


// Main program
void loop()
{
  delay(1000); //default 1000

  // Zeroing
  reset();

  // Transistor acts as a "reset switch" for the scale
  digitalWrite(A3, HIGH);
  delay(200);  //default 200
  digitalWrite(A3, LOW);
  delay(500); //default 500

  // Checking the unit
  Kilos();
  delay(1400); //default 3000. 3005 HYVÄ

  // Measuring, loops 5 times
  for (int m=0; m<11; m++){
    Measure();

    weight = 10.0*tens + 1.0*ones + 0.1*dec;
    tester[m] = weight;    // Saving the weight into a vector
    //Serial.print(tester[m]);
    //Serial.print("\n");   
    delay(100); //default 400
    //rassi();
  }


  // Checks the similarity between gotten values           
  float Reading;
    //Serial.print(tester[0]);
    //Serial.print(" ");
    // Serial.print(tester[1]);
    // Serial.print(" ");
    //  Serial.print(tester[2]);
    //  Serial.print(" ");
       Serial.print(tester[3]);
       Serial.print(" ");
        Serial.print(tester[4]);
        Serial.print(" ");
         Serial.print(tester[5]);
         Serial.print(" ");
          Serial.print(tester[6]);
          Serial.print(" ");
           Serial.print(tester[7]);
           Serial.print(" ");
            Serial.print(tester[8]);
         //   Serial.print(" ");
         //    Serial.print(tester[9]);
          //   Serial.print(" ");
          //    Serial.print(tester[10]);
              Serial.print("\n");
  if (tester[3] == tester[4] && tester[4] == tester[5] && tester[5] == tester[6] && tester[6] == tester[7] && tester[7] == tester[8] && tester[8] != 0.00 ){ 
    Reading = (tester[3] + tester[4] + tester[5] + tester[6] + tester[7] + tester[8]);
    Reading = (Reading/6);

    Serial.print("\n");
    Serial.print("###BOD");
    Serial.print("\n");
    Serial.print("Vaaka1,");
    delay(100);
    Serial.print(Reading);
   Serial.print("\n");
    Serial.print("###EOD");
    Serial.print("\n");
    delay(ctime);     // Values were correct, program waits the set amount of time                             
  }
  else if (tester[3] == 0 || tester[4] == 0 || tester[5] == 0 || tester[6] == 0) {
    Serial.print("\n");
    Serial.print("###BOD");
    Serial.print("\n");
    Serial.print("Vaaka1, 0");
    Serial.print("\n");
    Serial.print("###EOD");
    Serial.print("\n");
    delay (wtime);  // The values were not correct, program waits set time and measures again
  }

  else {     
    delay (wtime);  // The values were not correct, program waits set time and measures again
  }



}    // End of the main program


Virrankulutus on vielä mittaamatta, mutta sen ei pitäisi olla kovin suuri.

Otimme vaa'asta sen anturit ja osan kuoresta irti ja kiinnitimme ne vanerilevyjen väliin, jotta saisimme tasapainotettua pesän paremmin vaa'an päälle. Tämä aiheutti hieman vaihtelevuutta järjestelmän toiminnassa, mutta yritämme korjata aiheutuneita bugeja.


Haniclub

  • *
  • Viestejä: 9
Vs: Mehiläispesän painon tarkkailu
« Vastaus #2 : Toukokuu 04, 2014, 09:08:49 ip »
Rakentelin " kiikun " pesän punnitukseen.
Tarkan kokonaispainon tarkka punnitus vähän haastava, mutta painonmuutokset näkyvät  0,5 kg puntarilla hyvin.
makeaa elämää