Go Down

Topic: How to get Arduino to sense if a transformer is switched on. (Read 934 times) previous topic - next topic

mkobine

Hi,

I have built a domestic wall light that uses an Arduino Uno to control a servo that creates motion in some parts of the light. However I need to "pause" the Arduino when the light is switched off. I have mains electricity (220v) coming in and a transformer which steps this down to 12v DC 350-700mA. This transformer is used to power a bunch of LEDs. The Arduino is currently powered by a 9v PP3 battery.

Can I "sense" if the transformer is on and so stop the servo? I reckon the software is trivial if I can somehow figure out the electronics. Can anyone point me in the right direction?

I don't have an electronics background but have been able to build basic circuits from the various Arduino books.

Many thanks,
Mark

DVDdoug

I assume you know how to detect a high/low input in your sketch...   

You've got  one simple issue do deal with...   You can't put 12V into the Arduino.   You just need to drop that 12V down to 5V at the Arduino input (without affecting the other stuff that's connected to 12V).

If your "transformer" is putting-out DC, it's actually more than a transformer, and that's good, since you can't put AC (or negative voltage) into the Arduino.

I'm going to describe this in words because I although I've been working in electronics for a long time, I don't have any schematic-drawing software. :(  I'm gonna' have to get 'round to that...)

Put a resistor (~10k would be good) between the 12V from the transformer and one of the Arduino's inputs.   Then connect a diode between the same input and the Arduino's regulated 5V power supply (i.e. the "5V" pin), with the anode on the input (i.e. "point" the diode toward the 5V supply).    Any regular silicon diode will work, since there is very little current through the 10k resistor.

Whenever the voltage goes above 5V (plus the ~1/2V drop across the diode), the diode "turns on" and "clamps" the voltage at 5V (plus the diode drop).   The "remaining" ~7V gets dropped across the resistor.

Krodal

I would use an optocoupler. The DC from the transformer with a resistor to an optocoupler, and the output of the optocoupler directly to an input pin of the Arduino (with internal pull-up resistor).

mkobine

Thanks guys!

Krodal - a optocoupler sounds interesting but I'm not sure it'll work in my light.

DVDdoug - I think I understand the circuit you've described. Let me describe it back to test my understanding.

I take the 12v +ve output from my transformer (it's a Dialight MDU-18) and feed it in to a 10k resistor. That resistor is then used as an input to my Arduino. Which input pin should I use? Sorry, I think I should be using a digital pin but I'm not sure. I've drawn this circuit and attached an image of the diagram.

I've written a few sketches (by modifying existing ones) but never detected High / Low before. I've done some research and think I may want something like this -

#define IN_PIN x

void setup()
{
   pinMode(IN_PIN, INPUT);
}

void loop()
{
   int val = digitalRead(IN_PIN);
   
   if (val == HIGH)
   {
      // The light is on so do stuff!
   }
   
   delay(1000);
}

Does this look right?

Many thanks,
Mark

michael_x

#4
May 08, 2012, 01:31 pm Last Edit: May 08, 2012, 01:36 pm by michael_x Reason: 1

Put a resistor (~10k would be good) between the 12V from the transformer and one of the Arduino's inputs.   Then connect a diode between the same input and the Arduino's regulated 5V power supply (i.e. the "5V" pin), with the anode on the input (i.e. "point" the diode toward the 5V supply).    Any regular silicon diode will work, since there is very little current through the 10k resistor.

Whenever the voltage goes above 5V (plus the ~1/2V drop across the diode), the diode "turns on" and "clamps" the voltage at 5V (plus the diode drop).   The "remaining" ~7V gets dropped across the resistor.


What definitely is missing is the connection from the 0V pin of your 12V source to Arduino GND.

Not sure if it's a good idea to sink those probably noisy 12V into the 5V ? But if your Arduino is not doing anything else, why not...

A 4.8V zener diode to GND, or a 4.7k resistor to make a voltage divider 2-1 = around 4V at the digital pin, might be more suitable.

Any digital input (except 0 and 1 for Serial) should be fine.


BTW.
Quote
I don't have any schematic-drawing software.  I'm gonna' have to get 'round to that...)

google for LTSpice freeware.

mkobine

Thanks michael_x! That worked a treat. I used the version with the diode and it's perfect!

Many thanks,
Mark

The Clever Monkey


Can I "sense" if the transformer is on and so stop the servo? I reckon the software is trivial if I can somehow figure out the electronics. Can anyone point me in the right direction?


One approach is to use a reed switch as a sensor. If there is current running through the transformer, it will create an electromagnetic field that should trip a reed switch.
I yield() for co-routines.

pylon

Why not simply power the Arduino from the 10V DC you get? OK, you loose about 1-2 seconds for boot but for driving a servo it might be fast enough.

mkobine

Thanks pylon - that's ideally what I'd like to do. I tried powering my Uno from the transformer via the jack socket but it didn't seem to like it. The transformer was supplying 12v DC and 350-700mA but I have no idea if this is too much or too little. I didn't get any lights on the board. It still works fine so at least I didn't fry it  :)

Thanks,
Mark

Go Up