Go Down

Topic: Getting An out put after one second if my input is high for one second (Read 108 times) previous topic - next topic

Tanmay1990

Hi...

I am designing a eye blink alarm by IR sensor. I want when my output of IR Sensor is Blinking with blinking of my eye no output should come, but if i am closing my eye for one second or more output should come.

can any one help?

pert

Please post your full sketch. If possible you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it's ok to add it as an attachment.

Have you managed to get it successfully detecting your eye state via the sensor yet?

Tanmay1990


void setup() {
 
pinMode(A0, INPUT);
pinMode(A1, OUTPUT);
}

void loop()
{
 
while(digitalRead(A0)==HIGH)
delay(1000);
if (digitalRead(A0)==HIGH);{
 switch (digitalWrite(A1, HIGH);
}
else
{
  digitalWrite(A1, LOW);
 
}}

pert

I guess you didn't bother to read my reply very carefully.

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]// your code is here[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool. I recommend you to use the standard IDE instead.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we're trying to read your code.


I'll ask again:
Have you managed to get it successfully detecting your eye state via the sensor yet?

pert

Code: [Select]
while(digitalRead(A0)==HIGH)
delay(1000);
if (digitalRead(A0)==HIGH);{

Please take the time to read the reference page for while():
https://www.arduino.cc/en/Reference/While
Do you see the problem? The while() loop will continue as long as A0 is HIGH. It will only exit the while() loop when A0 goes low and then you immediately check if it's HIGH, which there is only a microscopic chance it would ever be.

if (digitalRead(A0)==HIGH);{[/code]
Please take the time to read the reference page for if():
https://www.arduino.cc/en/Reference/If
Do you see the problem with that line of code (hint: semicolon)?

switch (digitalWrite(A1, HIGH);
Please take the time to read the reference page for switch():
https://www.arduino.cc/en/Reference/SwitchCase

Go Up