#include <LiquidCrystal.h>
#include <Servo.h>
// Pin assignments
const int capSensorPin = 2; // Capacitive Proximity Sensor input pin
const int inductiveSensor1 = 3; // Inductive Sensor 1 input pin
const int inductiveSensor2 = 4; // Inductive Sensor 2 input pin
const int led1Pin = 5; // LED 1 pin
const int led2Pin = 6; // LED 2 pin
const int buzzer1Pin = 7; // Buzzer 1 pin
const int buzzer2Pin = 8; // Buzzer 2 pin
const int servo1Pin = 9; // Servo 1 control pin
const int servo2Pin = 10; // Servo 2 control pin
// Create servo objects
Servo servo1;
Servo servo2;
// Create LCD object
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
void setup() {
// Initialize components
pinMode(capSensorPin, INPUT);
pinMode(inductiveSensor1, INPUT);
pinMode(inductiveSensor2, INPUT);
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(buzzer1Pin, OUTPUT);
pinMode(buzzer2Pin, OUTPUT);
// Attach servos to pins
servo1.attach(servo1Pin);
servo2.attach(servo2Pin);
// Initialize LCD
lcd.begin(16, 2);
lcd.print("Metal: ");
lcd.setCursor(0, 1);
lcd.print("Plastic: ");
}
void loop() {
// Read sensor values
int capSensorValue = digitalRead(capSensorPin);
int inductiveSensorValue1 = digitalRead(inductiveSensor1);
int inductiveSensorValue2 = digitalRead(inductiveSensor2);
// Display sensor values on LCD
lcd.setCursor(7, 0);
lcd.print(capSensorValue);
lcd.setCursor(8, 1);
lcd.print(inductiveSensorValue1);
lcd.setCursor(8, 1);
lcd.print(inductiveSensorValue2);
// Check if metal is detected
if (inductiveSensorValue1 == HIGH) {
digitalWrite(led1Pin, HIGH);
tone(buzzer1Pin, 1000, 100);
servo1.write(90);
} else {
digitalWrite(led1Pin, LOW);
noTone(buzzer1Pin);
servo1.write(0);
}
// Check if plastic is detected
if (inductiveSensorValue2 == HIGH) {
digitalWrite(led2Pin, HIGH);
tone(buzzer2Pin, 1000, 100);
servo2.write(90);
} else {
digitalWrite(led2Pin, LOW);
noTone(buzzer2Pin);
servo2.write(0);
}
delay(200); // Adjust the delay as needed
}