analog sensor detection how to combine them
hi. im planning use water sensor in project. want 3 water sensors used. problem how other water sensor detect when first sensor detects input. disable 2 sensors. once removed, other sensor takes place first detects will. do?? pls.
this codes 2 sensors.
const int wsensor1 = a0;
const int wsensor2 = a1;
const int wsensor3 = a2;
const int led1 = 2;
const int led2 = 3;
const int led3 = 4;
int wsensor1val = 0;
int wsensor2val = 0;
int wsensor3val = 0;
int thresh1 = 501;
int thresh2 = 502;
int thresh3 = 503;
void setup()
{
serial.begin(9600);
pinmode(led1, output);
pinmode(led2, output);
pinmode(led3, output);
}
void loop()
{
wsensor1val = analogread(wsensor1);
serial.print("wsensor1=");
serial.println(wsensor1val);
wsensor2val = analogread(wsensor2);
serial.print("wsensor2=");
serial.println(wsensor2val);
wsensor3val = analogread(wsensor3);
serial.print("wsensor3=");
serial.println(wsensor3val);
if(wsensor1val >= thresh1)
{
digitalwrite(led1, high);
delay(1000);
while(wsensor1val >= thresh1)
{
digitalwrite(led1, high);
wsensor1val = analogread(wsensor1);
delay(1500);
if(wsensor1val < thresh1)
{
digitalwrite(led1, low);
break;
}
}
}
if( wsensor2val >= thresh2)
{
digitalwrite(led2, high);
digitalwrite(led1, high);
delay(1000);
while( wsensor2val >= thresh2)
{
digitalwrite(led2, high);
digitalwrite(led1, high);
wsensor2val = analogread(wsensor2);
delay(1500);
if( wsensor2val < thresh2)
{
digitalwrite(led2, low);
break;
}
}
}
}
help pls!
this codes 2 sensors.
const int wsensor1 = a0;
const int wsensor2 = a1;
const int wsensor3 = a2;
const int led1 = 2;
const int led2 = 3;
const int led3 = 4;
int wsensor1val = 0;
int wsensor2val = 0;
int wsensor3val = 0;
int thresh1 = 501;
int thresh2 = 502;
int thresh3 = 503;
void setup()
{
serial.begin(9600);
pinmode(led1, output);
pinmode(led2, output);
pinmode(led3, output);
}
void loop()
{
wsensor1val = analogread(wsensor1);
serial.print("wsensor1=");
serial.println(wsensor1val);
wsensor2val = analogread(wsensor2);
serial.print("wsensor2=");
serial.println(wsensor2val);
wsensor3val = analogread(wsensor3);
serial.print("wsensor3=");
serial.println(wsensor3val);
if(wsensor1val >= thresh1)
{
digitalwrite(led1, high);
delay(1000);
while(wsensor1val >= thresh1)
{
digitalwrite(led1, high);
wsensor1val = analogread(wsensor1);
delay(1500);
if(wsensor1val < thresh1)
{
digitalwrite(led1, low);
break;
}
}
}
if( wsensor2val >= thresh2)
{
digitalwrite(led2, high);
digitalwrite(led1, high);
delay(1000);
while( wsensor2val >= thresh2)
{
digitalwrite(led2, high);
digitalwrite(led1, high);
wsensor2val = analogread(wsensor2);
delay(1500);
if( wsensor2val < thresh2)
{
digitalwrite(led2, low);
break;
}
}
}
}
help pls!
why complexity while loops. couldn't this:
just be:
code: [select]
if(wsensor1val >= thresh1)
{
digitalwrite(led1, high);
delay(1000);
while(wsensor1val >= thresh1)
{
digitalwrite(led1, high);
wsensor1val = analogread(wsensor1);
delay(1500);
if(wsensor1val < thresh1)
{
digitalwrite(led1, low);
break;
}
}
}
just be:
code: [select]
if(wsensor1val >= thresh1)
{
digitalwrite(led1, high);
}
else
{
digitalwrite(led1, low);
}
Arduino Forum > Using Arduino > Programming Questions > analog sensor detection how to combine them
arduino
Comments
Post a Comment