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?

.

Welcome to the Arduino forums.

The people here want to help you but to do that we need certain bits of information. Without the correct information it is difficult or impossible to give you the help and advice you need. To help us to help you please read General guidance below and How to use this forum and provide the information asked for.

Being new here you might think this is asking too much or having rules for the sake of rules, that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of message while we try to get you to tell us what we need in order to help you, this is frustrating for you and frustrating for us.

Common mistakes for people posting here the first time:

Code problems:
Not posting any code while expecting us to work out what is wrong with your code; we are not telepathic and can only find problems in code we can see.
Posting a snippet of code in the belief that the problem is in the code snippet. It is almost always the case that the problem is not where you think it is but elsewhere in the code, hence we need all the code.
Not correctly formatting code. Before posting code use Tools / auto format at the top of the IDE, or use control T. Once you’ve done that use edit / copy for forum.
Posting code without code tags (</>), these are explained in the instructions linked to above. Using code tags makes the code easier to read. Not using code tags means some of the code gets interpreted as HTML with the result that it is displayed with smiley faces and other stuff that should not be there.
Not being clear about what is expected from code or what happened instead. Code ALWAYS works, that is the nature of code. Whether it does what you expect is a different thing altogether. We need to know what you expected the code to do and what happened instead.
Asking for complete code; we are not here to write code for you, we are here to help you if you get stuck writing code yourself. If you really want someone to write code for you please click on ‘report to moderator’ and ask them to move this to ‘Gigs and Collaborations’ and indicate how much you are willing to pay.

Schematics:
The language of electronics is a schematic or circuit diagram. Long descriptions of what is connected to what are generally useless. A schematic is a drawing of what connects to what, please make one and photograph it. We don’t mind if it’s hand drawn, scruffy and does not use the correct symbols. We do mind if you don’t at least try to post a schematic. Most images will self-attach to the bottom of your post but if it doesn’t Please read How to post an image

General:
Posting links to other sites where code or photos or schematics are hosted. Most of us will not follow such links, partly because of the risk that they hold malware or other unwanted content, partly to maintain everything on this site for the benefit of future users looking for an answer to a similar question and partly because we feel that if you want our help you should provide everything we need on this site not expect us to go hunting elsewhere for it. Exceptions are where you may be asked for a specific link such as a datasheet or product etc. However don’t post links to “similar” items only the ones you have there or want advice about.

Questions:
Not being clear about what is being asked, for example not asking a question at all or asking a vague question like ‘please help’ or some such thing. The same if you don’t follow somebody’s answer. Ask them to explain a little more and be clear you did not quite understand the answer you were given.

About us:
Those of us answering questions have a wide variety of backgrounds and electronics knowledge, some though working in electronics, some through electronics as a hobby, some both. Most of us are not trained as teachers so probably miss the finer points of how to teach and explain things effectively. We are not, with the rare exception, employees or representatives of Arduino.
Please also remember we are volunteers doing this for free in our spare time and are more inclined to help people who make it easy for us to provide help by providing the information we ask for.

About you:
We only know about you what you tell us; we need to know your level of experience with electronics or microcontrollers, if we don’t know then we can’t tailor our answer to your level of knowledge. We also don’t know if you have problems with English or language or communications in general unless you tell us. We can be sympathetic about problems we know about, but if you don’t tell us we don’t know.
Thank you.

COMMON ISSUES

  • Check you have a COMMON GROUND where required.
  • Where possible use USB 2.0 ports or a USB 2.0 POWERED HUB to rule out USB 3.0 issues.
  • Try other computers where possible.
  • Try other USB leads where possible.
  • You may not have the correct driver installed. CH340/341 or CP2102
  • There may be a problem with the board check your wiring first.
  • Remove any items connected to pins 0 and 1.

COMPUTER RELATED

  • close any other serial programs before opening the IDE.
  • Ensure you turn off any additional security / antivirus just to test.
  • There may be a problem with the PC try RESTARTING it.
  • You may be selecting the wrong COM port.
  • Avoid cloud/network based installations where possible OR ensure your Network/Cloud software is RUNNING.
  • Clear your browsers CACHE.
  • Close the IDE before using any other serial programs.
  • Preferably install IDE's as ADMINISTRATOR or your OS equivalent

Arduino specific boards

  • CH340/341 based clones do not report useful information to the "get board info" button.
  • NANO (Old Types) some require you to use the OLD BOOTLOADER option.
  • NANO (New Types) See the specific sections in the forum.
  • NANO (New Types) Install your board CORE's.
  • Unless using EXTERNAL PROGRAMMERS please leave the IDE selection at default "AVRISP mkII".
  • Boards using a MICRO usb connector need a cable that is both DATA and CHARGE. Many are CHARGE ONLY.

CREATE editor install locations.

  • On macOs ~/Applications/ArduinoCreateAgent-1.1/ArduinoCreateAgent.app/Contents/MacOS/config.ini
  • On Linux ~/ArduinoCreateAgent-1.1/config.ini
  • On Windows C:\Users[your user]\AppData\Roaming\ArduinoCreateAgent-1.1

Performing the above actions may help resolve your problem without further help.
Language problem ?
Try a language closer to your native language:

Thanks to all those who helped and added to this list.

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?