Tervetuloa mehiläisien kasvatukseen, yhdyskunnan automaatioon, suojaamiseen ja tiedonkeruuseen keskittyneelle sivustolle
// Project needs three libraries that are not part of arduino install.
#include <Average.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//Define used variables
#define MLuku 60 // The amount of minutes in an hour
#define TLuku 24 // The amount of hours in a day
#define WLuku 6 // The amount of hours to warm
#define HLuku 6 // The amount of minutes to warm
#define ONE_WIRE_BUS 2 // Data wire is plugged into pin 2 on the Arduino
#define Rele 53 //Pin for the relay
float Minuutti[MLuku]; // Slot to hold the measuring data for the minutes
float Tunti[TLuku]; // Slot to hold hourly data
float TempKA; // Variable for Average amount
int LEsto = 0; // Variable to indicate blocking of heating
int EstoAika = 15; // Variable to hold the time of blocking of heating
int Timma; // Variable to store the hour
int z = 0; // Counter for the heater
long lastminute = 0;
long minute = 59700; // Variable for the delay time, a minute for this project
boolean Warn; // Variable for enabling the heater
void setup()
{
// start serial port
Serial.begin(19200);
pinMode(Rele, OUTPUT);
}
void loop()
{
for (int j=0; j<TLuku; j++){ //
Mittaus(); // Jump to the measuring part
TempKA = mean(Minuutti,MLuku); // Measure the average temp of the minutes
Serial.print("Tunti: ");
Serial.print(j);
Serial.print(" Avg: ");
Serial.print(TempKA);
Serial.print("\n");
delay(100);
Reset1(); //Reset the temp of the stored minutes
delay(100);
Tunti[j] = TempKA; //Store the average temp of the minutes to the Vector
//Serial.print("Hourly averages's check \n");
//Serial.print(Tunti[j]);
//Serial.print("\n");
//Serial.print(Tunti[j-1]);
//Serial.print("\n");
//Serial.print(Tunti[j-2]);
//Serial.print("\n");
Serial.print(LEsto);
Serial.print(" Estobitti\n");
Serial.print(EstoAika);
Serial.print(" Eston tunti \n");
Timma = j; //Store the number of the current hour
NoWarm(); //Check if the 20 hour delay has passed
if (LEsto == 0 && Tunti[j-1] != 0 && Tunti[j-2] != 0) //If the restrictor of the heater is not on, enable the heater
{
Warm();
}
if (Tunti[j-1] > Tunti[j-2] && Tunti[j] > Tunti[j-1] && Tunti[j-2] != 0 && Tunti[j-1] != 0 && z >= 6) {
//If current hours temp has risen since the two ones before: delay heating for 20h
if (LEsto == 0) {
LEsto = 1; //Set blocking on
EstoAika = j; //set the hour of the blocking
z=0; //reset the counter
Warn = false; //disable the heater
Serial.print("No Warming for 20h");
Serial.print("\n ");
}
}
else if ( Tunti[j-1] == 0 && Tunti[j-2] == 0) { //If the hour counter goes from 23 -> 0 the check needs to be done slightly different.
Serial.print("\n Midnight \n");
if (Tunti[TLuku-1] > Tunti[TLuku-2] && Tunti[j] > Tunti[TLuku-1] && z >= 6) {
Serial.print("\n ");
if (LEsto == 0) {
LEsto = 1;
EstoAika = j;
z=0;
Warn = false;
Serial.print("No Warming for 20h");
Serial.print("\n ");
}
}
}
}
} // End of the main loop
void Mittaus()
{
for (int i=0; i<MLuku; i++){ //for 60 times
OneWire oneWire(ONE_WIRE_BUS); //Enable the OneWireBus
DallasTemperature sensors(&oneWire); //Enable the Dallas Library
sensors.begin(); //Start the bus
delay(10);
sensors.requestTemperatures(); //Request temp from the sensor
delay(10);
Minuutti [i] = sensors.getTempCByIndex(0); //Get and store the value from the first (and only) sensor on the bus
Serial.print(Minuutti[i]);
Serial.print("\n");
if (i < HLuku && Warn == true) //If usage of heater is enabled: switch it on
{
Serial.print(" Warn ");
digitalWrite(Rele, HIGH); //Modify this to control the relay
}
else
{
digitalWrite(Rele, LOW);
}
delay(minute);
}
}
int NoWarm() //Count when the 20 hours have passed
{
if ( EstoAika == 0 && Timma == 20 ) LEsto = 0;
if ( EstoAika == 1 && Timma == 21 ) LEsto = 0;
if ( EstoAika == 2 && Timma == 22 ) LEsto = 0;
if ( EstoAika == 3 && Timma == 23 ) LEsto = 0;
if ( EstoAika == 4 && Timma == 0 ) LEsto = 0;
if ( EstoAika == 5 && Timma == 1 ) LEsto = 0;
if ( EstoAika == 6 && Timma == 2 ) LEsto = 0;
if ( EstoAika == 7 && Timma == 3 ) LEsto = 0;
if ( EstoAika == 8 && Timma == 4 ) LEsto = 0;
if ( EstoAika == 9 && Timma == 5 ) LEsto = 0;
if ( EstoAika == 10 && Timma == 6 ) LEsto = 0;
if ( EstoAika == 11 && Timma == 7 ) LEsto = 0;
if ( EstoAika == 12 && Timma == 8 ) LEsto = 0;
if ( EstoAika == 13 && Timma == 9 ) LEsto = 0;
if ( EstoAika == 14 && Timma == 10 ) LEsto = 0;
if ( EstoAika == 15 && Timma == 11 ) LEsto = 0;
if ( EstoAika == 16 && Timma == 12 ) LEsto = 0;
if ( EstoAika == 17 && Timma == 13 ) LEsto = 0;
if ( EstoAika == 18 && Timma == 14 ) LEsto = 0;
if ( EstoAika == 19 && Timma == 15 ) LEsto = 0;
if ( EstoAika == 20 && Timma == 16 ) LEsto = 0;
if ( EstoAika == 21 && Timma == 17 ) LEsto = 0;
if ( EstoAika == 22 && Timma == 18 ) LEsto = 0;
if ( EstoAika == 23 && Timma == 19 ) LEsto = 0;
}
void Warm()
{
z=z++;
if (z >= WLuku) { //Warming has been on for the desired time (6h)
Serial.print("\n No Warming (6h full) \n");
Warn = false; //disable warming
}
else if (z < WLuku) { //Warming hasn't been on for the desired time (6h)
Warn = true;
Serial.print(" \n ..Warming.. \n");
}
}
void Reset1() //Reset the temps stored on the minutes vector
{
for (int y=0; y<MLuku; y++){
Minuutti[y] = 0;
}
}
// 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
Page created in 0.120 seconds with 16 queries.