Analog Input (ADC) Help

/*

I want to add another condition that if (sensorValue1<820 && sensorValue2<820) remain for smaller than 1 hour (<1hour) then LED remain High.
if (sensorValue1<820 && sensorValue2<820) remain grater than or equal (>=1hour) 1 hour after then LED will Low . How to do that. Please help me . My code lelow…

*/

int sensorPin1 = A0; // select the input pin for the potentiometer
int sensorPin2 = A1;
int LED = 13; // select the pin for the LED
unsigned int sensorValue1,sensorValue2; // variable to store the value coming from the sensor

void setup() {
pinMode(LED, OUTPUT);
pinMode(sensorPin1, INPUT);
pinMode(sensorPin2, INPUT);
}
void loop()
{
sensorValue1 = analogRead(sensorPin1);
sensorValue2 = analogRead(sensorPin2);

if (sensorValue1<820 && sensorValue2<820)
{ digitalWrite(LED,HIGH); }

else if (sensorValue1>820 && sensorValue2>820)
{ digitalWrite(LED,LOW); }

else
{ digitalWrite(LED,LOW); }
}

if (sensorValue1<820 && sensorValue1<820)

I don’t think you really mean that

Should sensorValue2 be in there somewhere ?

As to keeping the LED LOW for an hour then have a look at Using millis() for timing. A beginners guide, Several things at the same time and the BlinkWithoutDelay example in the IDE

/*

I want to  add another condition that     if (sensorValue1<820 && sensorValue2<820) remain  
for smaller than 1 hour (<1hour)  then LED remain High. 
if (sensorValue1<820 && sensorValue2<820)  remain    grater than or equal (>=1hour) 1 hour  
after then LED will Low  . How to do that. Please help me . My code lelow...

*/


int sensorPin1 = A0;    // select the input pin for the potentiometer
   int sensorPin2 = A1;
   int LED = 13;      // select the pin for the LED
unsigned int sensorValue1,sensorValue2;  // variable to store the value coming from the sensor
   
void setup() {       
   pinMode(LED, OUTPUT);
   pinMode(sensorPin1, INPUT);
   pinMode(sensorPin2, INPUT);
}
   void loop()
   {
   sensorValue1 = analogRead(sensorPin1);
   sensorValue2 = analogRead(sensorPin2);

   if (sensorValue1<820 && sensorValue2<820)
 {   digitalWrite(LED,HIGH); }

 else if (sensorValue1>820 && sensorValue2>820)
 {   digitalWrite(LED,LOW); }

 else
 {  digitalWrite(LED,LOW); }
}

Does the following Flow Chart of Fig-1 describe your this condition?
if (sensorValue1<820 && sensorValue2<820) remain for smaller than 1 hour (<1hour) then LED remain High.

If so, then code it and run it to test. After that you may draw similar flow chart for your other condition and then merge them together.

The Flow Chart:
flow7.png
Figure-1:

flow7.png

thank you very much.
I'm beginner in programming. can you please give me an example code ?

1. Do you have an Arduino UNO?

**2.**If yes, then connect the wiper point of a pot with A0-pin. Connect other two terminals with GND-pin/socket and 5V-pin/socket of UNO.

3. Write sketch to acquire the value value of the wiper pin of pot and show it on Serial Monitor at 1-sec interval. Upload the sketch into UNO.
Hints:

void setup()
{
     //Write code to enable Serial Monitor at 9600 Bd.
     //Write code to set the Vref voltage at 5V.
     
}

void loop()
{
     //Write code to read wiper voltage
     unsigned int x = analogRead(A0);
     //Write code to show x in decimal on Serial Monitor
     //Write code to wait for 1-sec; use delay() function or millis() function
}

4. Turn the pot from minimum value (voltage at wiper pin is 0V)) and maximum value (voltage at the wiper pin is 5V) and check that the Serial Monitor shows: 0 to 1023.

Try the above steps and report your result along with codes within code tags (</>).

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.... :slight_smile:

This part appears to be a mistake:

if (sensorValue1 > 820 && sensorValue2 > 820)
  {
    digitalWrite(LED, LOW);
  }
  else
  {
    digitalWrite(LED, LOW);
  }

Since the 'if' part and 'else' part both do "digitalWrite(LED, LOW)" the 'if' part doesn't need to exist. It will act the same if you change it to:

  {
    digitalWrite(LED, LOW);
  }

I hope I understood correctly how you want the LED to act.

const int sensorPin1 = A0;    // select the input pin for the potentiometer
const int sensorPin2 = A1;
const int LED = 13;      // select the pin for the LED


unsigned int sensorValue1, sensorValue2; // variable to store the value coming from the sensor


void setup()
{
  pinMode(LED, OUTPUT);
  // pinMode(sensorPin1, INPUT); // DO NOT USE with analogRead(), only digitalRead().
  // pinMode(sensorPin2, INPUT); // DO NOT USE with analogRead(), only digitalRead().
}


const unsigned long ONE_SECOND = 1000UL;
const unsigned long ONE_MINUTE = 60UL * ONE_SECOND;
const unsigned long ONE_HOUR = 60UL * ONE_MINUTE;


void loop()
{
  sensorValue1 = analogRead(sensorPin1);
  sensorValue2 = analogRead(sensorPin2);
  static boolean bothWereLow = false;
  static unsigned long timeBothWentLow;


  // If the signals have been low and an hour has expired, turn off the LED
  if (bothWereLow && millis() - timeBothWentLow >= ONE_HOUR)
  {
    digitalWrite(LED, LOW);
  }


  boolean bothAreLow = sensorValue1 < 820 && sensorValue2 < 820;


  if (bothAreLow != bothWereLow)
  {
    bothWereLow = bothAreLow;
    if (bothAreLow)
    {
      // The values just went from high to low
      digitalWrite(LED, HIGH);
      timeBothWentLow = millis();
    }
    else
    {
      // The values just went from both low to NOT both low
      digitalWrite(LED, LOW);
    }
  }
}

johnwasser:
I hope I understood correctly how you want the LED to act.

jito79:
I'm beginner in programming. can you please give me an example code ?

It appears that the OP is unable to write a single line of code and I doubt if he even owns an Arduino UNO Board.

What types of codes should we post so that he gets attracted and be trained?