Go Down

Topic: How to program a simple switch? (Read 2285 times) previous topic - next topic

DARCCLLC

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

larryd

#1
Apr 10, 2016, 11:51 pm Last Edit: Apr 10, 2016, 11:52 pm by LarryD
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?

.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Delta_G

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. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

DARCCLLC

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

aarg

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
Code: [Select]
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.
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

DARCCLLC

Code: [Select]
                         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





aarg

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.
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

DARCCLLC

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

aarg

#8
Apr 11, 2016, 01:24 am Last Edit: Apr 11, 2016, 01:32 am by aarg
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 :)

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?
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

PaulMurrayCbr

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).
http://paulmurraycbr.github.io/ArduinoTheOOWay.html

ChrisTenone

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.
What, I need to say something else too?

aarg

Please post a schematic of your circuit. Nothing else will help.
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

Delta_G

|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

outsider

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

Go Up