I am using an rf module to send numbers to two ardunos.
Using the radio head library I did the normal example of sending a msg(inthis case Welcome to the Workshop)
Which worked fine.
But using if statements I made it send the number 1 if it recieved input from pin 4
And 2 if input from pin 5.
All I'm getting on the reciver end is random numbers.
Troubleshooting code that we cannot see is difficult, doubly so now that my crystal ball is out for an oil change.
Post your transmit and receive codes. Please read the forum guidelines to see how to properly post code and some information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
two 3 pos switches both powered by arduino uno 3.3 v port.
switch1 = front,back, one pos to 6,other pos to 7
switch2 = left,right one pos to 8,other pos to 9
Please post a schematic. Written descriptions are always more ambiguous than a drawing. Hand drawn, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.
#include <RH_ASK.h>
#include <SPI.h>
int rightfront = 1;
int rightback = 2;
int leftfront = 3;
int leftback = 4;
RH_ASK driver;
void setup()
{
Serial.begin(9600);
driver.init();
}
void loop()
{
uint16_t data;
uint8_t datalen = sizeof(data);
if (driver.recv((uint8_t*)&data, &datalen))
{
Serial.println(data);
}
if(data == 1)
{
//switch on motor driver front pins
digitalWrite(rightfront,HIGH);
digitalWrite(leftfront,HIGH);
//switch off other back pins
digitalWrite(rightback,LOW);
digitalWrite(leftback,LOW);
}
else if(data == 2)
{
//switch on motor driver back pins
digitalWrite(rightback,HIGH);
digitalWrite(leftback,HIGH);
//switch off other front pins
digitalWrite(rightfront,LOW);
digitalWrite(leftfront,LOW);
}
else if(data == 3)
{
//switch on right back and left front pins to turn right
digitalWrite(rightback,HIGH);
digitalWrite(leftfront,HIGH);
//set left back and front back to off
digitalWrite(rightfront,LOW);
digitalWrite(leftback,LOW);
}
else if(data == 4)
{
//switch on right front and left back pins to turn right
digitalWrite(rightfront,HIGH);
digitalWrite(leftback,HIGH);
//set left front and right back to off
digitalWrite(rightback,LOW);
digitalWrite(leftfront,LOW);
}
}