element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • 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 Need help
  • 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
  • Replies 31 replies
  • Subscribers 388 subscribers
  • Views 4501 views
  • Users 0 members are here
  • help
  • prototyping
  • code
  • arduino
Related

Need help

masa98
masa98 over 3 years ago

hi

im working on a car seat controller and im using 2 arduino nano boards to controll the seat motors. but i ran into a problem with the code. i only get 1V from D2,D4,D5 if i use this code. but if i load another code the pins give 5V and my cirquit only draws 8.5 mA. can some body help.

 //B1-B6 Buttons 
 //D2-D7 output pins
 
int BI = 14;
int B2 = 15;
int B3 = 16;
int B4 = 17;
int B5 = 18;
int B6 = 19;

int D2 = 2;
int D3 = 3;
int D4 = 4;
int D5 = 5;
int D6 = 6;
int D7 = 7;

void setup() {
  
  pinMode(B1, INPUT);
  pinMode(B2, INPUT);
  pinMode(B3, INPUT);
  pinMode(B4, INPUT);
  pinMode(B5, INPUT);
  pinMode(B6, INPUT);

  pinMode(D2, OUTPUT);
  pinMode(D3, OUTPUT);
  pinMode(D4, OUTPUT);
  pinMode(D5, OUTPUT);
  pinMode(D6, OUTPUT);
  pinMode(D7, OUTPUT);
  
}

void loop() {
  
  if (digitalRead(BI) == HIGH && digitalRead(B2) == LOW) {
    
  digitalWrite(D2, HIGH);
  digitalWrite(D3, LOW);
}
  if (digitalRead(B2) == HIGH && digitalRead(BI) == LOW) {
    
  digitalWrite(D3, HIGH);
  digitalWrite(D2, LOW);
}
  else{
  digitalWrite(D2, LOW);
  digitalWrite(D3, LOW);
}

  if (digitalRead(B3) == HIGH && digitalRead(B4) == LOW) {
    
  digitalWrite(D4, HIGH);
  digitalWrite(D5, LOW);
}
  if (digitalRead(B4) == HIGH && digitalRead(B3) == LOW) {
    
  digitalWrite(D5, HIGH);
  digitalWrite(D4, LOW);
}
  else{
  digitalWrite(D4, LOW);
  digitalWrite(D5, LOW);
}

  
  if (digitalRead(B5) == HIGH && digitalRead(B6) == LOW) {
    
  digitalWrite(D6, HIGH);
  digitalWrite(D7, LOW);
}
  if (digitalRead(B6) == HIGH && digitalRead(B5) == LOW) {
    
  digitalWrite(D7, HIGH);
  digitalWrite(D6, LOW);
}
  else{
  digitalWrite(D6, LOW);
  digitalWrite(D7, LOW);
}
}

  • Sign in to reply
  • Cancel

Top Replies

  • beacon_dave
    beacon_dave over 3 years ago +4
    It looks like the second 'if' should be an 'else if'. if else if else instead of if if else Otherwise the pin is being turned on by the first if and then immediately turned off by the else.
  • scottiebabe
    scottiebabe over 3 years ago +4
    'B1' versus 'BI' seems strange, not sure if it's related.
  • Jan Cumps
    Jan Cumps over 3 years ago in reply to Jan Cumps +4
    This is what happens: Condition: B1 : 0, B2 : 0 - D2: false ,D3: false ,D2: false ,D3: false , Condition: B1 : 0, B2 : 1 - D2: false ,D3: false ,D3: true ,D2: false , Condition: B1 : 1, B2 : 0 - D2:…
Parents
  • masa98
    masa98 over 3 years ago

    i made some changes to the code but now i get 5v from D2 and only 2.9v from D3. the funktion im after is, if B1 is HIGH then D2 must be HIGH and D3 must be LOW. and if B2 is HIGH then D2 must be LOW and D3 must be HIGH

     //B1-B6 Buttons 
     //D2-D7 output pins
     
    int BI = 14;
    int B2 = 15;
    int B3 = 16;
    int B4 = 17;
    int B5 = 18;
    int B6 = 19;
    
    int D2 = 2;
    int D3 = 3;
    int D4 = 4;
    int D5 = 5;
    int D6 = 6;
    int D7 = 7;
    
    void setup() {
      
      pinMode(B1, INPUT);
      pinMode(B2, INPUT);
      pinMode(B3, INPUT);
      pinMode(B4, INPUT);
      pinMode(B5, INPUT);
      pinMode(B6, INPUT);
    
      pinMode(D2, OUTPUT);
      pinMode(D3, OUTPUT);
      pinMode(D4, OUTPUT);
      pinMode(D5, OUTPUT);
      pinMode(D6, OUTPUT);
      pinMode(D7, OUTPUT);
      
    }
    
    void loop() {
      
      if (digitalRead(BI) == HIGH && digitalRead(B2) == LOW) {
        
      digitalWrite(D2, HIGH);
      digitalWrite(D3, LOW);
    }
      else{
      digitalWrite(D2, LOW);
      digitalWrite(D3, LOW);
    
    
    if (digitalRead(B2) == HIGH && digitalRead(BI) == LOW) {
        
      digitalWrite(D3, HIGH);
      digitalWrite(D2, LOW);
    }
      else{
      digitalWrite(D2, LOW);
      digitalWrite(D3, LOW);
    }
    }
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • genebren
    genebren over 3 years ago in reply to masa98

    You still have an issue with your B1 and BI.  BI is not being set as input, but B1 is.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • genebren
    genebren over 3 years ago in reply to masa98

    You still have an issue with your B1 and BI.  BI is not being set as input, but B1 is.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Cancel
Children
  • masa98
    masa98 over 3 years ago in reply to genebren

    it had on effect when i changed it

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

    Did you change all occurrences of BI ?

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

    yes

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

    This one

    int BI = 14;

    this one:

    if (digitalRead(BI) == HIGH && digitalRead(B2) == LOW) {

    and this:

    if (digitalRead(B2) == HIGH && digitalRead(BI) == LOW) {

    ?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • masa98
    masa98 over 3 years ago in reply to Jan Cumps

    the code looks like this and i still have the problem with D3 it gives only 2.9v when HIGH

     //B1-B6 Buttons 
     //D2-D7 output pins
     
    int Button1 = 14;
    int Button2 = 15;
    int Button3 = 16;
    int Button4 = 17;
    int Button5 = 18;
    int Button6 = 19;
    
    int D2 = 2;
    int D3 = 3;
    int D4 = 4;
    int D5 = 5;
    int D6 = 6;
    int D7 = 7;
    
    void setup() {
      
      pinMode(Button1, INPUT);
      pinMode(Button2, INPUT);
      pinMode(Button3, INPUT);
      pinMode(Button4, INPUT);
      pinMode(Button5, INPUT);
      pinMode(Button6, INPUT);
    
      pinMode(D2, OUTPUT);
      pinMode(D3, OUTPUT);
      pinMode(D4, OUTPUT);
      pinMode(D5, OUTPUT);
      pinMode(D6, OUTPUT);
      pinMode(D7, OUTPUT);
      
    }
    
    void loop() {
      
      if (digitalRead(Button1) == HIGH && digitalRead(Button2) == LOW) {
        
      digitalWrite(D2, HIGH);
      digitalWrite(D3, LOW);
    }
      else{
      digitalWrite(D2, LOW);
      digitalWrite(D3, LOW);
    
    
    if (digitalRead(Button2) == HIGH && digitalRead(Button1) == LOW) {
        
      digitalWrite(D3, HIGH);
      digitalWrite(D2, LOW);
    }
      else{
      digitalWrite(D2, LOW);
      digitalWrite(D3, LOW);
    }
    }
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • ntewinkel
    ntewinkel over 3 years ago in reply to masa98

    Good call on using better names for the buttons "ButtonX" instead of "BX". It makes your code much more readable, and in the future you'll thank your past self Slight smile

    I mentioned it in your other post just a moment ago - it will be very helpful for you to make use of the Serial Console by adding Serial.println() debug statements into each of the if/else blocks.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • 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 © 2025 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