WASTE SEPERATOR








CIRCUIT
PROGRAM (ARDUINO)
WASTE SEPARATOR SECTION

#include <Servo.h>
Servo myservo1;  // create servo object to control a servo
Servo myservo2;  // create servo object to control a servo
//connections
#define metal 2
#define wet A5
#define LDR A2
void setup()
{
myservo1.attach(9); myservo1.write(90); //down servo  // attaches the servo on pin 9 to the servo object
myservo2.attach(10);myservo2.write(5);//valve  // attaches the servo on pin 10 to the servo object
keyinit();
//Serial.begin(9600);  Serial.println("wel");
//delay(1000);  
pinMode(LDR,INPUT_PULLUP);

}
void loop()
{
if(analogRead(LDR)>400)
{
delay(3000);  
if( !digitalRead(metal)  )   metalwaste();
else if( digitalRead(wet)  ) wetwaste();
else { drywaste();}
}
}


void metalwaste(void)
{
//Serial.println("metalwaste");
myservo1.write(180); //90 DEGREE  
delay(1000);  
valveopen(); //90 DEGREE  
delay(1000); 
myservo1.write(90); //90 DEGREE  
delay(1000);                                                                                                      
valveclose();  //90 DEGREE  
delay(1000); 
}
void wetwaste(void)
{
  Serial.println("wetwaste");
myservo1.write(0); //90 DEGREE  
delay(1000);  
valveopen(); //90 DEGREE  
delay(1000); 
myservo1.write(90); //90 DEGREE  
delay(1000);  
valveclose(); //90 DEGREE  
delay(1000);
}
void drywaste(void)
{
valveopen(); //90 DEGREE  
valveclose();//90 DEGREE  
delay(1000);  
}

void valveopen(void)
{
myservo2.write(100); 
delay(2000); 
}
void valveclose(void)
{
myservo2.write(5); 
}
void keyinit(void)
{
pinMode(metal,INPUT_PULLUP);
pinMode(wet,INPUT_PULLUP);
}


 62 KHz SQUARE WAVE GENERATION FOR CAPACITIVE SECTION
void setup()
{
  setPwmFrequency(6, 1);
  analogWrite(6, 200);
}
void loop()
{
}







void setPwmFrequency(int pin, int divisor) {
  byte mode;
  if (pin == 5 || pin == 6 || pin == 9 || pin == 10) {
    switch (divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 64: mode = 0x03; break;
      case 256: mode = 0x04; break;
      case 1024: mode = 0x05; break;
      default: return;
    }
    if (pin == 5 || pin == 6) {
      TCCR0B = TCCR0B & 0b11111000 | mode;
    } else {
      TCCR1B = TCCR1B & 0b11111000 | mode;
    }
  } else if (pin == 3 || pin == 11) {
    switch (divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 32: mode = 0x03; break;
      case 64: mode = 0x04; break;
      case 128: mode = 0x05; break;
      case 256: mode = 0x06; break;
      case 1024: mode = 0x7; break;
      default: return;
    }
    TCCR2B = TCCR2B & 0b11111000 | mode;
  }
}

/**
   Divides a given PWM pin frequency by a divisor.

   The resulting frequency is equal to the base frequency divided by
   the given divisor:
     - Base frequencies:
        o The base frequency for pins 3, 9, 10, and 11 is 31250 Hz.
        o The base frequency for pins 5 and 6 is 62500 Hz.
     - Divisors:
        o The divisors available on pins 5, 6, 9 and 10 are: 1, 8, 64,
          256, and 1024.
        o The divisors available on pins 3 and 11 are: 1, 8, 32, 64,
          128, 256, and 1024.

   PWM frequencies are tied together in pairs of pins. If one in a
   pair is changed, the other is also changed to match:
     - Pins 5 and 6 are paired on timer0
     - Pins 9 and 10 are paired on timer1
     - Pins 3 and 11 are paired on timer2

   Note that this function will have side effects on anything else
   that uses timers:
     - Changes on pins 3, 5, 6, or 11 may cause the delay() and
       millis() functions to stop working. Other timing-related
       functions may also be affected.
     - Changes on pins 9 or 10 will cause the Servo library to function
       incorrectly.


*/