element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum problem with digital input pins in controlling its output pins.. we really need suggestions...
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 7 replies
  • Answers 1 answer
  • Subscribers 418 subscribers
  • Views 735 views
  • Users 0 members are here
Related

problem with digital input pins in controlling its output pins.. we really need suggestions...

e14 Contributor
e14 Contributor over 13 years ago

i have 2 digital input pins(pin16 & pin17 actually i need 4)

just to test if it really gonna work.What i did is that

i just give 5volts or high to these pins as input data

but what happened there is that the 2 digitalOutput pins respectively

seems doesnt do to the conditions i gave it seems it can affect the other condition.

 

 

here is a part of my code .

 

  if (digitalRead(16) == LOW )

    { digitalWrite(ledPin7,HIGH);

    }

  if (digitalRead(17) == LOW )

    { digitalWrite(ledPin6,HIGH);

    }

 

  else

    digitalWrite(ledPin7,LOW);

    digitalWrite(ledPin6,LOW);

 

          ,,

          what i really want to do there is that

          just have  4  inputs(that would be 5volts)

          and also give 4  outputs respectively..

 

we really need Ur suggestions  and ideas.. thnx ;d

  • Sign in to reply
  • Cancel

Top Replies

  • mcb1
    mcb1 over 13 years ago in reply to billabott +2
    Nico Well done One other way is to make them LOW and change them if the button is LOW. digitalWrite(ledPin7,LOW); digitalWrite(ledPin6,LOW); if (digitalRead(16) == LOW ) { digitalWrite(ledPin7,HIGH); …
  • ntewinkel
    ntewinkel over 13 years ago +1 suggested
    I think it might be the way you are building your if...else statements. Try this way: if (digitalRead(16) == LOW ) { digitalWrite(ledPin7,HIGH); } else { digitalWrite(ledPin7,LOW); } if (digitalRead(17…
  • billabott
    billabott over 13 years ago in reply to ntewinkel +1
    Arduino IDE is modified version of the Processing Application as specified on Processing.org. (Think Turtle programming) My question is a carry over tangent from the J.Blum Arduino discussion.
Parents
  • ntewinkel
    0 ntewinkel over 13 years ago

    I think it might be the way you are building your if...else statements.

     

    Try this way:

     

      if (digitalRead(16) == LOW ) {

         digitalWrite(ledPin7,HIGH);

      }

      else {

         digitalWrite(ledPin7,LOW);

      }

     

      if (digitalRead(17) == LOW ) {

          digitalWrite(ledPin6,HIGH);

        }

      else {

        digitalWrite(ledPin6,LOW);

      }

     

    It's a good idea to always follow every if and else with a { ... } block, that way you know that everything within the { ... } block will be part of the if, or part of the else. The way you had it set up would always set ledPin6 LOW, because without the curly brackets only the first line after "else" is considered to be part of the else block - the next line is just a line that always gets executed.

     

    Hope that helps!

     

    Cheers,

    -Nico

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • ntewinkel
    0 ntewinkel over 13 years ago

    I think it might be the way you are building your if...else statements.

     

    Try this way:

     

      if (digitalRead(16) == LOW ) {

         digitalWrite(ledPin7,HIGH);

      }

      else {

         digitalWrite(ledPin7,LOW);

      }

     

      if (digitalRead(17) == LOW ) {

          digitalWrite(ledPin6,HIGH);

        }

      else {

        digitalWrite(ledPin6,LOW);

      }

     

    It's a good idea to always follow every if and else with a { ... } block, that way you know that everything within the { ... } block will be part of the if, or part of the else. The way you had it set up would always set ledPin6 LOW, because without the curly brackets only the first line after "else" is considered to be part of the else block - the next line is just a line that always gets executed.

     

    Hope that helps!

     

    Cheers,

    -Nico

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
  • billabott
    0 billabott over 13 years ago in reply to ntewinkel

    Yes, Nico, you are right.  The way the sketch was originally written if pin 17 is high then both out puts are driven low in a VERY short amount of time.  My brain was not in the correct level/mode to see it clearly.  I am glad you came along to do it.  It is amazing that I find myself trying to use a "hardware" hammer where a "software" hammer is needed.  Time to regroup.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • ntewinkel
    0 ntewinkel over 13 years ago in reply to billabott

    Hi billabott, you're right about that.

     

    If we properly format the original code it becomes very clear:

     

    if (digitalRead(16) == LOW ) {

          digitalWrite(ledPin7,HIGH);

      }

    // else nothing

     

      if (digitalRead(17) == LOW )  {

          digitalWrite(ledPin6,HIGH);

      }

      else

        digitalWrite(ledPin7,LOW);  // because there are no curly brackets, this is the only line that is part of the "else"

     

    // and this always gets executed

    digitalWrite(ledPin6,LOW);

     

    So you can see that ledPin6 is always LOW at the end of this code. ledPin7 is a bit less predictable.

     

    I must be missing part of an earlier conversation - what do you mean by "original processing application" ?

     

    Cheers,

    -Nico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 13 years ago in reply to ntewinkel

    Arduino IDE is modified version of the Processing Application  as specified on Processing.org.  (Think Turtle programming)  My question is a carry over tangent from the J.Blum Arduino discussion.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 13 years ago in reply to billabott

    Nico

    Well done

     

    One other way is to make them LOW and change them if the button is LOW.

     

        digitalWrite(ledPin7,LOW);

        digitalWrite(ledPin6,LOW);

     

      if (digitalRead(16) == LOW )

        {

            digitalWrite(ledPin7,HIGH);

        }

      if (digitalRead(17) == LOW )

        {

           digitalWrite(ledPin6,HIGH);

        }

     

     

     

    If the LED state was HIGH when the Button input was HIGH, you could simplify it to

    void loop()

    {

          digitalWrite(ledPin7,(digitalRead(16)));

          digitalWrite(ledPin6,(digitalRead(17)));

     

    }

     

    Note : it compiles but I haven't tried it.

     

    Mark

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 13 years ago in reply to ntewinkel

    thnx nicz!!! image that help  much,, now  i can now proceed to our actual material testing.hehe  i never thought that it would affect ..

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube