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
Blog Why does it work...sometimes?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: colporteur
  • Date Created: 9 Jul 2022 2:58 PM Date Created
  • Views 1902 views
  • Likes 6 likes
  • Comments 8 comments
  • arduino-troublshooting
  • arduino_development
Related
Recommended

Why does it work...sometimes?

colporteur
colporteur
9 Jul 2022

Why does this code loaded on a Nano knockoff work sometimes, if I clearly missed a section of code?

int LEDPin = 9;
int ButtonPin = 8;
int RelayPin = 2;

void setup() {

// initialize digital pin LED_BUILTIN as an output.
pinMode(LEDPin, OUTPUT);
pinMode(ButtonPin, INPUT); //Set the switch's pin to be an input with a pullup (default is HIGH)

pinMode(RelayPin, OUTPUT);

digitalWrite(RelayPin, HIGH);

}

I wrote some Arduino code to control a relay when a button is pressed. It worked on the bench at home but in the lab it didn't work. Two different breadboard circuits same Nano. The issue was I failed to pinMode the OUTPUT to the relay shown in red.

My question to the aficionados of Arduino, those individuals with much more knowledge and experience with Arduinos than moi, is why did it work? Uploading and compiling the code produced no warnings. At least none that I have become accustome to making. On one breadboard layout, the circuit worked but on another breadboard layout, it did not. I sheepishly confess it took me a few cycles to figure out what I had done wrong. This required multiple trips between the lab and home so I know it wasn't just a freak one-time event.

Any insight you can share loads up my toolkit for the next time.

  • Sign in to reply
  • colporteur
    colporteur over 3 years ago in reply to Jan Cumps

    The pin is floating (undetermined) if not set, agree. Thanks for the c++ insight. Why would the undetermined on one setup be HIGH and on another it would be LOW?

    The setup that was low was consistently low. On the setup that was high, was consistently high.  I assume the undetermined it is impacted by supply voltage?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ralphjy
    ralphjy over 3 years ago

    I would guess that your two breadboard circuits are not hooked up identically.  Are the other components on the breadboards besides the Nano the same?  What Nano knockoff are you using?  I think Jan's suggestion of measuring voltages will lead you to the cause.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 3 years ago

    The compiler did not show an error because you made no c++ syntax error.

    For the ATMxxx type of Arduinos, if you don't set PIN mode, they are high-Z, floating. Undetermined. 

    If you still havethe working and non-working setups, put a volt meter on the pin and check if you measure a difference ...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • 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.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube