Giuseppe Allocca
/* Box Food Saver V.1.0
code written by Giuseppe Allocca
FabLab class 2018
Santa Chiara FabLab SIena Italy
*/
//pins definition
int powerled = 3; //white led
int comled = 2;//blu led
int sensor= 16;
int sensor_value=0;
int button=5;
int valbutton=0;
int valv=8;
int pump=17;
int draweropen=0;
int empty=0;
// waitButton Function
void waitButton()
{//start waitButton
valbutton = digitalRead(button); //read button value
while(digitalRead(5) == 0){
// blue led blink wait button pressed
digitalWrite(comled,HIGH);delay(10);digitalWrite(comled,LOW);delay(10);}
OpenDrawer();// when button is pressed then call openDrawer function
}// End waitButton Function
// closeDrawer Function
void closeDrawer()
{//start closeDrawer
while(analogRead(16) >500 ){
// blue led blink wait button pressed
digitalWrite(comled,HIGH);delay(10);digitalWrite(comled,LOW);delay(10);}
vacuum();
}// End closeDrawer Function
// OpenDrawer Function
void OpenDrawer()
{//start openDrawer
digitalWrite(comled,HIGH);
digitalWrite(valv,LOW);
delay(200);
digitalWrite(valv,HIGH);
digitalWrite(comled,LOW);
delay(50);
closeDrawer();
}// End OpenDrawer Function
// vacuum Function
void vacuum()
{//start vacuum
digitalWrite(comled,HIGH);
digitalWrite(pump,LOW);
delay(1000);
digitalWrite(pump,HIGH);
digitalWrite(comled,LOW);
delay(50);
waitButton();
}// End vacuum Function
void setup() {
// initialize pin input/output
pinMode(powerled, OUTPUT);
pinMode(comled, OUTPUT);
pinMode(sensor, INPUT);
pinMode(button, INPUT);
pinMode(valv,OUTPUT);
pinMode(pump,OUTPUT);
// turn LED on:
digitalWrite(powerled, HIGH);//Board power-on
digitalWrite(comled,LOW);//comled off
//turn off pump and valve
digitalWrite(pump,HIGH);//HIGH value
digitalWrite(valv,HIGH);//turn OFF the RELAYS
}// end void setup
// "void loop" only read sensor value and call the correct function,
// after this , logical loop work alone
void loop() {
sensor_value=analogRead(sensor); // read the sensor value from pin 16
/* sensor control: is the drawer close?
if yes call vacuum function, else wait until the drawer will be closed
*/
if ((sensor_value)<500)
{vacuum();
} // end if
closeDrawer();
} //end void loop
Box Food Saver Software v.1.0
So…now is the time to program software for my final project…. to do it I organize the desk with everything I need…
My Desk ready to mental war!
programming: it is a logical flow
Although it is night and I am very tired ... I try to concentrate on the logic of the software, making a diagram of what the program should do.
The
magnetic
sensor
seems
to
be
the
key
to
all
actions.
Reading
its
value
I
can
understand
if
the
drawer
is
open
or
closed,
then
perform
the
appropriate procedure.
The
button
will
allow
me
to
open
the
drawer,
turning
on
the
solenoid
valve
that
will
let
the
air
in
the
box.
When
the
drawer
is
closed,
the
magnetic
sensor
will
detect
the
magnetic
field
and
perform
the
vacuum
function.
At
this
point
the
program
will
be
waiting
of
the
button
and the cycle will restart. The following diagram summarizes what has been said.
Write….on paper
Initially
I
write
the
code
in
my
notebook,
to
reason
I
prefer
paper
and
pen
...
the
old
way!
I
create
the
functions
I
need
for
the
logical cycle, there are four.
my sketch of logic diagram
I don't remember the "while" command, how work...
For
the
functions
of
the
magnetic
sensor
and
the
button,
I
need
to
use
the
"WHILE"
command,
but
I
do
not
remember
exactly
how
to
use
it.
So
I
decide to read the official Arduino documentation and I look for the command that interests me.
Reference > Language > Structure > Control structure > While
while
[Control Structure]
Description
A
while
loop
will
loop
continuously,
and
infinitely,
until
the
expression
inside
the
parenthesis,
()
becomes
false.
Something
must
change
the
tested
variable,
or
the
while
loop
will
never
exit.
This
could
be
in
your
code,
such
as
an
incremented
variable,
or
an
external
condition,
such
as
testing a sensor.
Syntax
while(condition){
// statement(s)
}
The condition is a boolean expression that evaluates to true or false.
Example Code
var = 0;
while(var < 200){
// do something repetitive 200 times
var++;
}
Write….my software
At
this
point
I’m
ready
to
start
to
write
the
code
in
arduino
language
(wiring)
to
program
my
board
and
manage
my
Box
Food Saver.After two hours the code seem be ready like this:
This is the video of my final project and you can see the software work very well...but the vacuum is not perfect! (very hardly to do!)
Original Files and Useful Links
Final Project Software