Greetings Guys!
I am trying to build a protype miniature trash compressor using micro linear actuator. To control it, I am going to use IR sensor instead of buttons, the IR sensor will be responsible to detect if the trash is full. If the trash is full, the linear actuator will extend and retract back to its position. There’s also a 2 channel relay module that will act as a switch for extend and retract of the linear actuator and allowing the low-voltage Arduino to control the high-voltage actuator and battery.
Materials
Arduino UNO
IR Sensor
2 channel relay module
Bread Board
12V Battery
Code
// Define the pin numbers for IR sensor and relay module
const int irSensorPin = 2; // Pin connected to the signal (OUT) of the IR sensor
const int relayExtendPin = 3; // Pin connected to IN1 of the relay module
const int relayRetractPin = 4; // Pin connected to IN2 of the relay module
void setup() {
pinMode(irSensorPin, INPUT);
pinMode(relayExtendPin, OUTPUT);
pinMode(relayRetractPin, OUTPUT);
}
void loop() {
// Read the IR sensor input
int irSensorValue = digitalRead(irSensorPin);
// If the IR sensor detects trash fullness (you may need to adjust the logic based on your sensor)
if (irSensorValue == LOW) {
// Extend the actuator to compress the trash
digitalWrite(relayExtendPin, HIGH);
delay(2000); // Adjust delay as needed
digitalWrite(relayExtendPin, LOW);
// Wait for a moment before retracting
delay(2000); // Adjust delay as needed
// Retract the actuator to its initial position
digitalWrite(relayRetractPin, HIGH);
delay(2000); // Adjust delay as needed
digitalWrite(relayRetractPin, LOW);
// Wait for a longer period before the next detection (prevent rapid triggering)
delay(3000); // Adjust delay as needed
}
}
1.) Is the materials possible to make this project work?
2.) Is the code correct?
3.) Where should I connect the wirings of the 12V battery, and electric linear actuator in 2 channel relay module? (NO1, NO2, NC1, NC2, COM1, COM2)