Control Led from 2 buttons

Hello everyone. Well what I intend to do is to control an LED wirelessly and also locally so that it works like a combined key, ocea who can turn from one side and on the other or vice versa, or just turn off and light from either side.

Hola a todos. Bueno lo que pretendo hacer es controlar un led de forma inalambrica y tambien de forma local de tal modo de que funcione como si fuera una llave combinada, ocea que lo pueda apagar de un lado y encender del otro o viceversa, o tan solo apagar y encender de cualquiera de los dos lados.

This is the link where I try to do the project
Este es el link de donde yo intento hacer el proyecto

Control 433 TR RC

Entiendo que debo hacer modificaciones en el sketch del receptor y al proyecto original agregarle un boton o switch en la protoboard como este
I understand that I must make modifications to the sketch of the receiver and the original project to add a button or switch on the breadboard like this

PushButton
I've tried but I had no luck. : smiley-cry:
Would greatly appreciate the help you could provide me: smiley-mr-green:
Lo he intentado pero no he tenido suerte. :sob:
Agradeceria mucho la ayuda que me pudieran brindar ¡ :grin:

Program code for the transmitter


/*
SimpleSend
This sketch transmits a short text message using the VirtualWire library
connect the Transmitter data pin to Arduino pin 12
*/
#include 
int switchPin = 8;
boolean lastButton = LOW;
boolean currentButton = LOW;
int check = 0;

void setup()
{
pinMode(switchPin, INPUT);

// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
}

boolean debounce(boolean last)
{
boolean current = digitalRead(switchPin);
if (last != current)
{
delay(5);
current = digitalRead(switchPin);
}
return current;
}

void loop()
{
currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton == HIGH && check == 0)
{
send("on");
delay(500);
check = 1;
}
else 

if (lastButton == LOW && currentButton == HIGH && check == 1)
{
send("off");
delay(500);
check = 0;
}
}

void send (char *message)
{
vw_send((uint8_t *)message, strlen(message));
vw_wait_tx(); // Wait until the whole message is gone
}

Program code for the receiver

/*
SimpleReceive
This sketch displays text strings received using VirtualWire
Connect the Receiver data pin to Arduino pin 11
*/
#include
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message
int relayPin = 7;

void setup()
{
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH);

Serial.begin(9600);
Serial.println("Device is ready");
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver
}
void loop()
{
if (vw_get_message(message, &messageLength)) // Non-blocking

{
Serial.print("Received: ");
for (int i = 0; i < messageLength; i++)
{
char c = message*;*
Serial.print(c);
char on = 'on';
if(c == on)
{
digitalWrite(relayPin, LOW);
}
char off = 'of';
if(c == off)
{
digitalWrite(relayPin, HIGH);
}
}
Serial.println();
}
}

char on = 'on';

Single quotes are for single characters. Please post a picture of your keyboard with the on key circled.

if(c == on)

Never going to be true. One character sent over the radio is never going to equal a multi-byte character (which the Arduino doesn't handle worth a damn anyway).

The receiver sketch is working good, only i have want to add a button here, so i also have control of the led in the receiver.

The receiver sketch is working good,

I disagree, so I'll just wish you luck.

Use one of the examples in serial input basics - whichever best suits your project.

If code with char on = 'on' (single quotes) appears to be working it is an accident waiting to happen.

...R

Ok thanks for the suggestions of the quotes.
i have got do something about what i wanted
This is the modification i had make to the receiver sketch

//Program code for the receiver

/*
 SimpleReceive
 This sketch displays text strings received using VirtualWire
 Connect the Receiver data pin to Arduino pin 11
 */
 #include <VirtualWire.h>


 byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
 byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message
 int relayPin = 7;
 const int botonPin = 8;     // Pin para el boton *****************************************
 int estadoBoton = 0;         // Variable para la lectura estado del boton ****************
 int salida = 0;              //*************** 
 int estadoAnterior = 0;      //***************          
void setup()
 {
   pinMode(botonPin, INPUT); // Inicializa el pin del boton como entrada **************
 pinMode(relayPin, OUTPUT);
 digitalWrite(relayPin, HIGH);

Serial.begin(9600);
 Serial.println("Device is ready");
 // Initialize the IO and ISR
 vw_setup(2000); // Bits per sec
 vw_rx_start(); // Start the receiver
 }
 void loop()
 {
    estadoBoton = digitalRead(botonPin); //**************************************************

  if ((estadoBoton == HIGH)&&(estadoAnterior == LOW)){ //*************************
    salida = 1 - salida;                               //**********************
    delay(20);                                         //********************
  }                                                    //********************
  estadoAnterior = estadoBoton;                        //********************
  
if ((estadoBoton == HIGH)&&(salida == 1)){             //********************
digitalWrite(relayPin, HIGH);                          //********************


}
if ((estadoBoton == HIGH)&&(salida==0)){               //********************
  digitalWrite(relayPin, LOW);                         //********************
 
}
delay(20);                                             //********************

 if (vw_get_message(message, &messageLength)) // Non-blocking

{
 Serial.print("Received: ");
 for (int i = 0; i < messageLength; i++)
 {
 char c = message[i];
 Serial.print(c);

char on = 'on';
 if(c == on)
 {
 digitalWrite(relayPin, LOW);
 //delay(20);
 
 }
 char off = 'of';

if((c == off))
 {
 digitalWrite(relayPin, HIGH);

 }
delay(20);
}


 Serial.println();
 }
 
 }

this is the link of one video i uploaded
Video control led from 2 buttons . modulo 433

char off = 'of';

Why is that in the revised code?

...R

I don 't know why, but if i change 'of' for "of" then it not work. try make this proyect look i am not a programmers i am learning. :sweat_smile:

oeste24:
I don 't know why, but if i change 'of' for "of" then it not work. try make this proyect look i am not a programmers i am learning.

You may not be getting a compiler error with char off = 'of'; but you can be absolutely certain it is NOT doing what you think it is doing. When you change to double quotes and get the error that is the correct situation.

I think you were already told that a char variable can only hold a single character whereas you are trying to make it hold two characters. I think you were also told that single quotes are for single characters and double quotes are for multiple characters. So you either need a char array and double quotes or a simple char variable and a single character and single quotes. You have to choose.

...R

Haaa ok, now i understand that is there a ERROR in the sketch, I will play with the code and change those quotes, i hope to have luck. thank you very much for your patience Robin and Pauls