I'm a beginner in arduino and i'm zero knowledge in this. having some problem. i tried to program arduino using 8 digital input to control 8 digital output. right now i got 8 push button and 8 relay module. can anyone help me to guide me how to program each input to control each relay?(FYI i also didn't had experience in C language). eg. if i press push button 1, relay 1 will trigger until i repress the push button 1 again it will off. same goes to other push button and relay.
Start simple, get the hardware working, expand from there
byte input2 = 2; // button wired to connect to Ground when pressed
byte ouptut3 = 3; // out that will drive output high hwen button is pressed,
// assuming it will drive a transistor to sink coil current & change contacts
// from Common-NC to Common-NO
// change to low if needed
void setup(){
pinMode (input2, INPUT_PULLUP);
pinMode (output3, OUTPUT);
}
void loop(){
if (digitalRead(input2) == LOW){ // button pressed?
digitalWrite (output3, HIGH); // energize relay coil
}
int led[] = {53, 51};
int button[] = {2, 3};
int val;
int lastButtonState = LOW;
int buttonState;
int ledState = LOW;
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup() {
int i = lastButtonState;
pinMode(led*, OUTPUT);*
_ pinMode(button*, INPUT);_ _ digitalWrite(led, ledState); } void loop() { int i = lastButtonState; val = digitalRead(button); if (val == lastButtonState) { lastDebounceTime = millis(); } if ((millis() - lastDebounceTime) > debounceDelay) { if (val != buttonState) { buttonState = val; if (buttonState == HIGH) { ledState = !ledState; } } } digitalWrite(led, ledState); lastButtonState = val; }* but, seem not working. help me please...._
Also everything has to be an array and you need to use the array index. For example you need the lastButtonstate variable to be an array as well as lastDebounceTime and ledState.
Read the how to use this forum sticky post on how to post code before you post any more.