Remote controlled Home water heater

So about a month ago, together with school, work, exams…I got the imp.
I bought it from sparkfun together with 2x16 lcd display, few other parts.
every now and then, i had a small amount of time to keep working on it.
Yesterday’s night and today’s morning I finally got the relays i was waiting for, and started building.

Image Hosted by

Image Hosted by

Image Hosted by

Image Hosted by

and as final result, sadly i have no cover to that old white box, so i just covered it with some tape…just for the next few days till i figure something out.
Image Hosted by

I used 2x SPST relays 220VAC@20A N.O, as i couldnt find DPST/DPDT, so i just wired it all in parallel.
pin 1 - used for serial comm. with the lcd
pin 5 - analog_out for controlling transistor
pin 8,9 - controlling led
pin 7 - DIGITAL_IN_PULLDOWN, for sensing if button was clicked.

a mistake i made, which i cant revert it now is that i attached the leds directly between digital_out & gnd, so its now at 3.3v, I hope its not a big disaster… please advice, if it is.

I made a small android app which allows the following:
turn on, turn off, turn on for X minutes, turn on in X time, turn on in X time for Y minutes

Now all that i have left is to import current status of imp when turning on the app…using some get features with agents, when it comes out.

LEDs without a resistor isn’t good as there’s no current limit. The green LED has a higher Vf and so will burn less current but the red LED could well get burnt out.

I would recommend disabling the LEDs in software until you add some resistors :slight_smile:

But doesnt the pin outputs only 4mA anyway?

No, they are not current limited. 4mA is all you should be taking from them, though.

Good to know. I will re-open the box in the weekend.
in the meanwhile… it suddenly went offline.
log is:
3/2/2013 8:35:26 PM: Time increment: 39, counter: 39 3/3/2013 4:13:11 AM: Power state: online=>offline

Should I do some regular wakeup every few minutes? any suggestions how to deal with it?

Reload the editor page and see if it actually went offline or just went down for a few seconds…

Its 5 hours ago, its offline

Nice Job!

You do need those resistors as Hugo stated.

You state that pin5 is used as analog out to control a transistor. What is that transistor controlling? are you modulating heating level? I assume not.

I wired the relays in such a way that the coil has one leg always attached to 5V supply
the other is attached to the transistor, and the transistor is wired to the ground.
i use analog out with values 0 or 0.3
about heat, i dont have tools for that, but according to the datasheet im far from max voltages Vce or Vbe (mine about 5v & 1v)
about the resistors, i know, thats very sad as i need to open everything again :-\

You should have a current limiting resistor from the imp pin to the transistor base (eg: 1k is likely fine), and a catch diode pointing “up” (cathode to 5v) in parallel with the relay coil, otherwise you are likely to blow the transistor up due to the inductive kick when you turn the coil off.

I see that your imp was not doing anything for a long period; there’s a known bug in the current release which means you need to run squirrel regularly otherwise things go wrong. You can do that by adding this code:

function watchdog() {
imp.wakeup(30*60, watchdog);

…then you should stay online just fine.

Hi Hugo, Good morning! :slight_smile:
I Do have a diode to protect the transistor. Im not sure its possible to see in 480p photo…but its there, hiding next to the voltage regulator.

About that bug, I added watchdog. works great…I saw this morning that its still up.

I didnt understand the first part, current limiting resistor…
Care to expand add a line or two about it?
At the moment its attached directly. What i thought of “protection” is adding a diode there, in case something happens to the transistor…so nothing will blow back to the board.

If you are using a real transistor (vs a FET) then Vbe (difference between the voltage on the base and the emitter) = ~0.7v.

This means, if you drive it high with an imp pin, the imp pin is effectively clamped down to 0.7v and will draw a lot of current (and heat up the transistor - it’s effectively a PN junction, ie a diode).

You put a resistor between the imp pin and the base to limit this current. Rather simplified, the current flowing from collector to emitter on a transistor is approximately hfe * current flowing from base to emitter. hfe is generally >100.

If you put a 1k resistor between the imp pin (at 3.3v) and the base (at 0.7v), it would be dropping 3.3-0.7=2.6v, and hence would be passing I=V/R=2.6/1000=2.6mA of current, which is within the imp’s design spec.

That means a relay that needs 260mA can be powered (100x2.6). If you wanted to power a lot more, you use a darlington pair, which is a transistor providing the base current for another transistor - effectively giving you a huge hfe.

…or you use a FET :slight_smile:

Hi Hugo,
I really dont know why I took BJT instead of nmos, even in univ., i remember nmos/pmos was easier :slight_smile:
anyway, I did took in mind that Vbe = 0.7v, so I use ANALOG_OUT with value 0.3, thats about 1v. but i dont have the current limiting, so i dont know actually what it draws from the imp.
even with v_pin5 = ~1v, do i need to put a resistor there?
I think its a good time to take my univ. notes and calc I_b, I just remember its relatively small comparing to I_c :>

A BJT transistor is perfect for this job (depending on the relay coil size) but you need the 1k resistor as Hugo stated. It is not correct to set the voltage levels - they just are what they are.

With that arrangement you can use digital out and your output pin will go to ~ 3.3V.

some small current will go through the base of the transistor allowing many times more current to flow through the other pins.

Does your relay have a power and voltage rating on it? or a Voltage and Current rating (for the coil, not for the contacts)?

its 5V coil, 230V relay capable of 20A N.O or 10A N.C (i work with N.O, of course)
at weekend i will add resistors for bjt & leds

Using analog out is… an interesting way to drive the base of a transistor. Yes, it will work and yes the current is limited (because the output impedance is about 5kohms in DAC mode) but it’s rather unconventional.

I’d still recommend the GPIO mode and resistor!

Thanks, will do it soon enough when I get home in a reasonable time from work :slight_smile:

Well, I did it last night.
Added 375Ohm resistor for the red led, 220Ohm for the green.
Added 1K resistor between pin5 and transistor’s base, now operating as DIGITAL_OUT with values 0,1 instead 0,0.3 before.
One sad thing to say is that I think the box is too small, and because of all the wires, something misbehaves with my button. when the box was open, it worked fine, but when it was closed sometimes the lcd screen didnt work properly, and then after many tryouts to sort the wires inside, its the button which doesnt work now :stuck_out_tongue:
So it was very late, and i was tired…so I just left it this way, and disabled it by software.
the whole point is internet-controlled, right? :))