Hello, so I'm currently working on my project. For my project, is to make an automatic water - oil separator system using laser sensor and water level sensor. I have got the wiring for the components done and correct now I'm stuck at the code for using the L298N Driver Motor. I'm using these components as follows:
- Arduino UNO R3
- KY-008 Laser Module
- Laser Receiver Module
- 5 V Relay
- Solu SLO67 Water Level Sensor
- Driver Motor L298N
- 12 V Pump with 4.2W (2)
- 12 V Diaphragm Pump
An overview for my project is to automatically separate water from oil. Firstly the diaphragm pump will pump out mixed water and oil to a tank, the pump will automatically stop if it reach the Solu SLO67 Water Level Sensor. Second, the system stops (delays) for 40 seconds so the water and oil can naturally be separated in the tank, and then the KY-008 Laser Module which is aligned to the Laser Receiver Module will activate and with this trigger will activate the 12V, 4.2 W pump connected to the OUT1 and OUT2 L298N Driver Module to pump out the bottom layer of water first. Third if the layer of water is fully pumped then the Laser Receiver Module will deactivate because the KY-008 Laser Module can't penetrate through the oil, so the other 12V, 4.2 W pump connected to the OUT3 and OUT4 L298N Driver Module will activate and pump out the remaining left oil in the tank. Lastly, the system will reset and go back to step one.
I'm having problems with the code for the L298N with OUT 3 and OUT 4 seems to be activated when the systems starts, but when the Solu SLO67 Water Level Sensor is detected, the diaphragm pump deactivate but the L298N with OUT1 and OUT2 activated, is there any way to solve this problem? and how to make the system automatically resets to the top of the program? thank you in advance.
int motor1pin1 = 2; //OUT 1 PIN
int motor1pin2 = 3; //OUT 2 PIN
int motor2pin1 = 4; //OUT 3 PIN
int motor2pin2 = 5; //OUT 4 PIN
int Laser = 6; //KY-008 laser module
int LaserSensor = 7; //laser receiver
int RelayPump = 8; //5V relay
int WaterSensor = 9; //Solu SLOO87 water level sensor
void setup() {
Serial.begin(9600);
pinMode(Laser, OUTPUT);
pinMode(LaserSensor, INPUT);
pinMode(WaterSensor, INPUT);
pinMode(RelayPump, OUTPUT);
pinMode(motor1pin1, OUTPUT);
pinMode(motor1pin2, OUTPUT);
pinMode(motor2pin1, OUTPUT);
pinMode(motor2pin2, OUTPUT);
digitalWrite(Laser, LOW);
digitalWrite(RelayPump, LOW);
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, LOW);
}
void loop() {
int SensorValue = digitalRead(WaterSensor);
if (SensorValue >= 1)
{
digitalWrite(RelayPump, HIGH);
digitalWrite(Laser, HIGH);
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, LOW);
}
int LaserDetected = digitalRead(LaserSensor);
if (LaserDetected == HIGH)
{
digitalWrite(motor1pin1, HIGH);
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, LOW);
delay(45000);
} else {
digitalWrite(motor1pin1, LOW);
digitalWrite(motor1pin2, LOW);
digitalWrite(motor2pin1, LOW);
digitalWrite(motor2pin2, HIGH);
}
}