title: Using an RF module to control a motor with Arduino
body: <p>I am working on a project in which 2 Arduinos are used to use wireless comunnication with the help of RF modules. The goal of the communication is to drive a motor wirelessly.</p>
  <p>So far, I have written code for the transmitter and receiver based on example code found on this page: <a href="https://randomnerdtutorials.com/rf-433mhz-transmitter-receiver-module-with-arduino/" rel="nofollow noreferrer">https://randomnerdtutorials.com/rf-433mhz-transmitter-receiver-module-with-arduino/</a></p>
  <p>Following code is used to drive the transmitter module. This code is similar to the example code with modified output.</p>
  <pre><code>#include &lt;RH_ASK.h&gt;
  #include &lt;SPI.h&gt; // Not actually used but needed to compile
  
  RH_ASK driver;
  
  void setup()
  {
      Serial.begin(9600);    // Debugging only
      if (!driver.init())
           Serial.println(&quot;init failed&quot;);
  }
  
  void loop()
  {
      const char *msg = &quot;U&quot;;
      driver.send((uint8_t *)msg, strlen(msg));
      driver.waitPacketSent();
      delay(1000);
  }
  </code></pre>
  <p>This code is used to receive the message and drive the motor</p>
  <pre><code>#include &lt;RH_ASK.h&gt;
  #include &lt;SPI.h&gt;
  
  const int motorPin1 = 2;
  const int motorPin2 = 3;
  RH_ASK driver(2000, 7, 6, 5);
  
  const char *Up = &quot;U&quot;;
  const char *Down = &quot;D&quot;;
  
  void setup() {
    pinMode(motorPin1, OUTPUT);
    pinMode(motorPin2, OUTPUT);
    Serial.begin(9600);
    if (!driver.init())
      Serial.println(&quot;init failed&quot;);
  }
  
  void loop() {
      uint8_t buf[1];
      uint8_t buflen = sizeof(buf);
      if (driver.recv(buf, &amp;buflen)) // Non-blocking
      {
        int i;
        // Message with a good checksum received, dump it.
        if ((char*)buf == Up){
          digitalWrite(motorPin1, HIGH);
          digitalWrite(motorPin2, LOW);
        }
        else if ((char*)buf == Down){
          digitalWrite(motorPin1, LOW);
          digitalWrite(motorPin2, HIGH);
        }
          else{
          digitalWrite(motorPin1, LOW);
          digitalWrite(motorPin2, LOW);
        }
        Serial.println((char*)buf);
      }
  }
  </code></pre>
  <p>The final line in the receiver code is used to check via the serial interface if any message is received. This is the case. But for some reason, the message received is not the same as the provided control text. In essence, the send &quot;U&quot; is not the same as the character &quot;U&quot;.</p>
  <p>I suppose there is something wrong with the datatype of those variables. Anyone have any ideas what the problem could be?</p>