rf transmitter/ receiver

I wanted to learn how to integrate a radio frequency receiver and transceiver into my arduino projects, so I looked up how to, wired it up, and programmed it, but yet it still didn’t work. I think the problem is in the programming,but i could post a schematic of the project if necessary.
Transmitter:

#include <VirtualWire.h>

void setup(){
  
  
  pinMode(A0, INPUT);
  vw_setup(2000);
  vw_set_tx_pin(7);
}

void loop(){
 
   char c = digitalRead(A0);
   
   if(c == '1'){
     vw_send((uint8_t *)c, 1);
   }else if(c == '0')
   {
     vw_send((uint8_t *)c, 0);
   }
 }

Receiver:

#include <VirtualWire.h>

void setup(){
  pinMode(13,OUTPUT);
  
  vw_setup(2000);
  vw_set_rx_pin(7);
  vw_rx_start();
}

void loop(){
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  uint8_t buf[buflen];
  
  if(vw_get_message(buf, &buflen))
  {
    for(int i = 0;i < buflen;i++){
      if(buf[i] == '1'){
        digitalWrite(13,HIGH);
      }else if(buf[i] == '0'){
        digitalWrite(13,LOW);
      }
    }
  }
}

It is always a good idea to try the working examples (and there are many), before you "roll your own" code.

But here is one problem wuith yours:

char c = digitalRead(A0);
   
   if(c == '1'){

How often do you suppose that c will be equal to the ascii code for the digit 1?

   char c = digitalRead(A0);
   
   if(c == '1'){

The digitalRead() function does not return a char. It returns an int. The value that it returns is either 0 or 1, not ‘1’ or ‘0’.

Why do you want to send 1 or 0 bytes? Sending one byte, containing 0 or 1 makes more sense.

jremington I was using a push button so the only thing that was received was a one or a zero.

PaulS: I quite new to coding with chars, could you please explain how you think I could fix this.

'0' is hexadecimal 30 (the ASCII code for a printable 0)
0 is hexadecimal 00

'1' is hexadecimal 31 (the ASCII code for a printable 1)
1 is hexadecimal 01

A digitalRead returns a 0 or a 1, not '0' or '1'.

   int c = digitalRead(A0);
   
   if(c == 1){
      // do your thing here
   }

// or you can use 
    if(c) {
        //do your thing here
    }

Thank you, i will try it.

This is my new code, but it still doesn’t work

#include <VirtualWire.h>

void setup(){
  
  
  pinMode(A0, INPUT);
  vw_setup(2000);
  vw_set_tx_pin(7);
}

void loop(){
 
   char c = digitalRead(A0);
   
   if(c == 1){
     vw_send((uint8_t *)c, 1);
   }else if(c == 0)
   {
     vw_send((uint8_t *)c, 0);
   }
 }

This is not one of the working examples, and it won't work.

Find one of the working examples and make sure it functions correctly with your setup. Then, take a look at the program action that immediately follows the line "vw_send()"

Some examples can be found at http://www.airspayce.com/mikem/arduino/examples.html

How about posting links to your hardware.

Even so why are you using A0?

Mark

You posted revised transmitter code but did you also revise the receiver code? As already suggested, please post a schematic. Please also identify your TX and RX modules.

Documentation for the function calls in VirtualWire VirtualWire: VirtualWire.h File Reference

   if(c == 1){
     vw_send((uint8_t *)c, 1);
   }else if(c == 0)
   {
     vw_send((uint8_t *)c, 0);
   }

If c is 1, send 1 character. Otherwise, send 0 characters. Why? LOOK UP THE vw_send() FUNCTION. YOU ARE USING IT WRONG!