Using Relays with LilyPad Arduino

lilypad_messrelayUsing the Arduino Diecimila, the microphone breakout board, and a relay switch, I’m able to send voltage to flexinol when I yell into the microphone. I used the Arduino Diecimilia because I’m more familiar with it and I have a ‘back up’ arduino just in case I fry one. After figuring out the code and wiring, I moved on to hook this up to an Arduino LilyPad so the components can be sewn into a garment. I found out that my switches will not work with the LilyPad. I was using a reed relay switch and later picked up another relay (shown here) hoping that (for some reason) this one might work since the other was not. I think this 1 Amp 5VDC relay is not compatible because of the amperage. I’m able to flip the switch with a 1.5volt battery so the voltage was not the issue (the LilyPad registered 3.1 volts through a digital pin). However, the LilyPad is 40mA and the switch is 1A – so now I’m searching for a 40mA 5VDC relay switch. Hopefully, that will allow me to move on to sewing the components into a garment.

The code:

inline void digitalPullup(byte pin, boolean b) {  pinMode(pin, INPUT);  digitalWrite(pin, b?HIGH:LOW); }
#if defined(__AVR_ATmega1280__)
inline void analogPullup(byte pin, boolean b) { digitalPullup(pin+54,b); }
#else
inline void analogPullup(byte pin, boolean b) { digitalPullup(pin+14,b); }
#endif

long energy =0;
long v;
int red = 10;      // select the pin for the LED or Flexinol

void setup() {
Serial.begin(9600);
pinMode(red, OUTPUT);

analogPullup(0, true); // enable the 20kOhm pull-up on analog pin 0
}

void loop() {

// read the analog input into a variable:
int analogValue = analogRead(0);
// print the result:
Serial.println(analogValue);

if(analogValue > 700)
{ digitalWrite(red, HIGH);
delay (200);
} else {
digitalWrite(red, LOW);
}
if(analogValue < 450)
{ digitalWrite (red, HIGH);
delay (200);
} else {
digitalWrite(red, LOW);
}

v = analogRead(0) -512;
energy += v*v;
delay(10);
v = analogRead(0);
energy += v*v;
delay(10);v = analogRead(0) -512;
energy += v*v;
delay(10);v = analogRead(0) -512;
energy += v*v;
delay(10);v = analogRead(0) -512;
energy += v*v;
delay(10);v = analogRead(0) -512;
energy += v*v;
delay(10);v = analogRead(0) -512;
energy += v*v;
delay(10);v = analogRead(0) -512;
energy += v*v;
delay(10);
energy /= 64;
}

Special thanks to Mr. Adrian Freed for his help at the Center for New Music and Audio Technology at UC Berkeley.

Advertisements

One thought on “Using Relays with LilyPad Arduino

  1. 1 amp is a lot to drive a relay, probably the rating for what it can control. just google “arduino relay”, there are many examples, driving a 5v relay should only need a transistor, A diode, and a resistor if using a 5v arduino, otherwise add a 5v power supply. When you say you flipped the switch with a 1.5v battery, did you test the contacts or just hear a noise? when I tried to switch my 12v relay at 9v and 5v, I heard a noise but the contacts did not change. If your application is low enough current, a transistor might do.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s