Problem with momentary button function via rf module

Hi
I'm kind of new to programming. I tried to modify an existing code in order to have an extra momentary button funtion. The wireless motor control of the rover is working as desired, but the pushbutton function is not.

On the hardware side:

Transmitter (Arduino mini pro):

  • The rf module (hc-12) is connected to pin 3
  • The pushbutton is connected on pin 8

Receiver (Arduino Uno):

  • The rf module (hc-12) is connected to A0
  • The LED is connected to Pin 13 and GND

Any help is very much appreciated!

RX_433Mhz_Robot_mod_delay.ino (3.71 KB)

TX_433Mhz_Robot_mod_delay.ino (1.92 KB)

So, you attached one wire of the switch to the Arduino, left the other one dangling, and cobbled up some code that does something. You didn't see fit to say what it actually does. You didn't see fit to say what you expected.

On the other Arduino, you cobbled up some more code that does something. You didn't see fit to say what it actually does. You didn't see fit to say what you expected.

And, yet, you want us to tell you what is wrong. It's your switch wiring.

Hi Paul

Thanks for Your reply. You're right about my lack of knowledge regarding programming (unfortunately I only did one semester in electronic engineering at the university ;). But on the hardware side I actually know what I'm doing. I forgot to mention in the first post that the button is not only connected to Pin 8, but also to GND with a 10k pulldown resistor. I also measured the button function (5V on Pin 8) with my fluke multimeter.

So I'm still guessing there must be a beginner mistake in the code..

On the transmitter side, you call Serial.begin() but then you never call Serial.print(). So, how do you KNOW what the transmitter is doing?

   onOff = 1; //set boolean to 1

Rubbish. Set booleans to true or false.

You really should look at the state change detection example.

Why are you using println() in some places and write() in others to send ASCII data?

     if(bluetooth.available() >1){
        int input = bluetooth.parseInt(); //read serial input and convert to integer
        if(input == 1111){ // if code is received
          digitalWrite(ledPin, HIGH); // turn LED on
        }
        if(input == 0000){ // if code is received
          digitalWrite(ledPin, LOW); // turn LED off
        }
      }

This code has no place in the body of a switch statement.

      bluetooth.flush(); // clear the serial buffer for unwanted inputs

Bullshit. That is NOT what that code does. It is, in fact, completely useless code.

You need to completely rethink what you are sending or how you are reading the data from the bluetooth device.

Ok so I tried to solve the problem by deleting the "useless code" and try it with a simply case switching, like the two motor controls are driven.
But I still get no output on Pin 13. What am I doing wrong?

TX_433Mhz_Robot_mod_2.ino (1.88 KB)

RX_433Mhz_Robot_mod_2.ino (3.4 KB)

What are you sending? Why don't you know?
What are you receiving?

I'm sending the caracter "6" by BTSerial.write("6") in order to activate the case 6 which is linked with digitalWrite(ledPin, HIGH). No?

Hi Paul

I just connected another rf module (same as on the receiver) and wired it to an arduino uno with a instant messenger code. In the serial monitor I can actually see that the character "6" (and the caracter "D" which stands for both motors stop) is sent when the button pushed.

I'm sending the caracter "6" by BTSerial.write("6") in order to activate the case 6 which is linked with digitalWrite(ledPin, HIGH). No?

You may think you are. But, are you? Is it REALLY that difficult to add some curly braces and a Serial.print() statement to assure yourself that you are?

laurin123:
Hi Paul

I just connected another rf module (same as on the receiver) and wired it to an arduino uno with a instant messenger code. In the serial monitor I can actually see that the character "6" (and the caracter "D" which stands for both motors stop) is sent when the button pushed.

So, why can't you do the same thing on the real receiver? Whatever it was you did. I have no idea what an "instant messenger code" is.

I actually connected the same receiver (same channel) to an Uno and read the incoming data sent by the transmitter by the serial monitor. But also now did a serial.Print as you suggested. I get the same data. I get a clear "6" character (as programmed) when the button is pushed.