control 1 output with 6 push buttons for a basic nurse caller

Hello!

i'm trying to do a basic nurse caller, but i have a little problems when i'm coding, i have a caller and reset push buttons on six imaginary rooms, and a table with leds and each room with a led and finally one buzzer, the problem starts when i have two or more rooms active, the idea is if every room are off the buzzer stops but if one or more than two rooms are on the buzzer still on. I can't code it with push buttons, i try join all of the digital outputs of the arduino mega on the circuit but nothing ocurrs... some ideas for how to control one output with 6 push buttons?

Your description is very confusing! A diagram would be better, hand-drawn is ok. Not a full schematic at this stage, just a block diagram showing what controls and indicators are in which rooms.

(deleted)

Have a buzzer variable, initially telling buzzer off. Then inspect the inputs, and if one is active, set the buzzer variable on. Finally set the buzzer output on or off, depending on the buzzer variable state.

Thanks a lot for the ideas! all of them are great! now…

i’m iterating an array for identificate if one of the six rooms are HIGH the buzzer still on, but i can’t modify the array with a button for example:

int i = 0;
int rooms_on[6] = {est_1,est_2,est_3,est_4,est_5,est_6};


for(i; i<7; i++)
{
  if(salas_prendidas[i] == 1 )
  {
  
    digitalWrite(sound,HIGH);
  }
}


if(caller == HIGH)
{
est_1 == HIGH;
digitalWrite(room_1,HIGH);
}

if(caller_2 == HIGH)
{
est_2 == HIGH;
digitalWrite(room_2,HIGH);
}
if(caller_3 == HIGH)
{
est_3 == HIGH;
digitalWrite(room_3,HIGH);
}
if(caller_4 == HIGH)
{
est_4 == HIGH;
digitalWrite(room_4,HIGH);
}
if(caller_5 == HIGH)
{
est_5 == HIGH;
digitalWrite(room_5,HIGH);
}
if(caller_6 == HIGH)
{
est_6 == HIGH;
digitalWrite(room_6,HIGH);
}


if(RESET == HIGH)
{
est_1 == LOW;
digitalWrite(room_1,LOW);
}

if(RESET_2 == HIGH)
{
est_2 == LOW;
digitalWrite(room_2,LOW);
}
if(RESET_3 == HIGH)
{
est_3 == LOW;
digitalWrite(room_3,LOW);
}
if(RESET_4 == HIGH)
{
est_4 == LOW;
digitalWrite(room_4,LOW);
}
if(RESET_5 == HIGH)
{
est_5 == LOW;
digitalWrite(room_5,LOW);
}
if(RESET_6 == HIGH)
{
est_6 == LOW;
digitalWrite(room_6,LOW);
}

But it doesn’t work, i couldn’t modificate the state of an arrays’s variables with buttons, can you show me how can i do it?

Hi,

for (int i=0; i<6; i++)

Might help…
Your array starts at variable[0] to variable[5], so 6 variables
Please post you COMPLETE code and a basic circuit diagram so we can see how you have connected your components.
Your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Thanks… Tom… :slight_smile:

Also understand the difference between = and ==.

Hello! sorry for the delay, i got sick, here is the code, my original code is in spanish, i erased the six rooms code because is not understandable x.x


[code]// LLAMADOS Y RESETS, CALLER AND RESET
const int reset = 22;
const int llamado = 23;

const int reset_sala2 = 24;
const int llamado_sala2 = 25;


//LUCES DE TABLERO, SALAS Y SONIDOS//LIGHTS AND SOUND

int tablero = 34;
int sala = 35;
int sonido = 36;

int tablero_sala2 = 37;
int sala2 = 38;




// ESTADOS DE PULSADORES // BUTTONS

int estado = 0;
int estado2 = 0;

//ESTADOS DE SALAS //ROOM STATES
 bool est_sala = 0;
 bool est_sala2 = 0;
// ESTADOS DE RESETS
int reset_1 = 0;
int reset_2 = 0;

//iteration
//est_sala,est_sala2
int i = 0;
int salas_prendidas[2] = {est_sala,est_sala2};

void setup() {
 //CONFIGURACION DE LLAMADOS Y RESETS
 
  pinMode(llamado, INPUT);
  pinMode(reset,INPUT);
  
  pinMode(llamado_sala2, INPUT);
  pinMode(reset_sala2, INPUT);
  Serial.begin(9600);

 // CONFIGURACION DE LUCES DE TABLERO
  
  pinMode(tablero,OUTPUT);
  pinMode(tablero_sala2,OUTPUT);


 // CONFIGURACION DE LUCES DE SALAS
  
  pinMode(sala,OUTPUT);
  pinMode(sala2,OUTPUT);


 // CONFIGURACION DE SONIDOS
  pinMode(sonido,OUTPUT);
 

}

void loop() {
 // SE ALMACENAN LAS LECTURAS DE LOS BOTONES DE LLAMADOS
   estado = digitalRead(llamado);
 
   estado2 = digitalRead(llamado_sala2);
  
  
  

// SE ALMACENAN LAS LECTURAS DE BOTONES DE RESET   
   reset_1 = digitalRead(reset);
   reset_2 = digitalRead(reset_sala2);




for(i; i<6; i++)
{
  if(salas_prendidas[i] == 1 )
  {
    Serial.print("hola");
    digitalWrite(sonido,HIGH);
  }
}


if (estado == HIGH){
    
    digitalWrite(tablero,HIGH);
    est_sala = 1;
    digitalWrite(sala,HIGH);
     
    }

    if(reset_1 == HIGH){  
    
    digitalWrite(tablero,LOW);
    est_sala = 0;
    digitalWrite(sala,LOW);
    

    }  
    
    if(estado2 == HIGH){ 
    est_sala2 = 1;
    digitalWrite(tablero_sala2,HIGH);
    digitalWrite(sala2,HIGH);
     
     
    }  
    if(reset_2 == HIGH){  
    est_sala2 = 0;
    digitalWrite(tablero_sala2,LOW);
    digitalWrite(sala2,LOW);
    
    
    } 

    
}

Better:

for(i=0; i<6; i++)

Hi,
How have you got your buttons wired?

If pressing pulls the input high, have you got a 10k resistor between the input and gnd to pull the input to gnd when the button is open?

Your strategy needs to be;

Scan the CALL buttons and set that room's statevariable HIGH if the CALL button CHANGES from LOW to HIGH.
Scan the RESET buttons and set the statevariable LOW if the RESET button CHANGES from LOW to HIGH.
Scan the statevariables and check if they are ALL LOW, if NOT turn the buzzer ON. if they are ALL LOW turn the buzzer OFF.
Use the statevariable for each room to switch the LEDs ON or OFF.

We need to see a circuit diagram.....

Thanks.. Tom.. :slight_smile:

Here is a code what should do what you want to achieve. Its not very tidy, nor optimised, as i’m only a beginner…

Digital pins 2,3,4 represent 3 rooms. Requires latching switches to GND
Digital pins 8,9,10 are LED representing rooms each( 8=R1, 9=R2, 10=R3)
Digital pin 13 is the buzzer output (onboard LED)

I have used the built in pullup resistors, so you can directly GND(ground) pins 2,3,4

Any one pin, brings on the buzzer, and will remain on until no pins(rooms) are latched. And each pin(room) should also bring on 1 relevant related LED, indicating WHICH room. Its not a counter.

int buzzer = 13;
int buzzerstate = LOW;

int swt1 = 2;
int swt2 = 3;
int swt3 = 4;

int led1 = 8;
int led2 = 9;
int led3 = 10;

int room1 = HIGH;
int room2 = HIGH;
int room3 = HIGH;

int last1 = LOW;
int last2 = LOW;
int last3 = LOW;

void setup(){
  pinMode(buzzer, OUTPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(swt1, INPUT_PULLUP);
  pinMode(swt2, INPUT_PULLUP);
  pinMode(swt3, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop(){
  room1 = digitalRead(swt1);
  room2 = digitalRead(swt2);
  room3 = digitalRead(swt3);

if(room1 == LOW && last1 == LOW){
  last1 = HIGH;
  buzzerstate = HIGH;
  Serial.println("Room 1 Calling!");
}
if(room1 == HIGH && last1 == HIGH){
  last1 = LOW;
  Serial.println("Room 1 OFF!");
}
if(room2 == LOW && last2 == LOW){
  last2 = HIGH;
  buzzerstate = HIGH;
  Serial.println("Room 2 Calling!");
}
if(room2 == HIGH && last2 == HIGH){
  last2 = LOW;
  Serial.println("Room 2 OFF!");
}
if(room3 == LOW && last3 == LOW){
  last3 = HIGH;
  buzzerstate = HIGH;
  Serial.println("Room 3 Calling!");
}
if(room3 == HIGH && last3 == HIGH){
  last3 = LOW;
  Serial.println("Room 3 OFF!");
}
if(room1 && room2 && room3 == HIGH){
  buzzerstate = LOW;
  last1 = LOW;
  last2 = LOW;
  last3 = LOW;
  Serial.println("ALL OFF!");
}
digitalWrite(buzzer, buzzerstate);
digitalWrite(led1, last1);
digitalWrite(led2, last2);
digitalWrite(led3, last3);
}

The code below, does not require the latch, but instead has a “master reset” button.

int buzzer = 13;
int buzzerstate = LOW;
int reset = 12;
int resetstate = HIGH;

int swt1 = 2;
int swt2 = 3;
int swt3 = 4;

int led1 = 8;
int led2 = 9;
int led3 = 10;

int room1 = HIGH;
int room2 = HIGH;
int room3 = HIGH;

int last1 = LOW;
int last2 = LOW;
int last3 = LOW;

void setup(){
  pinMode(buzzer, OUTPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(reset, INPUT_PULLUP);
  pinMode(swt1, INPUT_PULLUP);
  pinMode(swt2, INPUT_PULLUP);
  pinMode(swt3, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop(){
  resetstate = digitalRead(reset);
  room1 = digitalRead(swt1);
  room2 = digitalRead(swt2);
  room3 = digitalRead(swt3);

if(room1 == LOW && last1 == LOW){
  last1 = HIGH;
  buzzerstate = HIGH;
  Serial.println("Room 1 Calling!");
}
if(room2 == LOW && last2 == LOW){
  last2 = HIGH;
  buzzerstate = HIGH;
  Serial.println("Room 2 Calling!");
}
if(room3 == LOW && last3 == LOW){
  last3 = HIGH;
  buzzerstate = HIGH;
  Serial.println("Room 3 Calling!");
}
if(resetstate == HIGH){
  buzzerstate = LOW;
  last1 = LOW;
  last2 = LOW;
  last3 = LOW;
  Serial.println("ALL OFF!");
}
digitalWrite(buzzer, buzzerstate);
digitalWrite(led1, last1);
digitalWrite(led2, last2);
digitalWrite(led3, last3);
}

Finally after a bit of insomnia on my side… A tested code which does what you were asking.
Same pins as above.
Digital pins 2,3,4 are room triggers // connect directly to GND
Digital pins 5,6,7 are reset buttons // connect directly to GND
Digital pins 8,9,10 are the led
Digital pin 13 is the buzzer (and on board LED)

The code is compiled and tested on UNO R3. Use Serial Monitor to view the results.

int buzzer = 13; //buzzer or alarm output
int buzzerstate = LOW;
//unsigned longs are used to prevent serial montior spamming debug text
unsigned long millis();
unsigned long lasttime = 0;

// trigger buttons and variable
int swt1 = 2; //room 1 call button
int swt2 = 3;
int swt3 = 4;
int room1 = HIGH;
int room2 = HIGH;
int room3 = HIGH;
//trigger debounce AND used for LED value
int last1 = LOW; //store if room was last pressed to prevent button being held and use for LED value
int last2 = LOW;
int last3 = LOW;

//reset buttons and variable
int rstin1 = 5; //reset room 1 button
int rstin2 = 6;
int rstin3 = 7;
int rst1 = HIGH;
int rst2 = HIGH;
int rst3 = HIGH;
//reset debounce, to prevent button being held and preventing other button pushes
int rstlast1 = HIGH;
int rstlast2 = HIGH;
int rstlast3 = HIGH;

//led output and last/led store
int led1 = 8; //room 1 led
int led2 = 9;
int led3 = 10;

void setup(){
  pinMode(buzzer, OUTPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(swt1, INPUT_PULLUP);
  pinMode(swt2, INPUT_PULLUP);
  pinMode(swt3, INPUT_PULLUP);
  pinMode(rstin1, INPUT_PULLUP);
  pinMode(rstin2, INPUT_PULLUP);
  pinMode(rstin3, INPUT_PULLUP);
  Serial.begin(9600); //enables serial monitor for debugging
}

void loop(){
  room1 = digitalRead(swt1);
  room2 = digitalRead(swt2);
  room3 = digitalRead(swt3);

  rst1 = digitalRead(rstin1);
  rst2 = digitalRead(rstin2);
  rst3 = digitalRead(rstin3);

if(room1 == LOW && last1 == LOW){ //if you press room1 button to GND, and was not last pressed, then should trigger
  last1 = HIGH;
  buzzerstate = HIGH;
  rstlast1 = LOW;
  Serial.println("Room 1 Calling!");
}
if(rst1 == LOW && rstlast1 == LOW){ //if you press reset button for room1 to GND, and it was not last pressed, then it should reset this room
  last1 = LOW;
  rstlast1 = HIGH;
  Serial.println("Room 1 OFF!");
}
if(room2 == LOW && last2 == LOW){ // trigger
  last2 = HIGH;
  buzzerstate = HIGH;
  rstlast2 = LOW;
  Serial.println("Room 2 Calling!");
}
if(rst2 == LOW && rstlast2 == LOW){ //reset
  last2 = LOW;
  rstlast2 = HIGH;
  Serial.println("Room 2 OFF!");
}
if(room3 == LOW && last3 == LOW){ //trigger
  last3 = HIGH;
  buzzerstate = HIGH;
  rstlast3 = LOW;
  Serial.println("Room 3 Calling!");
}
if(rst3 == LOW && rstlast3 == LOW){ //reset
  last3 = LOW;
  rstlast3 = HIGH;
  Serial.println("Room 3 OFF!");
}
if(rstlast1 && rstlast2 && rstlast3 == HIGH){ // if RESET was last used on all rooms, then switch off the single buzzer
  buzzerstate = LOW;
  if(lasttime+5000 < millis()){  // ALL off on monitor will not spam 100000's of times
  Serial.println("ALL OFF!");
  lasttime = millis();
  }
}
digitalWrite(buzzer, buzzerstate);
digitalWrite(led1, last1);
digitalWrite(led2, last2);
digitalWrite(led3, last3);
}