Pages: 1 2 [3] 4   Go Down
Author Topic: Arduino Wireless Remote -- Help Please!  (Read 4220 times)
0 Members and 1 Guest are viewing this topic.
Queens, New York
Offline Offline
Faraday Member
**
Karma: 101
Posts: 3644
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Muskego WI
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Be nice to nerds... Chances are, you'll end up working for one. -Bill Gates
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 616
Posts: 49433
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Muskego WI
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Be nice to nerds... Chances are, you'll end up working for one. -Bill Gates
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 616
Posts: 49433
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Muskego WI
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Be nice to nerds... Chances are, you'll end up working for one. -Bill Gates
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: March 17, 2013, 11:53:24 am by MaxKulik » Logged

Muskego WI
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Be nice to nerds... Chances are, you'll end up working for one. -Bill Gates
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
#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.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 101
Posts: 3644
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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"?
« Last Edit: March 17, 2013, 02:21:02 pm by HazardsMind » Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Muskego WI
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Be nice to nerds... Chances are, you'll end up working for one. -Bill Gates
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

**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.
« Last Edit: March 17, 2013, 02:24:22 pm by MaxKulik » Logged

Muskego WI
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Be nice to nerds... Chances are, you'll end up working for one. -Bill Gates
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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".
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 101
Posts: 3644
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok so, when you install those pull down resistors, everything will work fine.
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Muskego WI
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Be nice to nerds... Chances are, you'll end up working for one. -Bill Gates
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Could I use some 10K Ohm resistors?
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 101
Posts: 3644
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Muskego WI
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Be nice to nerds... Chances are, you'll end up working for one. -Bill Gates
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 101
Posts: 3644
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You should use a 9V rechargeable battery pack like the ones used in RC cars.
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Pages: 1 2 [3] 4   Go Up
Jump to: