arduino remote

I am trying to wirelessly control whenever a led is on or off by a signal. I have the transmitter’s ground pin connected the vcc to 5 volts and the data pin to pin 12. For the signal I have a wire connecting to ground and another wire connecting to A0. When I connect them it gave me an analog read of 0 and used that.
I also have an led connected to pin 53 to show me when the message is being sent.

For the receiver I have the 5 volts and ground connected and the data pin also connected to pin 12.
I also have an led on pin 53 to tell me if the message is received and it hasn’t lightened up.

Here is the transmitter code:
#include <VirtualWire.h>
const char *message = “Merry Christmas”;

void setup() {
pinMode(A0,INPUT);
pinMode(53,OUTPUT);

vw_set_ptt_inverted(true);
vw_set_tx_pin(12); // set transmitter pin
vw_setup(4000);// speed of data transfer Kbps
}

void loop(){

if (analogRead(A0) == 0){
digitalWrite(53,HIGH);
message=“X”;
vw_send((uint8_t *)message, strlen(message));
vw_wait_tx();
delay(2000);
}
else if(analogRead(A0) != 0){
digitalWrite(53,LOW);
}
}

Here is the reciever code:

#include <VirtualWire.h>

int ledActive = 53;

void setup()
{
pinMode(ledActive,OUTPUT);

vw_set_ptt_inverted(true);
vw_set_rx_pin(12);
vw_rx_start();
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen)) {
if(buf[0]==‘X’){
digitalWrite(53,HIGH);
}
else if(buf[0]!=‘X’){
digitalWrite(53,LOW);
}

}
}

Sorry for any mispells but I uploaded it and the code seems fine so what am I doing wrong?

Could you take a few moments to Learn How To Use The Forum. Other general help and troubleshooting advice can be found here. It will help you get the best out of the forum in the future

Hi I’m using the arduino ATmega2560 to try to wirelessly control and led with a signal. Whenever I connect 2 wires on the transmitter arduino the receiver arduino’s led is supposed to light up. and a message on the Serial port is supposed to show up.
For the transmitter arduino it had pin 12 for data. pin 2 for the signal(I couldn’t find a button so is just me connecting 2 wires with each 1 in a different hand)pin 2 is connected to ground with a 470 ohm resistor and I connect 5 volts through a wire to the pin 2 wire. The led is on pin 53. The code for the transmitter is given.

twenty.jpg

TransmitterCode.ino (943 Bytes)

For the receiver arduino the data pin is again pin 12 and an led is connected to pin 52.
Can someone tell me what is wrong because the led doesn’t light up(look at the code). And a message doesn’t show up on the serial monitor(on the code).

here is the code for the receiver:

#include <VirtualWire.h>

void setup()
{
pinMode(52,OUTPUT);

vw_set_ptt_inverted(true); // On a communication line means that each
// party is either transmitting or receiving ( like a walkie talkie)
vw_set_rx_pin(12); // set receiver pin
vw_setup(4000); // Bits per sec
vw_rx_start(); // Start Phase Locked Loop (listening to the receiver)
Serial.begin(9600);
}
void loop()
{

digitalWrite(52,LOW);
uint8_t buf[VW_MAX_MESSAGE_LEN]; // 80 bytes is messgage length
uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen)) { // if message received
if(buf[0]==‘X’){ // and if the first letter in message array is X

Serial.print(“received”);
digitalWrite(52,HIGH);
delay(2000);

}
else if(buf[0]!=‘X’){
digitalWrite(ledPassive,HIGH);
}

}
}

sorry for any misspells i verified it and the code seems fine.

Duplicate topics merged

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

oh sorry I originally posted it and nothing showed up and I thought that I wrote everything out but didn't post it so I did it again. Sorry and I will read it.

I have already tried a ton of videos on google and some articles and almost always they didn't have what I wanted or required 3 random IC chips that I didn't have. And if your confused why the file transmitter and receiver code are different. It is because I edited it so the codes from the first post are the ones that I am actually using. So what I used is a wire from ground and a wire from A0. When I connect them the analog Read should equal 0. When it equals 0 the if statement should work and to make sure of that I added an led on pin 53. So then the message should transmit and the receiver should get it and an led form there should light up. This code seems right, right? If it is I guess then it is a hardware problem.

One more question on the twenty.pg file ont the very right is the word ATAD and on the very left ground. Does this mean I should put the 5 volts in the middle?