type or paste code here
#define M_1 2 // Motor 1
#define M_2 3 // Motor 2
#define M_3 4 // Motor 3
#define Sensor_1 8 // Sensor 1
#define Sensor_2 9 // Sensor 2
#define Sensor_3 10 // Sensor 3
int Port_1 = A0; // Port 1
int Port_2 = A1; // Port 2
int Port_3 = A2; // Port 3
int portValue_1 = 0;
int outputValue_1 = 0;
int portValue_2 = 0;
int outputValue_2 = 0;
int portValue_3 = 0;
int outputValue_3 = 0;
void setup() {
Serial.begin(9600);
pinMode(M_1, OUTPUT);
pinMode(M_2, OUTPUT);
pinMode(M_3, OUTPUT);
pinMode(Sensor_1, INPUT);
pinMode(Sensor_2, INPUT);
pinMode(Sensor_3, INPUT);
}
void loop() {
int SSensor_1 = digitalRead(Sensor_1);
int SSensor_2 = digitalRead(Sensor_2);
int SSensor_3 = digitalRead(Sensor_3);
portValue_1 = analogRead(Port_1);
portValue_2 = analogRead(Port_2);
portValue_3 = analogRead(Port_3);
outputValue_1 = map(portValue_1, 0, 1023, 0, 3000);
outputValue_2 = map(portValue_2, 0, 1023, 0, 3000);
outputValue_3 = map(portValue_1, 0, 1023, 0, 3000);
Serial.print("sensor1 = " );
Serial.print(SSensor_1);
Serial.print("\t output_1 = ");
Serial.println(outputValue_1);
Serial.print("sensor2 = " );
Serial.print(SSensor_2);
Serial.print("\t output_2 = ");
Serial.println(outputValue_2);
Serial.print("sensor3 = " );
Serial.print(SSensor_3);
Serial.print("\t output_ = ");
Serial.println(outputValue_3);
if ( SSensor_1 == 0)
{
digitalWrite(M_1, HIGH);
delay( outputValue_1);
digitalWrite(M_1, LOW);
delay(500);
}
else if ( SSensor_2 == 0)
{
digitalWrite(M_2, HIGH);
delay( outputValue_2);
digitalWrite(M_2, LOW);
delay(500);
}
else if ( SSensor_3 == 0)
{
digitalWrite(M_3, HIGH);
delay( outputValue_3);
digitalWrite(M_3, LOW);
delay(500);
}
else{
digitalWrite(M_1, LOW);
digitalWrite(M_2, LOW);
digitalWrite(M_3, LOW);
}
}
Can you Do changes in code that At time multiple sensors can be work I mean if 2 sensor are active at a time both condition have to work at time