NOOBE help....Issues making the analog input respond to 5VDC

Hello ,

I need some guidance with the sketch that I have written to make three relays work. I have a Arduino UNO and have a simple code that works for the two relays. The issue that I need help is when I issue a "if" command to the analogeRead it skips the Read and activates the third Relay.

I am new to this and this is my first sketch. How do I create a command that tells the relay to look at the voltage and if it is gone to turn on Relay3?

Here is the sketch. I am hopeing that I am missing something easy

.//Relay control//

int RELAY = 12; //Relay connected to digital pin 12
int RELAY2 = 13; //relay2 connected to digital pin 13
int analogPin = 0; // assigns A0 as a analogue input
int RELAY3 = 2; //assigns pin 2 as output

void setup()
{
pinMode(RELAY, OUTPUT); //sets the digital pin as output
pinMode(RELAY2, OUTPUT); //sets the digital pin as output
pinMode(analogPin, INPUT); //sets AO as a analoge input
pinMode(RELAY3, OUTPUT); // sets the digital pin as output

}

void loop()

{
digitalWrite(RELAY, HIGH); //turns on Relay on
delay(500); //runs for time
digitalWrite(RELAY, LOW); //turns off Relay
delay(500); //waits for time
digitalWrite(RELAY,HIGH); //turns on Relay
delay(200); //runs for time
digitalWrite(RELAY,LOW); //turns off Relay
delay(100); //waits for time
digitalWrite(RELAY, HIGH); //turn Relay on
delay(200); //runs for time
digitalWrite(RELAY,LOW); //turns Relay off
delay(100); //waits for time
digitalWrite(RELAY, HIGH); //turns Relay on
delay(200); //runs for time
digitalWrite(RELAY, LOW); //turns off Relay
delay(100); // waits for time
digitalWrite(RELAY, HIGH); //turns Relay on
delay(1000); //runs for a second
digitalWrite(RELAY,LOW); //turns Relay off
delay(9000); //waits for 15 minutes

digitalWrite(RELAY2, HIGH); //turns on relay2
delay(2000); //runs for 2 seconds
digitalWrite(RELAY2, LOW); //turns relay2 off
delay(1000); //turns off for a second
digitalWrite(RELAY2, HIGH); //turns relay2 on
delay(500); //runs for half a second
digitalWrite(RELAY2, LOW); // turns off relay2
delay(4500);

analogRead(analogPin = 1023);

if (analogPin < 1023);

digitalWrite(RELAY3,HIGH);
}

 analogRead(analogPin = 1023);

This assigns the value 1023 to the variable analogPin, and then attempts to read from analog pin 1023. There are no Arduinos with that many pins.

The value that would be read from the pin is discarded. Why?

  if (analogPin < 1023);

If the value is less than 1023 (How can it be? You just set it to 1023), do nothing (;). Otherwise, do nothing. Why bother with the test when you are going to do nothing either way?

I read that analog needs to read from a value from 0-1023 for 5V. So I assumed that this was correct. I want the next command to read the value and if it is off

 analogeRead < 1023;

SCRstudios:
I read that analog needs to read from a value from 0-1023 for 5V. So I assumed that this was correct. I want the next command to read the value and if it is off

 analogeRead < 1023;

Check out the reference section of this site. It has pretty detailed help on usage of the various arduino supplied functions. For analogRead() they give an example of how to properly use it:

//Example

int analogPin = 3;     // potentiometer wiper (middle terminal) connected to analog pin 3
                                       // outside leads to ground and +5V
int val = 0;                 // variable to store the value read

void setup()
{
  Serial.begin(9600);          //  setup serial
}

void loop()
{
  val = analogRead(analogPin);    // read the input pin

  Serial.println(val);             // debug value
}

Thanks but it I still cant find that vale to tell the code. I have run the Serial Monitor and have the value of 5V at 1023 for analog.
Can I use a if statement?

Try looking at the ReadAnalogVoltage example in the arduino program. In the arduino program go to File>Examples>basics>ReadAnalogVoltage

Great thanks..got it to work by looking at the value commands ( != ) for 1023 analog value.

Thanks!!