Controlling electronics from the grounded side of a circuit

Hi there,

I have a circuit and would like to control a the electronics from the grounded side of the circuit. Like a fool I assumed I could connect the circuit to a pin, and set the pinmode to output, and could digital write it to high to "connect" the circuit. It didn't work. Any advice on how to accomplish this?

  • Matt

After doing a bit of research, I think I want to use the internal pull-up or pull-down resistor and set the pins as inputs and not outputs. Is this the case?

Post your circuit, let's see what you're talking about.
There are only "weak" internal pullups, 30-50K, and no pull downs.
Set the pinMode to INPUT if you want to read the state of the pin, HIGH or LOW, while something else drives it.
Set the pinMode to OUTPUT if you want to drive the state of the pin, also HIGH or LOW.

Actually, I was a bit confused about how the board that I'm interfacing with worked. I didn't realize that the outputs had a default high state and needed to set them as low initially.

Now I'm having an issue with a push button.. attached are pictures of my circuit and the push button I'm using and my code

In my loop function I have the following if statement:

void loop() {
  unsigned long currentTime = millis();   // Store time to compare against duration
  startbuttonstate = digitalRead(start_button);       // Read the value of the button pin, high or low

  if (startbuttonstate == HIGH) {
    digitalWrite(inj_4, HIGH);     // inj_4 is the pin for a fuel injector
    digitalWrite(ledPin, HIGH);  // using the board LED..
  }
}

What's happening is that the injector opens and stays open.. then the LED turns on and stays on and nothing happens when I press the button. If I press reset the injector closes (because I have it set to low in the setup function).

In the picture of my board, the button is grounded and the red lead goes to pin 8. It has the two wires with the black heat shrink.

P.S. Go Boston!

I didn't realize that the outputs had a default high state and needed to set them as low initially.

No they don't.

Now take a step back. Your explanation is so very confusing, you know what you have but you have not managed to convey that in your words so far.

So:-

  1. Post all of your code or go here:-
    http://snippets-r-us.com/

  2. Post a SCHEMATIC of your circuit and how the arduino interfaces to it.

  3. Explain what you are trying to do.

Sorry about that.

Here is my code:

// Initialize injector number integers for calling pin outs

int inj_1 = 2;      // Output pins that will connect to injectors on driver board
int inj_2 = 3;      // Pin 2
int inj_3 = 4;      // Pin 3
int inj_4 = 5;      // Pin 4
int start_button = 8;          // Input Pin from Start Push Button
int startbuttonstate = 0;      // value of start button state
int rocker = 9;    // Input from Rocker Switch
int injector = 1;  // Used to store which injector the process is using, start with injector #1

const int ledPin = 13;
boolean flushing = false;  // Used to store whether the flushing process is active or not

long previousTime = 0;  // Store time, used to loop flushing sequence without using delay() function
int duration = 1000;    // Duration to leave injector open in ms

void setup() {
  // Initialize the digital pins as outputs for energizing injectors
  pinMode(inj_1, OUTPUT);  // Out to Injector 1
  digitalWrite(inj_1, LOW);
  pinMode(inj_2, OUTPUT);  // Out to Injector 2
  digitalWrite(inj_2, LOW);
  pinMode(inj_3, OUTPUT);  // Out to Injector 3
  digitalWrite(inj_3, LOW);
  pinMode(inj_4, OUTPUT);  // Out to Injector 4
  digitalWrite(inj_4, LOW);
  pinMode(start_button, INPUT);  // In from Push Button
  //pinMode(rocker, INPUT);  // In from Rocker Switch
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);

}

void loop() {
  unsigned long currentTime = millis();   // Store time to compare against duration
  startbuttonstate = digitalRead(start_button);       // Read the value of the button pin, high or low
  
  //digitalWrite(13, HIGH);
  //delay(duration);
 
  
  //if (flushing == false) {
    if (startbuttonstate == LOW) {
      //flushing = true;                  // Set the flushing variable to 1 to prevent resetting the process if the button is pressed during the flushing process
      //previousTime = currentTime;    // Record the currentTime as the previousTime to compare against duration 
      digitalWrite(inj_1, HIGH);
      //digitalWrite(ledPin, HIGH);
      delay(1000);
      //flushing = false;
    }
    else {
      digitalWrite(inj_1, LOW);
      delay(1000);
    }
  //}
  
//  
//  if (currentTime - previousTime < duration) {  // if the duration has not elapsed, break the statement.
//    break;
//  }
//  else {  // If the duration has elapsed, then use a Switch statement to modify the injector
//    switch (injector) {
//      case 1:
//        digitalWrite(inj_1, LOW);     // De-energize injector #1
//        injector = 2;                 // Increment injector number
//        digitalWrite(inj_2, HIGH);    // Energize injector #2
//        break;
//        }
//      case 2:
//        digitalWrite(inj_2, LOW);     // De-energize injector #2
//        injector = 3;                 // Increment injector number
//        digitalWrite(inj_3, HIGH);    // Energize injector #3
//        break;
//        }
//      case 3:
//        digitalWrite(inj_3, LOW);     // De-energize injector #3
//        injector = 4;                 // Increment injector number
//        digitalWrite(inj_4, HIGH);    // Energize injector #4
//        break;
//        }
//      case 4:      
//        digitalWrite(inj_4, LOW);     // De-energize injector #4
//        injector = 1;                 // Reset injector counter
//        flushing = false;                 // Reset the flushing process variable
//        break;
//        }
//      default:
//        break;
//    }
//  }
          
// EOF
}

I have another circuit board that is independent of the Arduino, pins 3 through 5 connection to that. I want to energize pin 2 when I press my push button, which was shown in a picture in my previous post. It's not like a breadboard button.

Added a pull up resistor and the button worked. Can I run another button from the same 5V source in parallel ? Or should I use the 3.3V pin..

You can run another button from the same 5V. That said the normal practice if you want a pullup resistor on a digital input is to define the pin as INPUT_PULLUP instead of just INPUT.

Does that mean I didn't need to solder this 10K resistor into my circuit? Basically I soldered it to secure a connection between the lead going into pin 8 then attached the end of the resistor to ground.

Look in the Learning section of the forum for examples of how to connect up buttons OR this topic

Arduino Basic Connections

Mark

Thanks, haha. That would have saved me so much work. So should I desolder my resistors, change the pinMode to INPUT_PULLUP and check to see if my button states go low? Would that be cleaner? Or should I leave it as it is.

Hi, if you are an Engineering student, you must have access to a better CAD package for drawing circuits than frissing.

Even a picture of a hand drawn circuit is better than frizzing.

Tom........ :slight_smile:
PS I'm getting used to the foetal postion, 1/2 hour wasn't to bad.

here is another view on inputs:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

So should I desolder my resistors, change the pinMode to INPUT_PULLUP and check to see if my button states go low?

Yes.

TomGeorge:
Hi, if you are an Engineering student, you must have access to a better CAD package for drawing circuits than frissing.

Hehe. I'm a Mechanical Engineering student doing this for my internship. I know nothing about electronics and am learning on my own =) I might look around in the EE lab to see what sort of software they have. I'm sure you're correct.

Grumpy_Mike:
here is another view on inputs:-

Thanks Mike, that helped quite a bit! If I have time before my project ends, I'll rewire it =) (I have to be finished by tomorrow! haha)

I think I've basically got the hang of it. I can control four cleanliness solution injectors to flush out the internals of a part. I have a toggle switch for 3 or 4 injectors depending on the part being tested, a start button, a cancel button (in the process of adding a feature that you need to press it twice within 10 seconds to fully cancel the cycle..), and an LCD to show the user which injector is in use, and the duration of the injector cycle. Thank you all for your help!

  • Matt