Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: xBee: duplicate response on: April 26, 2012, 12:36:12 pm
Lol thanks for trying. It really is a mess! Luckily my problem is already solved. I think it was a case of not knowing how to use the relay. My relay is being powered by the arduino on 3.3v (as this is the voltage that my xBees work at). It came with a beginner kit from oomlaut.com and this is what the accompanying tutorial instructed. There was no schematic or power information provided so i was kind of guessing.

This is the basic circuit i was working with http://www.oomlout.com/oom.php/products/ardx/circ-11 i am using the same relay and transistor.

I've had to adapt it to work with my mp3 player. The way i've wired it up now makes no sense according to the diagram but it works reliably so i'm quite happy with it.

Cheers!
2  Using Arduino / Programming Questions / Re: xBee: duplicate response on: April 26, 2012, 11:21:20 am
I read somewhere that things connected to the relay had to share a common ground with the arduino (and its been in the online tutorials/projects that ive been referring to). I just thought 'hang on a second....what if...' and I put the yellow wire on the opposite side of the relay (parallel to the orange wire) and now it works perfectly. As far as i can tell its not connected to ground. This projects slowly driving me crazy! Siobhan
3  Using Arduino / Programming Questions / Re: xBee: duplicate response on: April 26, 2012, 11:07:08 am
Hey,

This is a fritzing diagram and a schematic of my circuit:




Note: I have put a speaker instead of the hacked MP3 player in the circuit. What i've done is a crude override of the on/off switch using  a relay to turn it on/off remotely. I have only included the board with the relay on it.

The mp3 player is from amazon: http://www.amazon.co.uk/gp/product/B004UYTA08/ref=wms_ohs_product and powering it on and off with a relay. It has its own power supply. I would post the mp3 power details but they're unknown to me. I've tried a few different ways of doing this remote control hack, but it is now proving temperamental. Today i've gone to re-test the circuit and its not working properly. I do think it is interfering with the power source as you mentioned before. It wont stop once its started playing now for some reason.

Thanks,

Siobhan
4  Using Arduino / Programming Questions / Re: xBee: duplicate response on: April 21, 2012, 11:07:37 am
Update:

The system now works perfectly with the 560ohm resistor. Seems a bit temperamental though so I'll test a few times in the next 24hours before celebrating  smiley-grin
5  Using Arduino / Programming Questions / Re: xBee: duplicate response on: April 21, 2012, 10:47:29 am
Thanks so much for your answers. They really helped!

I've made the changes that you suggested, Jack. I also stripped down the code of any unnecessary lines as Paul Suggested

This fixed my problem completely when I had an LED in place with the relay.  However, when I was using a new component with the relay, it went back to repeating itself.

I then tried using a 560ohm resistor, which stopped the repetition, but didn't quite provide enough current for the new component (enough to indicate that it was on, but not enough to make it work). I am going to pick up a couple of lower value resistors, swap them in and pick the one that stops the repetition but provides enough current for the new component. I note that the component wouldn't work with a higher value resistor. Also, the repetition I'm experiencing only happens with relays; putting something else in the circuit doesn't have the same result.

It seems odd to me that this would make any difference!

It would be interesting to know why for future reference. It seems bizarre to me that the resistance within the relay circuit would cause it to turn on and off twice and also register a false 'D'.
6  Using Arduino / Programming Questions / Re: Temperature controlled fan using Arduino on: April 21, 2012, 04:35:23 am
My advice would be to either:

1. use PWM (pulse width modulation). http://arduino.cc/it/Tutorial/PWM This is my preferred method, and the most simple to implement.
2. the fan should have more than one speed setting. If it does, hack the fan by overriding the switches for these speed settings (you'll need to take some or all of the housing apart), and connect relays to these. When it is cold in the room, turn the fan off. When it is  cool, turn the fan to slow. When it is hot, turn the fan on full blast.
3. build your own fan using a motor, then control the motor speed.

This is a similar topic to yours with responses  http://arduino.cc/forum/index.php?topic=101952.0
7  Using Arduino / Programming Questions / Re: Coding Using Time intervals help on: April 21, 2012, 04:24:03 am
Seems like quite a big project to start with.

My advice would be to start by developing code to control the motors to start with, possibly using up/down and left/right controls. This will teach you how to manipulate the motors whilst you're doing it as well as working out timings. Here is a tutorial for a car http://arduinoarts.com/2011/08/arduino-tutorial-f1-rc-car-dc-motor-driven-by-mos-transistor/ here is a basic motor tutorial. http://www.oomlout.com/oom.php/products/ardx/circ-03 it includes wiring, explanations and a breadboard layout.

Then incorporate sensors to control the motors. I'm not sure what kind of avoiding action you want, but you can probably use just a few photoresistors to do the job in a very basic way i.e. stopping, reversing/turning, then repeating this if the obstacle is still in the way and continuing if not.

P.s. I'm not sure why you're using led's and havent wired up a motor yet. If you are a complete beginner, work through these tutorials before doign anything else (its how i was taught basic arduino at uni this year) http://www.oomlout.com/a/products/ardx/ youll just waste time trying to do something too hard.

Example pseudocode once you know how to control the motor:

go forwards
if (sensor says there is an obstacle in the way), stop
reverse motor
turn car (using two motors-one going left and one staying straight/going right)
stop car a few inches back
go forward in a straight line until more obstacles are met
repeat avoiding code

this is just one way to do it if you have say two sensors at the front.

good luck!
8  Using Arduino / Programming Questions / Re: xBee: duplicate response on: April 21, 2012, 03:24:56 am
Ok, the full code is below

Button xBee

Code:
#define VERSION "1.00a0"
int BELL= 11;
int localINDICATOR= 7;
int BUTTON = 2;

void setup() {
  pinMode(BUTTON, INPUT);
    pinMode(BELL, OUTPUT);
 pinMode(localINDICATOR, OUTPUT);
  Serial.begin(9600);
}

void loop() {
 //      digitalWrite(BELL, HIGH);
char s2 = Serial.read();   
digitalWrite(localINDICATOR, LOW);
digitalWrite(BELL, LOW);
  // send a capital D over the serial port if the button is pressed
 
  if (digitalRead(BUTTON) == LOW) {
    Serial.print('D');
    delay(1000); // prevents overwhelming the serial port i increased the delay
digitalWrite(localINDICATOR, HIGH);

}
   //        digitalWrite(BELL, HIGH);

  if (Serial.available() > 0) {
 //   Serial.print(s2);
    if (Serial.read() == 'K'){
      //ring the bell briefly
         //  Serial.print('k');
     digitalWrite(localINDICATOR, HIGH);
     delay(10); 
    }
    if (Serial.read() == 'H'){
      //ring the bell briefly
     digitalWrite(BELL, HIGH);
     delay(10);
//      Serial.print('k'); response code - develop later
    }
  }
}

relay xBee

Code:
//this is the device with the relay on it

int globalset = 1;
int indicatorVar = 0;
int timerVar =0; //i was using these three as external variables

int buttonState = 0;         // variable for reading the pushbutton status
#define VERSION "1.01"
int REMOTEINDICATOR = 8;
int BELL = 5;
char val;
int lightsetting = 400;
//int BUTTON = 6;
int relay = 2;

void setup() {
  pinMode(BELL, OUTPUT);
    pinMode(REMOTEINDICATOR, OUTPUT);
  Serial.begin(9600);
  pinMode(relay, OUTPUT);     
}

void loop() {

 //  digitalWrite(relay, LOW);   // set the relay OFF
  if (Serial.available() > 0) {

val=Serial.read();   
        if (val == 'h'){
        }
       
    if (val == 'D'){
  //    Serial.print('K');
  //    timerVar = 1;     
      digitalWrite(relay, HIGH);
  delay(5000);
    digitalWrite(relay, LOW);
    delay(1000); 
    }
 }
};

Cheers, Maraesa
9  Using Arduino / Programming Questions / xBee: duplicate response on: April 20, 2012, 05:42:24 pm
I have a project with two xBees on two boards. On one board there is a button, which will turn a relay connected to a light on the other  board for 5 seconds, then off (with a 1 second delay). It is doing this by sending a letter 'd' over the serial port, and then the other xBee executes the relay code in response to it.

Problem: What is going wrong is that the relay is turning on/off twice, rather than just once.

My actions so far: I have added debounce code for the button, and have looked at the serial monitor of the xBee that is sending the 'd' and it is only sending it once. However, when i look at the serial monitor of the relay-connected xBee, it responds twice for reasons beyond my comprehension. I have also tried a switch statement with a break with no joy. I have also tried utilising external variables to trigger the relay response, but they were even more problematic.

Below are snippets of my code.

button xBee
Code:
if (buttonState == LOW) {
    delay(100);
    Serial.print('D');
    delay(5000); // prevents overwhelming the serial port & increased the delay
digitalWrite(localINDICATOR, HIGH);
}


relay xBee

Code:
if (val == 'D'){
       digitalWrite(relay, HIGH);
  delay(5000);
    digitalWrite(relay, LOW);
    delay(1000);
 
    }

I'd really appreciate any help with this!

Note: Removing the relay entirely isn't an option for me as i need it to switch a larger load than the LED that is is currently being debugged with.

Cheers, Maraesa
10  Using Arduino / Networking, Protocols, and Devices / Re: xBee to Arduino small code problem on: February 19, 2012, 10:54:36 am
Thanks for your help. Will now close this topic smiley
11  Using Arduino / Networking, Protocols, and Devices / Re: xBee to Arduino small code problem on: February 19, 2012, 10:54:08 am
Hiya yes i'd figured that out lol
12  Using Arduino / Networking, Protocols, and Devices / Re: xBee to Arduino small code problem on: February 19, 2012, 09:50:58 am
Hey everyone!

Seems I managed to fix the problem myself by looking at this post and incorporating the responses http://arduino.cc/forum/index.php/topic,91707.0.html

I declared a variable at the top: 'char val';

And then rather than putting 'Serial.read()' into my if loop, i instead placed the serial value into the 'val' variable, and inserted 'val' into the if loop.

My new code looks like this

char val;

if (Serial.available() > 0) {
val=Serial.read();
    if (val == 'D'){
      //ring the bell briefly
      digitalWrite(BELL, HIGH);
      delay(10);
      digitalWrite(BELL, LOW);
      // uncomment the next line if you don't have an oscillating buzzer
      //tone(BELL, 440, 100);
    }

if (val == 'H'){
     Serial.print(Serial.read());
    }
  }

It's still coming up with '-1's in the serial window rather than actual words but it's a start smiley If anyone can explain why thats happening, please let me know.

Thanks,

Maraesa
13  Using Arduino / Networking, Protocols, and Devices / xBee to Arduino small code problem on: February 19, 2012, 09:34:51 am
Hi,

I'm adapting the basic xBee doorbell project from 'Building wireless sensor networks' by Robert Faludi which involves two xbees and two arduino boards. I'm having some arduino code problems.

What I want the system to do is turn on a light based on the value from the LDR sensor OR print out a message when a button is pressed. At the moment the best I can do is have both sensors triggering the same action (flashing LED). I have tried to make them trigger seperate actions by using the code below, but it doesn't work.

Code on arduino1:

 if(photocellReading<lightsetting) {
           Serial.print('D');
           delay(100); //prevents port being overwhelmed
        }
  if (digitalRead(BUTTON) == LOW) {
    Serial.print('H');
    delay(100); // prevents overwhelming the serial port i increased the delay
  }

Code on receiving arduino2:

if (Serial.available() > 0) {
    if (Serial.read() == 'D'){
      digitalWrite(BELL, HIGH);
      delay(10);
      digitalWrite(BELL, LOW);
    }

else if (Serial.read() == 'H'){
     Serial.print("hey");
    }
  }

I've just started using xbees, and have looked around online but i cant understand why the code  'if (Serial.read() == 'H' || 'D')'   responds to both the LDR and push button but when i try to seperate them it only listens to one of them.

I would really appreciate any help on this!

Thanks!

Maraesa
Pages: [1]