How can I use switch on adruino? (not pushbutton)

how can I use this on adruino? (not pushbutton)

Link: http://www.ebay.com/itm/5-pcs-Heavy-Duty-15A-250V-SPST-2-Terminal-ON-OFF-Toggle-Switch-Waterproof-Boot-/162403428711?hash=item25cfffa967:g:7xoAAOSw9mFWKJiv&vxp=mtr

just Gnd to it and put it in inputpins?

...and enable the input pullup resistor.

Do you have a drawing? :slight_smile: and code :slight_smile:

A button is just a switch that gets unswitched when you let go of it.

Literally every tutorial that shows you how to hook up a button will also work for a switch.

Yes like this:)

But how to change the code, so it works on (not pushbutton) :smiley:

remove this: // variables will change:
int buttonState = 0; // variable for reading the pushbutton status

A pushbutton is just a switch that operates momentarily. So you need to explain to us, what you need the software to do that is different.

You could just replace

int buttonState = 0;

with

int switchState = 0;

:wink:

oki :slight_smile:

Car control system

Going to make 2 arduino NANO to control relay like this:

Arduino 1: 5 switch and 5 led light (When I turn on switch then the led lights and it send RX/TX to my arduino 2)

¤RX/TX¤

Arduino 2: 5 relay ( He get info from arduino 1 and turn on relay )

I be happy if you make a exempl code to me I can work with :smiley:

Why the second Arduino? Just connect the relays to the first Arduino (and make sure to power the relays themselves using an external power supply, only control them by the Arduino).

There are switch and LED examples in the example sketches that come with the IDE.

There :slight_smile: But how do I fix the blink? Can the blink get a own loop? Button2 not work befor delay is over in button1

/*


 http://www.arduino.cc/en/Tutorial/Button
 */

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin1 = 1;     // the number of the pushbutton pin
const int buttonPin2 = 2;     // the number of the pushbutton pin
const int buttonPin3 = 3;     // the number of the pushbutton pin
const int buttonPin4 = 4;     // the number of the pushbutton pin

const int ledPin1 =  5;      // the number of the LED pin  Starter når arduino starter
const int ledPin2 =  6;      // the number of the LED pin
const int ledPin3 =  7;      // the number of the LED pin
const int ledPin4 =  8;      // the number of the LED pin
const int ledPin5 =  9;      // the number of the LED pin

#define RELAY1  10 
#define RELAY2  11
#define RELAY3  12
#define RELAY4  13

// variables will change:
int buttonState1 = 0;         // variable for reading the pushbutton status
int buttonState2 = 0;         // variable for reading the pushbutton status
int buttonState3 = 0;         // variable for reading the pushbutton status
int buttonState4 = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
// initialize the relay
   pinMode(RELAY1, OUTPUT);  
   pinMode(RELAY2, OUTPUT);  
   pinMode(RELAY3, OUTPUT);  
   pinMode(RELAY4, OUTPUT);  
//oppstart
    digitalWrite(ledPin1, HIGH);
}

void loop() 



{
  //blink til led
  // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState1 == HIGH) {
    // turn blink LED on:
    digitalWrite(ledPin2, HIGH);
    delay(500);
    digitalWrite(ledPin2, LOW);
    delay(500);
  } else {
    // turn blink LED off:
    digitalWrite(ledPin2, LOW);
   }
   
  //button1
  // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState1 == HIGH) {
    // turn LED on:
    digitalWrite(RELAY1,0);           // Turns ON Relays 1
  } else {
    // turn LED off:
    digitalWrite(RELAY1,1);          // Turns Relay Off
  }
  
  //button2
  // read the state of the pushbutton value:
  buttonState2 = digitalRead(buttonPin2);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState2 == HIGH) {
     digitalWrite(RELAY2,0);           // Turns ON Relays 1
    // turn LED on:
    digitalWrite(ledPin3, HIGH);
  } else {
     digitalWrite(RELAY2,1);          // Turns Relay Off
    // turn LED off:
    digitalWrite(ledPin3, LOW);
 } 


  //button3
  // read the state of the pushbutton value:
  buttonState3 = digitalRead(buttonPin3);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState3 == HIGH) {
     digitalWrite(RELAY3,0);           // Turns ON Relays 1
    // turn LED on:
    digitalWrite(ledPin4, HIGH);
  } else {
     digitalWrite(RELAY3,1);          // Turns Relay Off
    // turn LED off:
    digitalWrite(ledPin4, LOW);
 }
    
   
  //button4
  // read the state of the pushbutton value:
  buttonState4 = digitalRead(buttonPin4);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState4 == HIGH) {
     digitalWrite(RELAY4,0);           // Turns ON Relays 1
    // turn LED on:
    digitalWrite(ledPin5, HIGH);
  } else {
     digitalWrite(RELAY4,1);          // Turns Relay Off
    // turn LED off:
    digitalWrite(ledPin5, LOW);
 }

}

Look at the "blink without delay" example on how to get rid of those blocking delays.