How to program a simple switch?

I can't find any examples of making pin 6 connect to pin 5.
I have written a program that makes pin 6 HIGH when I push a button and stay on until I push a different button. Works great. I'm sure a lot of people are far ahead of this but I am starting and I am stuck.
Now that I can control pin 6 I want to control my solar led (1.2v). I have the wiring ready but I can't find a method to make a switch.
Now I want to close the connection between pin 5 and pin 6 when I push a button and stay closed until I push a different button. So basically a normally open switch.
I hope I have not upset any one by asking a stupid question. I do not want the voltage from the Mini Pro to reach the solar led. And since the led only requires 1.2vdc I don't feel I am harming the board.

Of course if anyone wants the program I will post it.

Really appreciate someone's help as my project has stopped until I figure this out.

Thanks for your time and help,

razz

Welcome!
Yes post your sketch.
Please, you must show us your complete sketch. Attach your code using the </> icon on the left side of the posting menu.
Put your sketch between the code tags [code][/code]

What is a solar led?

.

DARCCLLC:
Now I want to close the connection between pin 5 and pin 6 when I push a button and stay closed until I push a different button. So basically a normally open switch.

To do what you are saying here, you would just wire pin 5 to one side of a switch and pin 6 to the other side and when you close the switch those two pins are connected. I doubt that is really what you need to do. Why don't you describe what you are trying to accomplish and not just how you think you would accomplish it.

I guess I am asking how to program an internal relay.

MI_02.ino (1.41 KB)

Welcome to the Forum. Please read this post:

How to use this forum - please read.

Please post your code using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpreted by the forum code as italics or funny emoticons.

Unless the sketch is too large, it's better if you post your code, rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.

                         int LED = 13;
const int led5 = 5;
const int led6 = 6;
const int sw9 = 9;
const int rb12 = 12;

int swV = 0;
int rbV = 0;
int led6on = 0;

void setup()
{                           pinMode(LED, OUTPUT);
 pinMode(led5, OUTPUT); //Pin 5 1.2V from Cell
 pinMode(led6, OUTPUT); //Pin 6 1.2V to LED
 pinMode(sw9, OUTPUT);  //Pin 9
 pinMode(swV, OUTPUT);  //Variable Switch Value
 pinMode(rb12, OUTPUT);  //Pin 12
 pinMode(rbV, OUTPUT);  //Variable Button Value

}
 
void loop()
{                         digitalWrite(LED, LOW); //Keep LED Off

  rbV = digitalRead(rb12); //Makes rbV = Pin 12 value
  swV = digitalRead(sw9);  //Makes swV = Pin 9 value
  while (swV == HIGH)      //#1 Loop until this value becomes false
 {
  if (rbV == HIGH)         //If Reset Button is pressed turns off led5 and proceed
   {
  rbV = digitalRead(rb12); //Makes rbV = Pin 12 value
  swV = digitalRead(sw9);  //Makes swV = Pin 9 value
  digitalWrite(led6, LOW);
   } //If End

  swV = digitalRead(sw9);  //Makes swV = Pin 9 value
  rbV = digitalRead(rb12); //Makes rbV = Pin 12 value  
  while (rbV == LOW)       //#2 Loop until this value becomes false
    {
  rbV = digitalRead(rb12); //Makes rbV = Pin 12 value 
  swV = digitalRead(sw9);  //Makes swV = Pin 9 value
  led6on = digitalRead(led5); //Makes led6on = Pin 5 value
  digitalWrite(led6, led6on);
    }  //While #2 End
 } //While #1 End
  digitalWrite(led6, LOW);
} //Void End

Thank you. That's much better. One problem is, your variable names are extremely terse, making the logic of the sketch hard to follow. Also, we are still waiting for an explanation of what you are trying to do.

I'm trying to connect pin 5 to pin 6 when I press a button. Like a relay.

DARCCLLC:
I'm trying to connect pin 5 to pin 6 when I press a button. Like a relay.

How is that like a relay? I'm not being disingenious here, it's just that you still aren't explaining clearly.

The literal answer to that question would be, connect one terminal of the button to pin 5, and the other to pin 6. Or a relay :slight_smile:

This hinges on what the H you mean by, "connect pin 5 to pin 6 ". To do that, you would normally run a wire, or complete an electrical connection, from pin 5 to pin 6 (not that I would recommend it).

I strongly recommend that you post a schematic of your circuit.

You do realize that the Arduino has nothing like internal switches or analog multiplexers that you can assign to pins, right?

DARCCLLC:
I'm trying to connect pin 5 to pin 6 when I press a button. Like a relay.

Pins don't do that.

You can connect a pin to the +5v rail on the board, you can connect it to ground, you can connect it to the +5v rail with a resistance, and you can leave it floating (very high impedance to ground, I think).

I think we are perplexed by your question, and believe that you MAY be going about things in the wrong way. So: Why do you want to connect pin 5 to pin 6?

This won't accomplish much by itself.

By solar LED, do you mean one of those garden decorations, you put it in the sun, it charges a battery, and when the sun goes down, a LED comes on (we have some of those that look like dragonflies. They are cool, and seem to last forever - they are 5 years old and still work fine.

So (rephrasing) what part of this do you want the Arduino to do? Please don't talk about internal relays, because we don't know what you mean by that.

Please post a schematic of your circuit. Nothing else will help.

Do you mean you want pin6 to mimic the state of pin5?
You have pin5 as an output:
pinMode(led5, OUTPUT); //Pin 5 1.2V from Cell

Perhaps you meant pin5 as an input?
Since you never write it, but you do read it later on:
led6on = digitalRead(led5); //Makes led6on = Pin 5 value

If your comment is correct, above you have it connected to a 1.2V source.
That will only read low, as an input needs 0.3 x Vcc (5V) = 1.5V to be read as a high.

I believe the OP thinks he can close a circuit between pins 0 and 12 by writing pin0 = digitalRead(pin12).

I think the OP wants to pass some 'voltage' through the Arduino - using the pins as simple 'contacts' to his hoped-for Arduino 'relay'.

If that's the case - he's completely on the wrong track - and either needs an external relay & driver, or to approach the problem in a different way.

His swx (switch?) pins are assigned as OUTPUTS - so that's not a good start.

This is the second time this weekend someone wanted to use a switch to connect one pin to the other. The other instance was on a steering wheel.

Maybe we are missing something, if we could market the solution, we could make a million.

If you want pin 5 to be in the same condition as pin 6, and you already have the wherewithal to control pin 6, why not just control pin 5 the same way.

But I'm probably missing something here, and as someone suggested already I suspect an XY problem here.

ChrisTenone:
This is the second time this weekend someone wanted to use a switch to connect one pin to the other. The other instance was on a steering wheel.

..... and that didn't end well :wink:

As aarg stated "You do realize that the Arduino has nothing like internal switches or analog multiplexers that you can assign to pins, right?"

I have worked with PLC's and did not realize that Arduino does not have internal switches.

Thanks for your time and patience.

I'll be looking for a STSP relay.