I'm constructing a device which measures an analogue input.
when the analogue input is below a threshold, an output goes high once, until the analogue input goes above a threshold.
int sensorPin = A0; // select the input pin for the detector
unsigned int count = 0;
byte latch = 0; //initial variable
unsigned int sensorValue = 0; // variable to store the value coming from the detector
void setup()
{
pinMode(13, OUTPUT);
//Start Serial port
Serial.begin(9600);
count=0;
}
void loop()
{
// read the value from the soil detector:
sensorValue = analogRead(sensorPin);
if(count==0&&sensorValue<500)
digitalWrite(13, HIGH);
delay(1000); // 1 second delay
++count;// this increments the count by 1
Serial.println(sensorValue);
Serial.println(count);
digitalWrite(13, LOW);
if(sensorValue>600)
count=0;
}
The problems I have..
the count variable displays a "1" when held high.... and when running, why isn't it 0 as per initialisation.
When taking A0 low the count keeps incrementing, ignoring the "count==0", why not just +1,
When taking A0 HIGH the count displays a "1" not 0 ?
int sensorPin = A0; // select the input pin for the detector
int count = 0;
//byte latch = 0; //initial variable
unsigned int sensorValue = 0; // variable to store the value coming from the detector
void setup()
{
pinMode(13, OUTPUT);
//Start Serial port
Serial.begin(9600);
}
void loop()
{
Serial.println(sensorValue);
Serial.println(count);
// read the value from the soil detector:
sensorValue = analogRead(sensorPin);
delay(500);
if(count=0&&sensorValue<500)
{digitalWrite(13, HIGH);
delay(5000); // 5 second delay
count++;// this increments the count by 1
delay(500);
digitalWrite(13, LOW);}
if(sensorValue>600)
{count=0;
delay(2000);}
}
int sensorPin = A0; // select the input pin for the detector
int count = 0;
byte latch = 0; //initial variable
unsigned int sensorValue = 0; // variable to store the value coming from the detector
const int LED = 4;
void setup()
{
pinMode(LED, OUTPUT);
//Start Serial port
Serial.begin(9600);
}
void loop()
{
Serial.println(sensorValue);
Serial.println(count);
// read the value from thedetector:
sensorValue = analogRead(sensorPin);
delay(500);
if(count=0&&sensorValue<500)
{digitalWrite(LED, HIGH);
delay(5000); // 5 second delay
delay(500);
digitalWrite(LED, LOW);}
count++;
// this increments the count by 1
if(sensorValue>600)
{count=0;
delay(2000);
//digitalWrite(LED, LOW);
}
}