Saturday 21 April 2012

Version 3 Development: Fixed Relay Function

I posted a question to the arduino forums for help

http://arduino.cc/forum/index.php/topic,102291.0.html

I got two responses from two members
1. move the indicator light code to the top
2. To 'clean up' my code of any unnecessary function calls

Note: I had to tweak the code so that the LED was normally off rather than normally on.

This fixed the relay whilst it was connected to an LED. However when i put my hacked MP3 ino the circuit, the duplication re-occurred. I noticed that with the LED there was a resistor in series with it, so i added a low-value 560ohm resistor back into the circuit (as to not stop the MP3 payer working entirely).

Partial Success! The MP3 player turned on only once! Then off again after 5 seconds

Pitfall: It did not allow quite enough current through to turn the MP3 on completely, only enough to turn the lights on it on. This means that it needs a very small resistor, so i will purchase a couple and try them to see which gets the desired result. I don't know exactly why this works as it suggests that it was a physical problem   rather than a coding one. I have reposted to the forum to see if i can get an explanation for this.

Below are snippets of my finished code

button xbee


if (digitalRead(BUTTON) == LOW) {
    digitalWrite(localINDICATOR, HIGH);
    Serial.print('D');
    delay(2000); // prevents overwhelming the serial port i increased the delay
}

relay xbee

added this line at the top to turn the relay off in its natural state :     digitalWrite(relay, HIGH); //TURN OFF


  digitalWrite(relay, LOW); //TURN ON
  delay(5000);
    digitalWrite(relay, HIGH); //TURN OFF
    delay(1000);

UPDATE: On a second tests the system seems to be working perfectly with a 560ohm resistor

Below: Video of the system working
In the video I am touching the wires together on one xBee (not visible in the video).


Below: new relay layout-note the extra resistor



No comments:

Post a Comment