Hello.
I have a pair of cheap wireless communication modules, that I bought off eBay.
it is the ones used in this tutorial:
I also copied most of my code from that tutorial.
I am using the virtual wire library.
here is all my code for the transmitter:
//Transmitter Code
#include <VirtualWire.h>
int potPin = 0;
int val;
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
vw_setup(2000);
vw_set_tx_pin(7);
}
void loop()
{
if(Serial.available())
{
char c = Serial.read();
if(c == '1')
{
vw_send((uint8_t *)c, 1);
}
else if(c == '0')
{
vw_send((uint8_t *)c, 1);
}
}
//val = analogRead(potPin);
}
and here is all my code for the reciever:
//Reciever Code
#include <VirtualWire.h>
void setup()
{
pinMode(13,OUTPUT);
digitalWrite(13,LOW);
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);
}
}
}
}
As it is there the code works as expected. I type a ‘1’ or a ‘0’ into the Serial terminal of the transmitter and then it will transmit over and the light on pin 13 on the receiver Arduino will turn on or off. (I normally have to type the 1 or the 0, two to three times for it to register, I’m pretty sure this is just because the modules are cheap and terrible).
However, if on the transmitter code I uncomment the line:
val = analogRead(potPin);
this reads from analog pin 0 which is hooked up to a potentiometer.
If I uncomment that line the transmission is really bad. Now when I have to type the ‘1’ or the ‘0’ into the Serial terminal 20-30 times for it to be registered by the receiver, and that’s only if I don’t give up before it actually decides to register at all.
So I was messing around for a long while trying to fix it and just randomly decided to unplug the wire on the transmitter Arduino from the 5V and plug it into the 3.3V and suddenly now it works, however the potentiometer only goes up to a value of ~750 I think it was.
so I was hoping that you could help me out and figure out what is going on here.
Why does it work for the 3.3V and not the 5V?
why does just reading from the analog pin affect the transmission so much?
Is there a way I can have 5V and have the transmission working properly?
thankyou.