Certain outputs are inverted

Hi, I'm having trouble with a program I made for my uno. My output 7 seems to work just like i want it to. But once I define any other pin as an output it goes high. Specifically, 3 and 5 in my code but i have tried 3,5,8,13 with the same results. If i add a line digitalWrite(x,LOW); it will stay high but digitalWrite(x,HIGH); will set it low. Does this make sense? What am I doing wrong?

const unsigned long light0trigger = 43200000;                          // define light0 time
unsigned long light0previoustime = 0;                                  //update light0 time

int light0state = 0;                                                   //variable for light0 state  
void setup()                                                           // put your setup code here, to run once:
{  
Serial.begin(9600);                                                    // start serial 
pinMode (3,OUTPUT);                                                    // 3 is pump0
pinMode (5,OUTPUT);                                                    // 5 is pump1
pinMode (7,OUTPUT);                                                    // 7 is light0
pinMode (A0,INPUT);                                                    // a0 is soil0
pinMode (A1,INPUT);                                                    // a1 is soil1


}

void loop()                                                            //main loop
{
unsigned long currenttime = millis();                                  // saves current milis value to variable and updates
int soil0 = analogRead(A0);                                            // defines A0 as a variable and updates
int soil1 = analogRead(A1);                                            // defines A1 as a variable and updates

if (currenttime - light0previoustime >= light0trigger)                // if currenttime minus light0previoustime is greater than or equal to light0trigger 
  {
  light0previoustime = currenttime;                                   //updates light0previous time to currenttime  
  if (light0state % 2 == 0)                                          // if light0state is even turn on light0 else turn it off
    {
    digitalWrite (7,HIGH);
    light0state++;                                                    // add one to light0state
    }
   else 
     {
      digitalWrite (7,LOW);
      light0state++;
     } 
   }
  }

What is connected to those other pins?

What is connected to the output pin and how do you know that the output state is reversed ?

Is it a relay by any chance and, if so, is it turned on by a HIGH state or by a LOW state ?

Many (most) relays are active LOW

They are connected to the input of a relay.

People here have become excellent mind readers. :slight_smile:

And I bet the relay is actually a "relay module" and the module is powered and the connection is setting at 5 volts, waiting for your code to set is LOW to activate the relay. Use your DVM to verify.

Yes, they are connected to relay inputs. However, my relay output is connected to the normally open contacts. Also the relay will close on high coming in regardless of the output.

Oh, also the output that is working is going a a different relay of the same type.

On the other hand, some of us woukd like to know

what relay module

and

how is it wired to your arduino

You could add some Serial.print statements to see where the code is actually executing the digitslWrites…

a7

Ok, you're right Paul. I assumed my relay was active high but it isn't. Thanks guys.

I didn't realize that, thanks.

Does your module have jumpers? Some are able to change input sense that way.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.