Instructables

Arduino nano controling a dental vacuum motor by checking liquid waste level

Picture of Arduino nano controling a dental vacuum motor by checking liquid waste level
/*
    //////////////                            DESCRIPTION                      ///////////////////////////////////////////////////////////
   This is an application for controling a dental vacuum motor.
   The motor needs a 24 volt signal(via a relay connected to arduino's digital output) to turn ON.
   When its turned ON it fills a bootle with liquids form patient's mouth.
   Bottle has  two level switches (sensors) for LOW and HIGH level of liquid.
   Motor state must be ON until liquid reaches high level.Then motor state must be OFF so liquid goes to drain (that happens only when motor is OFF) and then turned ON again.
   All this works when dental vacuum tips are on doctors hands.
   The stand for dental vacuum tips has a switch so when placed in stand the switch is OPEN and when in dentist's hand the switch is CLOSE.
   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   *****************code by ALEXANDROS PAGONIDIS     http://www.BiomedicalTechnology.gr  *********************************************************

*/


#include <Time.h>  //arduino can read time for 50 days from initialization and then resets time again

unsigned long time; 
unsigned long time2;




/////*** numbers of pins************************/////
int lowLevelPin  = 2;  // digital pin ( 2)  connected to LOW  level switch of bootle.                      Pin 1 of switch goes to digital pin of arduino and pin 2 of switch goes to GROUND.
int highLevelPin = 3;  // digital pin ( 3)  connected to HIGH level switch of bootle.                      Pin 1 of switch goes to digital pin of arduino and pin 2 of switch goes to GROUND.
int valveTipsPin = 4;  // digital pin ( 4)  connected to the stand's  switch where vacuum tips are placed. Pin 1 of switch goes to digital pin of arduino and pin 2 of switch goes to GROUND.
int motorPin     =12;  // digital pin  5V DC relay module witch controls motor's 24V AC singal (CAUSE MY CHINESE MODULE IS STUPID LOGIG IS INVERTED SO WHEN POWER OFF NO TO TURN ON THE MOTOR)
int ledPin       =13;  // internal led of arduino board

/*
THIS CONNECTIONS ARE FOR SPECIFIC SIRONA CHAIR WITH CATANNI ELECTRONICS
PINS  AND SOME OF CABLES COLORS:
1,19,12,13,14 : NOT CONNECTED

2, 3:  24VAC INPUT FROM BOX     
9,11: 24VAC OUTPUR TO MOTOR     (PINS 3,9 ARE PINS OF A NORMALLY OPEN RELAY)

4, 5: TIPS SWITCH (WHERE IN PIN 4  YELLOW-BROWN CABLES  5 WHITE-GRAY CABLES           

  6  : BOTTLE HIGH LEVEL SENSOR (CABLE RED  )
  7  : BOTTLE  LOW LEVEL SENSOR (CABLE WHITE)
  8  : BOTTLE COMMON,MIDDLE     (CABLE BLACK)


*/



/////*** values of swithes state (HIGH=OPEN or LOW=CLOSE)
int valveTipsVal;
int lowLevelVal ;
int highLevelVal;




/////*** delay times in msecs*******************/////
int timeOfReadings          =  200;
int problemInLowLevelSwitch = 8000;
int timeOfMotorMinON        = 4000;  
int timeOfMotorMaxON        = 8000;
int timeOfTipOnStand        = 2500;
int timeOfTipRest           = 999;

/////*** val that states if motor is ON Or OFF***///
int motorState;        // gets values of 0 or 1

//////////////////////////////////////






void setup()
{
 

 
 
  //configure pins as an input and enable the internal pull-up resistor
  pinMode(lowLevelPin,INPUT_PULLUP);
  pinMode(highLevelPin,INPUT_PULLUP);
  pinMode(valveTipsPin,INPUT_PULLUP);

 
  //configure pins as outputs
  pinMode(motorPin,     OUTPUT);
  pinMode(ledPin,       OUTPUT);        //internal on chip led indicator

  motorOFF();                           // When arudino TIPS_CHECKs up motor should be turned OFF



}// end of setup
////////////////////////////////



void loop()
{

/*
   digitalRead with INPUT_PULLUP setup reads:
   HIGH when a switch or button  is as an open    connection to the ground.
   LOW  when a switch or button  is as a  closed  connection to the ground.
*/




valveTipsVal=digitalRead(valveTipsPin);delay(1); //read
lowLevelVal =digitalRead( lowLevelPin);delay(1); //     all
highLevelVal=digitalRead(highLevelPin);delay(1); //         swithes


  
    ////////////////////////////////////////
  
TIPS_CHECK:

                         

while (valveTipsVal == LOW)     //TIPS_CHECK while ***** when vacuum tips are in dentist's hand, stand's switch is closed. *****
  {
    valveTipsVal=digitalRead(valveTipsPin);delay(1);
    if (valveTipsVal==HIGH)
{goto TIPS_CHECK;}     //  check on all levels of code if valve tips are on stand and if yes goto TIPS_CHECK
 


  delay (timeOfReadings);                               //time of readings...wait for sensors to stabilize and calm down proccessor from many readings
    
              
LEVEL_CHECK_RUN:
  {

    lowLevelVal =digitalRead( lowLevelPin);delay(1);   //read
    highLevelVal=digitalRead(highLevelPin);delay(1);   //     level swithes
   
    if (lowLevelVal == HIGH  && highLevelVal == HIGH)  // if high level switch OPEN, low level switch OPEN
           {lowLevelVal =digitalRead( lowLevelPin);delay(1);
            highLevelVal=digitalRead(highLevelPin);delay(1);
            motorON();
           }       
   
    if (highLevelVal == HIGH  && lowLevelVal ==  LOW)   // if high level switch OPEN, low level switch CLOSE
           {lowLevelVal =digitalRead( lowLevelPin);delay(1);
            highLevelVal=digitalRead(highLevelPin);delay(1);
            motorON();
           }    
    
   
       
    while (highLevelVal == LOW) // LEVEL_CHECK_RUN while   //while high level switch is CLOSE 
       {
         highLevelVal=digitalRead(highLevelPin);delay(1);
        
          valveTipsVal=digitalRead(valveTipsPin);delay(1);
          if (valveTipsVal==HIGH)
{goto TIPS_CHECK;}                      //  check on all levels of code if valve tips are on stand and if yes goto TIPS_CHECK
        
         motorOFF();
        
                             
         if (highLevelVal == HIGH)  //if !!!03!!!   need an if before the while so get time  and runonce outside of the while loop
          { 
            int runonce=0;         // to run once some procedures inside the next while !!!03!!!
            time = millis();
           
            while (highLevelVal == HIGH)   //while !!!03!!!
             {  lowLevelVal =digitalRead( lowLevelPin);delay(1);   //read
                highLevelVal=digitalRead(highLevelPin);delay(1);   //     level swithes
   

                valveTipsVal=digitalRead(valveTipsPin);delay(1);
                if (valveTipsVal==HIGH)
{goto TIPS_CHECK;}                //  check on all levels of code if valve tips are on stand and if yes goto TIPS_CHECK


               
                time2 =millis();
                if ( time2 > (time +problemInLowLevelSwitch) && lowLevelVal !=HIGH  &&  (runonce == 0)  ) //if low level switch has a problem and doesn't go off
                   { runonce ++;                                                                           //with a runonce parameter to stop counting
                   
                     delay(timeOfMotorMinON);                                                             //motor stay turned of for a delay and then turned on again
                   
                     motorON();
                   
                   
                     //goto LEVEL_CHECK_RUN;  //need to use this in case you don't use the runonce statement
                  }
                 
                 
                  if (lowLevelVal == HIGH &&  (runonce == 0))                                              //if low level switch is closed
                   { runonce ++;
                    
                     delay(timeOfMotorMaxON);                                                              // motory stay turned of foa delay and then turned on again
                                                                                                           // so liquids go to drain.    
                     motorON();
                              
                     //goto LEVEL_CHECK_RUN;    //do not use but if you use it works all right.
                    }
             }        //end of while !!!03!!!
          }           //end of if !!!03!!!
    }         //end LEVEL_CHECK_RUN while   

  } //end of  LEVEL_CHECK_RUN         




} // end of TIPS_CHECK while  ******under this line code belongs to case that tips are on stand*******  
   //********************************                                                           *******


//motorOFF();
switch(motorState)                                                    // when vacuum tips are in stand, stand's switch is open so motor must be off.
                                                                          // but if motor was turned ON then when dentist's puts the tip on stand
                                                                          // there must be a delay so waste-liquid inside vacuum tubing goes to boottle and than drain.
     {
      case 1:  delay(timeOfTipOnStand);
               motorOFF(); 
               break;
      case 0:  delay(1);
               motorOFF();                             
               break;
      default: break;
     }      
   
   
  delay(timeOfTipRest);                                                            // precausion in case tip doesn't fit or tip come out at once. 


  
} //End of loop//////////////////////////////////////////
///////////////////////////////////////////////////////// 
///////////////////////////////////////////////////////// 
/////////////////////////////////////////////////////////




 
void motorON()                //turn motor ON and motorstate 1
  {                           //this is for the switch(motorstate)
    digitalWrite(motorPin, LOW); // YES LOW(inverted logic), cause of stupid chinese module
    delay(1);
    motorState = 1;
    digitalWrite(ledPin, HIGH);
    delay (1);
  
  }
 

void motorOFF()                    //turn motor off and motorstate 0
  {                                //this is for the switch(motorstate)
    digitalWrite(motorPin, HIGH);  // YES HIGH(inverted logic), cause of stupid chinese module
    delay(1);
    motorState = 0 ;
    digitalWrite(ledPin,LOW);
    delay (1);
  }
 
//////////////////////////////////////////////////////

void blink()          //put in code for testing where you are when using swithes
  {
   digitalWrite(ledPin, HIGH);   // sets the LED on
   delay(200);                  // waits for a second
   digitalWrite(ledPin, LOW);    // sets the LED off
   delay(200);                  // waits for a second
   digitalWrite(ledPin, HIGH);   // sets the LED on
   delay(200);                  // waits for a second
     
  }///////////////////////////////////////
 
 
 
 
 
 
 
 
gsandhu23 months ago

I’m working on a project which is about making a rescue
robot . I have struggling with it for 4 months and now all the mechanical works
had been done . but I’m facing difficulty in make the robot to work with rf
module can u plzz help me…

I want make transmitter and receiver that can control the
motion…I mean that receiver should have control 8 dc gear motor and each dc
motor should have a forward and backward botton to control the motion ……can u
kindly help me with this project ….if u can make the circuit board diagram for
the PCB ….or any other suggestion plz reply……mail me at “sunny1995gagan@gmail.com”

xalpage (author)  gsandhu23 months ago
Well this is interesting!
Good luck with the project.

So do you think you could control some motors simultaneously.Do you have any pair of motors that always do same movement or exactly the opossite / reverted movement?

This should lower the amount of communication data.

After this you have to make it first work with cable(non wirelessly) and then it will be easy to do it wirelessly.So you need a communication protocol regardless it it's cable or not.

Maybe even two controller boards one in vehicle and one in monitoring station.
Find such a protocol as IC2 via cable.Then make it wireless Lan and make your robot through some ap repeaters on its way.


Take just a little look at this.
http://makezine.com/projects/3-solar-powered-cell-phone-charger/


How do you control a single motor?

Tell me more.
gsandhu2 xalpage3 months ago
Yes I want all the 8 motor to work separately., and each motor should have a forward as well as backward button Truly speaking I'm new to these microcontroller so can u tell me the easiest way to control these 8 motors. rf module will be best... As it's cheap and simple to use...

Yup u r right. I should first try it wire system
gsandhu23 months ago

I’m working on a project which is about making a rescue
robot . I have struggling with it for 4 months and now all the mechanical works
had been done . but I’m facing difficulty in make the robot to work with rf
module can u plzz help me…

I want make transmitter and receiver that can control the
motion…I mean that receiver should have control 8 dc gear motor and each dc
motor should have a forward and backward botton to control the motion ……can u
kindly help me with this project ….if u can make the circuit board diagram for
the PCB ….or any other suggestion plz reply……mail me at “sunny1995gagan@gmail.com”