SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By MICyborg
#176239
I realy was looking all over the net but i cant find anything about relays used with a lilypad mp3.

its about a littel fun phone experiment.
there is this bell and a electromagnet to ring it by hammering a small stick against it.
its working with 8 AA(1,5V) batteries, seriell. i also can work the relay by using another 4 batterys already but thats it. if you takte the phone off during the ringing you should hear a audiofile playing and it should ring randomly all 10 to 50 minutes for 10 ringing periods of 6 seconds. thats the project.


i allready found out a lot of other stuff but i cant find a description how to use a FRS1B-S DC5V 1A/125VAC relay with the lilypad mp3.

how can i connect it to the board and how should i call it in the code to tell that it needs to be activated at least 5 times a second. so the bell can ring properly.. i am open to all suggestions but i need to get it done till monday the 26. :-|

i would be very happy if anybody knows ansers.
By Mee_n_Mac
#176266
You can't drive the relay coil directly from the LP because the coil resistance is only 56 ohms and so will draw too much current from the LP pin. You need a "driver" of some sort and the simplest would be a transistor (2N2222a) and a "flyback" diode (1N4001-1N4004) as shown below. Make R1 somewhere between 700 and 1000 ohms.
Image
By MICyborg
#176292
Thanks a lot for now :-)

i think i can read this plan.. just to be shure.
R1 is an resistor. so i should buy a pullup resistor with 1k Ohms?

The Gnd on the right side is the batteryblock that gnd and the 5V comes also from the batteryblock. (if thats right.whats if i got 12V there because of my 8AA Batterypack with each 1,5V, there is no problem to use that instad, am i right??)

So after the RL1 at the right end this is just the sign for the output of the relay to the bell +pol.. the mass for the bell i have to take from the battery... or am i gettin it wrong ??? sorry for that stupid questioning but i am learning and i am very thankful for your help.
By MICyborg
#176295
!!!Or no no no!!!...i got it now.

the 5 V Batteryblock i should have is for the trigger electricity of the relay. SO the right Gnd on the plan is the negativ pole of that Batteryblock and the 5V is also going to that Battery positiv pole.. So the 12V Batterypack that gona be triggered through the relay is not on the Plan.. This is going through the section after the RL1 at the right middle side of the plan.

Thats it or not???

and the other thing i am not shure right now is still the Resistor.
i get 3,3V and 0,04 A from the Digitalpin and i need, lets say 800Ohms?

do i need to calculate this and how? or should i just take a 1k resistor?
By Mee_n_Mac
#176324
MICyborg wrote:!!!Or no no no!!!...i got it now.

the 5 V Batteryblock i should have is for the trigger electricity of the relay. SO the right Gnd on the plan is the negativ pole of that Batteryblock and the 5V is also going to that Battery positiv pole.. So the 12V Batterypack that gona be triggered through the relay is not on the Plan.. This is going through the section after the RL1 at the right middle side of the plan.

Thats it or not???
I think that's it. The 4 AA battery pack outputs ~5V on it's + terminal. The - terminal should be connected to the LP ground and to the 12V battery pack (8 AA) - terminal. The + terminal of the relay coil should be connected to the + terminal of the ~5V battery pack. The - terminal of the relay coil goes to the transistor's collector pin. The emitter pin goes to Arduino ground. The base is connect through the resistor to the Arduino output pin.
MICyborg wrote:and the other thing i am not shure right now is still the Resistor.
i get 3,3V and 0,04 A from the Digitalpin and i need, lets say 800Ohms?
do i need to calculate this and how? or should i just take a 1k resistor?
The resistor value is not that critical but if you want to calculate it, here you go:
Take the current you think will go through the transistor, collector to emitter. That's the current through the relay coil, which will have about 5V across it (when the transistor switched on) with a resistance of 56 ohms. Per Ohms law (Google it) that's a current of 5/56 = 0.089 A. Let's be conservative and call it 100 mA. The transistor has a current gain spec/number which tells you how much current can flow from collector (C) to emitter (E) given the current flowing from base (B) to emitter. That number is often = 100 but people use (again, a conservative number) of 25 when switching w/a transistor. So to get 100 mA flowing C->E, you need 100/25 = 4 mA flowing B->E. If you have 3.3V on the Arduino output pin** and given that the base acts like a common diode, dropping 0.65V with almost any current flowing B->E, you then have (3.3V - 0.65V) across the R1 resistor and that voltage should make at least 4 mA flow. Again via Ohms law, the resistance needed is (3.3V - 0.65V)/0.004A = 662 ohms. Given how conservative we've been, even larger values would still work. Use any resistor you have btw 600 and 800 ohms.

**my original calculations above were for a 5V Arduino pin, hence the higher resistance value in my post above. But the immediately above numbers are better for a 3.3V LP pin.

Depending on how much current your 12V device (ringer/bell) draws, you might be able to simplify your circuit even more and get rid of the relay and 4AA battery pack. You might be able to "drive" your ringer directly from the transistor, if it draws < 0.4A. R1 might need to be lower, depend on how much current the ringer/bell takes.
arduinorelay.jpg
You do not have the required permissions to view the files attached to this post.
By MICyborg
#176614
finaly i got all components set up like without a relay like the second idea of you.
so the programming of this device is also new to me and i cant find a good example or tutorial for my needs.

Its about to let the ringer ring so i need the code for transform the digital pin (lets say pin3) of the arduino into an output(thats easy)but then i need the code to tell the arduino to just put out the 3.3V just for 50 milliseconds then 50 ms no output than 50 ms output again and that for 50 seconds. he should do this process randomly every 5 to 60 minutes.
than...if you trigger another digital pin (lets say pin4) during this randomly executed process of 50 seconds ringing he should play one out of 10 different audiofiles.
thats it..
i should know how to do the rest (if you trigger pin4 during no ringing it should play 1 soundfile automaticaly) for my self.

This seems to be easy if you know the basics but i dont know how i can learn this. Maybe anybody can help me writing this or give me some links or other sources of good knowledge about my codingproblem :-)

thanks in advance
By Mee_n_Mac
#176629
I have no idea what your coding background is but you should be able to read a pin and determine if a button/switch has been pushed ...
http://arduino.cc/en/Tutorial/InputPullupSerial
Beyond that activating the ringer is a lot like blinking an LED but faster ...
http://arduino.cc/en/Tutorial/Blink
... but imagine the delay between on and off is shorter and the on/off process repeats ...
Code: Select all
for(x = 0; x < numRings; x++){
  digitalWrite(ringerPin, HIGH);   // turn the solenoid on (HIGH is the voltage level)
  delay(50);                           // wait for 50 msec
  digitalWrite(ringerPin, LOW);    // turn the solenoid off by making the voltage LOW
  delay(50);                          // wait for 50 msec
}
You should look over these pages if you're really a newbie to this all ...
http://arduino.cc/en/Guide/Environment
http://arduino.cc/en/Tutorial/Foundations
http://arduino.cc/en/Reference/HomePage
http://arduino.cc/en/Reference/For
http://arduino.cc/en/Reference/If
http://arduino.cc/en/Reference/Random
http://arduino.cc/en/Reference/Millis
By MICyborg
#176663
i am geting in to the coding stuff but i got a problem that is not logical to me.

if i use this code the ringer just does one ringprocess with a delay of 1 second aproximatly.
this means i got an output thats on for 1 sec.
if i use another pin it doesnt turn off again. it just stays on.
what the hack am i doin wrong?
Code: Select all
const int ringerPin = 4;

void setup(){
pinMode(ringerPin, OUTPUT);
}

void loop()
{
for(int x = 0; x < 500; x++){
  digitalWrite(ringerPin, HIGH);   // turn the solenoid on (HIGH is the voltage level)
  delay(50);                           // wait for 50 msec
  digitalWrite(ringerPin, LOW);    // turn the solenoid off by making the voltage LOW
  delay(50);                          // wait for 50 msec
}
}
:think:
By Mee_n_Mac
#176664
The code in loop() ... loops, over and over until a reset or power off. So when the for() loop runs it's 500 iterations, the loop() starts again and the for() loop runs another 500 times and then the whole process repeats ... over and over.

If the 50 msec on, 50 msec off cycle for the solenoid actually "rings" (once), then the above code should ring continuously. If you want to, experiment and put a delay(5000); at the bottom of the loop().

BTW 50 msec on, 50 msec off is a cycle of 0.1 secs and repeating that 500 times means a single for() loop above runs for ~ 50 secs, not 1 sec.
By MICyborg
#176675
i tryed a lot of different setings.

pin4 always does the same. it turns on for 1 sec and then off again.
The other pins are just turning on without turning off again.

but i also testet the mp3 player sketch that is working with all pins like it should :-|

maybe its possible if it works inside the trigger sketch. i dont know where to put it there.

phew ... this is strange

:?: :?: :?:
By Mee_n_Mac
#176679
How are measuring pin 4 ? Is this w/ or w/o the FTDI programming cable attached ?

From the schematic, sew tap (pin) 4 is shared w/the FTDI and MP3 decoder. Maybe it would be wise to use a different pin ? That said, I'm not sure what pins are unused. Pins 2, 3 are the I2C link to the speaker amp. I don't know if that's used when playing. Pins 4, 5 are for the serial communication w/the FTDI, w/pin 4 sending MIDI data (per the signal name) to the decoder. Pin 1 seems to be the only unshared pin.

All the other pins don't go to digital I/O.

http://dlnmh9ip6v2uc.cloudfront.net/dat ... 3-v15a.pdf
By MICyborg
#176684
OK... its still strange, but its workin now :-)

i use pin 1 but the output is at pin 4 working now :-D
Code: Select all
const int ringerPin = 1;

void setup(){
pinMode(ringerPin, OUTPUT);
}

void loop()
{
for(int x = 0; x < 500; x++){
  digitalWrite(ringerPin, HIGH);   // turn the solenoid on (HIGH is the voltage level)
  delay(50);                           // wait for 50 msec
  digitalWrite(ringerPin, LOW);    // turn the solenoid off by making the voltage LOW
  delay(60);                          // wait for 50 msec
}
}
i dont know how to use the pin numbers now in the next coding steps.

i will begin with try and error.

thank you again for your help.
By Mee_n_Mac
#176694
Kewl. Can you better explain the concept here ...
if you takte the phone off during the ringing you should hear a audiofile playing and it should ring randomly all 10 to 50 minutes for 10 ringing periods of 6 seconds. thats the project.
The phone rings for 6 secs at a time, unless answered ? If answered then it plays some audiofile (?random?) ? If not answered, it stops ringing after 6 secs and then waits some (?random?) time until it starts ringing again ? This goes on for up to 50 mins (or 10 times ?) after turned on and then ????
By MICyborg
#176702
Ok, first anser about the trigger control..last posting. it was very easy. i looked at the trigger sketch example and found the right name for the different pins. here they are:
const int TRIG1 = A0;
const int TRIG2 = A4;
const int TRIG3 = A5;
const int TRIG4 = 1;
const int TRIG5 = 0;
:idea:

so i use A0 in my code now and the first pin is working :-)
Code: Select all
const int ringerPin = A0;
const int offhook = A4;
const int onhook = A5;

void setup(){
pinMode(ringerPin, OUTPUT);
pinMode(offhook, INPUT);
pinMode(onhook, INPUT);
}

//i need it to do the next loop for 20 seconds. every 5 to 60 minutes randomly choosen. 
//if you pick it up the offhook trigger will be triggert but only if it is doing that loop here it should play one of 10 audiofiles randomly choosen,
//i guess this will be the hardest part for me. (it must not ring as long as you got the phone picked up.)
//u put the phone down (hookon will be triggered) and it turns off the soundfile that is playing.
//if you pick up the phone when it is not ringing it plays a special audiofile (the openline tone).
//the hole thing has no end.only if you turn the lily pad off or akku is empty.

void loop()
{
for(int x = 0; x < 15; x++){
  digitalWrite(ringerPin, HIGH);   // turn the solenoid on (HIGH is the voltage level)
  delay(50);                           // wait for 50 msec
  digitalWrite(ringerPin, LOW);    // turn the solenoid off by making the voltage LOW
  delay(80);                          // wait for 50 msec
}
delay(2500);
}
so i am about geting the random process runing and after that i need the different status of the phone, if it is picked up, if it is ringing, as in the code useable statements to build the last function i guess.

Lets see. i already have learned a lot with this art project ... but still i am :mrgreen: