Go Down

Topic: Arduino Wireless Remote -- Help Please! (Read 4941 times) previous topic - next topic

HazardsMind

Something is making button 2 HIGH, so, do you have pull down resistors? You can not have a floating input, otherwise it will give you bad results.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

MaxKulik

I don't exactly know what a Pull down resistor is. I know what a resistor is though.

PaulS

Code: [Select]
  if (digitalRead(Button1)){
The digitalRead() function does not return a boolean. You should NOT be writing code that looks like it does.

MaxKulik

So are you saying the code is set up to return a "True" or "False" statement but in face it is not?

PaulS

Quote
So are you saying the code is set up to return a "True" or "False" statement but in face it is not?

No. I'm saying that you have written the code in a way that makes it appear as though digitalRead() returns true or false, when, in fact it returns HIGH or LOW.

MaxKulik

#35
Mar 17, 2013, 05:46 pm Last Edit: Mar 17, 2013, 05:53 pm by MaxKulik Reason: 1
Can "True" or False" act as "HIGH" or "LOW"? Or is there a different way I can re-write that statement in order for it to function as it should?

MaxKulik

Alright playing around with the controller code for a while and this is what I have:

Code: [Select]

#include <VirtualWire.h>

int RF_TX_PIN = 2;
int Button1 = 13;      //Forward (Button 1)
int Button2 = 12;      //Backwards (Button 2)

void setup()
{
 Serial.begin(9600);
 Serial.println("Setup Complete");
 vw_set_tx_pin(RF_TX_PIN); // Setup transmit pin
 vw_setup(2000); // Transmission speed in bits per second.
 pinMode(Button1, INPUT);
 pinMode(Button2, INPUT);
}

void loop()
{
 if (digitalRead(Button1)){
 Serial.println("Forwards");
 const char *msg = "1";
 vw_send((uint8_t *)msg, strlen(msg));  // Send 'Forwards' every 50ms.
 }
 else if (digitalRead(Button2)){
 Serial.println("Backwards");
 const char *msg = "2";
 vw_send((uint8_t *)msg, strlen(msg)); // Send 'Backwards' every 50ms.
 }
 else {
 Serial.println("Stop");
 const char *msg = "0";
 vw_send((uint8_t *)msg, strlen(msg));  // Send 'Stop' every 50ms.
 }
}


Everything works, other then the fact that it is always transmitting "2" or backwards. As of right now I am stuck because I even did some research on how if-then-else statements and how they work and I don't see why this doesn't work.

HazardsMind

#37
Mar 17, 2013, 08:18 pm Last Edit: Mar 17, 2013, 08:21 pm by HazardsMind Reason: 1
Did you install pull down resistors on the buttons? Do a search for "pull down resistor", and to use them with buttons.

Added: Wait, did you put one the receive code a way to turn off the second relay? Another thing, does the serial monitor put out "Backwards"?
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

MaxKulik

#38
Mar 17, 2013, 08:22 pm Last Edit: Mar 17, 2013, 08:24 pm by MaxKulik Reason: 1
**EDIT** No and yes it does say "Backwards"

Is this what I am looking for:



I can do this easy, I just want to make sure I am looking at the right thing. I am currently reading about them too, just to understand them a bit more.

MaxKulik


Did you install pull down resistors on the buttons? Do a search for "pull down resistor", and to use them with buttons.

Added: Wait, did you put one the receive code a way to turn off the second relay? Another thing, does the serial monitor put out "Backwards"?


No I don't think I did and Yes it does just print out "Backwards" on the serial monitor, BUT every now-and-then I will see "stop".

HazardsMind

Ok so, when you install those pull down resistors, everything will work fine.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

MaxKulik


HazardsMind

My GitHub:
https://github.com/AndrewMascolo?tab=repositories

MaxKulik

After installing the pull-down resistors, everything seems to check out perfect on the serial monitor. It repeats "stop" when nothing is pressed, "forward" when the forward button is pressed, and "backward" when the backwards button is pressed. Here are some updated picture of the controller:







The last thing that I seem to be having a problem with is powering everything on the board. When I have it plugged into my laptop and a 9v batter at the same time I have no problem with power. It seems that the 9v battery alone is nowhere near as powerful as it needs to be for all the LEDs and receiver and such. Do you or anyone have any suggestions as to how I could power the Arduino better?

HazardsMind

You should use a 9V rechargeable battery pack like the ones used in RC cars.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

Go Up