If-Condition sensor

Hi,

Can someone help. I need to do, that when sensor is covered for 350ms (Sensor 1)is LOW and if sensor
less covered than 350ms ( Sensor 1) HIGH, and when (Sensor 2) HIGH active pin 5 output.

Becouse when Sensor 2 stuck something and covered for 350ms, then mashine stops, and Sensor 1 see whats coming and active Blow function to blow everything that not damaging mashine more.

I try somthing, but didint work. I need that then sensor 2 covered 350ms it will be LOW and when mashine stops, and when mashine stops sensor 1 what see everything blow.

int S1=3; // sensor 2
int S4=4; // Sensor 1
int p=5; // Blow

const unsigned long period = 350;

int minLight;
int maxLight;
int t = 0;

int startMillis;

void setup() {

pinMode(S1,INPUT);
pinMode(S4,INPUT);
pinMode(p,OUTPUT);
startMillis = millis();

}

void loop()

{
if (digitalRead(S1)==HIGH&&digitalRead(S4)==LOW){
digitalWrite(p,HIGH);
}
else{
digitalWrite(p, LOW);
}
}

Your code doesn't even compile. Code that won't compile never works.

Among other problems

S4 = analogRead(S4);
    if (S4 > 300Mms)

S4 is the pin number. Why would you try to do an analogRead() into a pin number?

And what do you expect to get when you compare an integer (0-1023) to '300Mms'?

Steve

And how to do that if sensor covered for 350ms then S4 LOW?

Please give a good description of the requirements. E.g. at the moment this is my interpretation of your text
1)
sensor 1 must be low for 350ms
2)
next sensor 1 must be high for 350ms
3)
other sensor must be high during (1) and (2)

Note:
Never modify posts that people commented on; add a new post with additional information and/or updated code.

  1. I need that if sensor 2 is covered 350ms or more should be LOW. Otherwise HIGH.( Becouse sensor is always active 24V, when covered 0v)
  2. When sensor 2 LOW and Sensor 1 High, active Output. Otherwise do not active.

Becouse this two sensors on conveyor and always fast go products, when stuck product on sensor 2 for 350ms this stop mashine, but not conveyor, thats why i need active output, only if stuck something to long.

can u make flowchart? or line by line event and decisions of your program.

Its two sensors

One sensor see product and count, other sensor also see product and stop line if stuck more then 350ms. But not working anymore timer, and blow.

Thats why i need that one sensor then is low more then 350ms (this stop line), and when other sensor then see coming product active output blow. 2 inputs, and one output. When one input low and one high, active output.

Its work if sensors 1 low and sensor 2 high, but i dont known how to do timer

is it possible to program input, that if sensor covered more then 350ms active output?

Ramunas10:
is it possible to program input, that if sensor covered more then 350ms active output?

Unfortunately you're not making much sense. We don't understand what you're asking for and just saying the same thing over and over again isn't helping.

You have 2 sensors, S1 and S4. What are these sensors? Which sensor has to be "covered" and what does "covered" mean in terms of HIGH or LOW?

When whichever sensor it is has been in that state for 350ms what is the output that has to be "active" and what does "active" mean in terms of HIGH or LOW?

What does the other sensor have to be doing while all this is happening?

Try to describe EXACTLY what should happen slowly and one step at a time.

Steve

S1 sensor always HIGH, when he see product go LOW.
S4 is always LOW, when see product go HIGH

S1 sensor LOW for 350ms

When S1 LOW more than 350ms and S4 HIGH, OUTPUT p must be HIGH. Otherwise output p LOW

So, if sensor2 is LOW and sensor1 is HIGH for more than 350ms, blow air on sensor2?
How long do you want the air to blow? Until sensor2 goes HIGH?

If that's the case, try this: (compiled, but untested)

const byte sensor1 = 4;
const byte sensor2 = 3;
const byte blower = 5;

bool sensor1State = false;
bool sensor2State = false;
bool sensor2Blocked = false;

const unsigned long period = 350;

unsigned long startTime;

void setup() {
    pinMode(sensor1, INPUT);
    pinMode(sensor2, INPUT);
    pinMode(blower, OUTPUT);
}

void loop() {
  sensor1State = digitalRead(sensor1);
  sensor2State = digitalRead(sensor2);

  if (sensor1State == HIGH && sensor2State == LOW)
  {
    if (sensor2Blocked == false)
    {
        startTime = millis();
        sensor2Blocked = true;
    }
    else
    {
        if (millis() - startTime > period)
        {
            digitalWrite(blower,HIGH);
        }
    }
  }
  else
  {
    digitalWrite(blower,LOW);
    sensor2Blocked = false;
  }
}

how to check that if sensor 1 on low is more when 350ms that's put output on HIGH? if less when 350ms output LOW

Ramunas10:
how to check that if sensor 1 on low is more when 350ms that's put output on HIGH? if less when 350ms output LOW

An easy way would be the bounce library. Just think of the sensor as a pushbutton and set the debounce time to whatever

a pictures of what I'm talking about

You may get further if there is a forum section in your native language... try scrolling down the forum home page.

No my language.:confused: maybe someone will understand. Other picture