Downloaded project why use hardware pulldown and code pullup

Just wondering if I am missing something here or has this bloke made a stuff up in the code.
They use hardware pull down resistors on the input buttons and then code in input pullups to the same buttons.

//Winding Machine Arduino code by: Engineer USMAN AHMAD
//Easy HomeMade Projects (YouTube)
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
int a = 0; // number of turns that are set initially
int c = 0; // current turns counter
int clr = 4; 
int up = 5;
int down = 6;
int motor = 7;
int startt = 3;
int sn = 2;
int f = 0;


 
void setup() {
  
  pinMode(motor,OUTPUT);
  pinMode(clr,INPUT_PULLUP);
  pinMode(startt, INPUT_PULLUP);
  pinMode (up, INPUT_PULLUP);
  pinMode (down, INPUT_PULLUP);
  pinMode(sn, INPUT);
   lcd.begin(); // begins connection to the LCD module
  lcd.backlight(); // turns on the backlight
  lcd.setCursor(0, 0);
  lcd.print("SET TURNS = ");
   lcd.setCursor(12, 0);
  lcd.print(a);
    lcd.setCursor(0, 1);
  lcd.print("CRT TURNS = ");
  lcd.setCursor(12, 1);
  lcd.print(c);
  digitalWrite(motor,LOW);
  
}


void loop() 
{
 if (digitalRead (up) == HIGH)
  {
    delay(200);
    a=a+1;
   if (a>3000)
    {
      a=3000;
    } 
      while (digitalRead (up) == HIGH)
  { 
  lcd.setCursor(12, 0); // set cursor to secon row
  lcd.print(a);
  lcd.print(" ");
    delay(50);
    a=a+10;
  
    if (a>3000)
    {
      a=3000;
    } 
  
  } 
  }
   if (digitalRead (down) == HIGH)
  {
     delay(200);
    a=a-1;

   if (a<=0)
    {
      a=0;
    } 
      while (digitalRead (down) == HIGH)
  { 
  lcd.setCursor(12, 0); // set cursor to secon row
  lcd.print(a);
  lcd.print(" ");
    delay(50);
    a=a-10;
  
    if (a<=0)
    {
      a=0;
    } 
  
  } 
  }
    lcd.setCursor(12, 0); // set cursor to secon row
  lcd.print(a);
  lcd.print(" "); 

  if(digitalRead(startt) == HIGH && c<a)
  {
    digitalWrite(motor,HIGH);
    
    delay(250);
     while(c != a)
      {
         if (digitalRead(sn) == HIGH && f == 0)
          {
             c = c + 1;
             f = 1;
          }
          
         if (digitalRead(sn) == LOW && f == 1)
          {
            f = 0;
          }
  lcd.setCursor(12, 1);
  lcd.print(c);
  if (digitalRead(motor) == HIGH && digitalRead(startt) == HIGH )
    {
      digitalWrite(motor,LOW);
       delay(200);
    }
if (digitalRead(motor) == LOW && digitalRead(startt) == HIGH && c<a)
    {
     digitalWrite(motor,HIGH);
     delay(200);
    }
if (digitalRead(clr) == HIGH)
{
  digitalWrite(motor,LOW);
  delay(200); 
  break;
}
}
  digitalWrite(motor,LOW);
  delay(10);
 }
   if (digitalRead(clr) == HIGH)
    {
       c = 0;
       lcd.setCursor(12, 1);
       lcd.print(c);
       lcd.print("    ");
       delay(200);
      while (digitalRead(clr) == HIGH)
      {
         delay(500);
         if (digitalRead(clr) == HIGH)
         {
             a = 0;
            lcd.setCursor(12, 0);
            lcd.print(a);
            lcd.print("    ");
         }
      }
    }
}

Nope, not missing anything. The project would definitely be more reliable with pins clr, startt, up and down commented out or deleted.

But they are inputs and need to be shown in the setup surely...?
Don't follow what you mean.

Yes, pins are configured as INPUT by default.

I remember when this confusion crept in…
Mid 1970s, everyone was in a rush to use the first micros.
Positive logic was easy to understand while we all scrambled with opcodes, assembler and the static sensitive nature of the beast.

As understanding grew, and wirewrap construction was a pain, less components might also help.

The early micros didn’t have internal pull-ups, and the risk of accidentally hard tying an output pin to +Vcc, was an almost always fatal decision.

Then other forces came into play, like using NC contacts to identify open circuits.
Losing an external resistor by using switchable internal pull-ups was a happy coincidence.

So, thinking with negative external logic became a useful piece of the toolkit to get the most by using the least.

Hi,
Yes the author of that "code" is in two minds.

Edit the pinMode statements to just be INPUT rather than INPUT_PULLUP.

Don't tell me this is from an "Instructibles" (Destructible) project?

Tom.... :smiley: :+1: :coffee: :australia:
PS. Good catch to the confusion of statement and hardware states. :+1:

Place a 100nF ceramic capacitor from the input to GND on your L7805.

Yes, that was what I thought but just checking, thanks.
Was picked up on youtube so could have come from anywhere although to answer your question, no, didn't go looking on destructables.
thankyou Tom......... Jeff
LarryD, I missed the cap being missing, thanks for that also.....cheers

Controlling an induction motor?

  • A good opportunity to ugrade the SRU-12VDC-SL-C relay, because this will be the first part to fail.
  • A suitable SSR rated for motor control would work great ... no EMI, no contact arcing, provides opto-isolation.

Hi,
Are you switching the main power/current wire to the motor/controller or a signal input on the controller?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

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