Pages: [1]   Go Down
Author Topic: How to get Arduino to sense if a transformer is switched on.  (Read 814 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Edison Member
*
Karma: 32
Posts: 1288
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. smiley-sad  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.
Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1016
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


* photo.JPG (365.79 KB, 1632x1224 - viewed 11 times.)
Logged

Germany
Offline Offline
Faraday Member
**
Karma: 56
Posts: 2983
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


* 12to5VZener.PNG (4.28 KB, 377x189 - viewed 11 times.)

* 12to5VResistor.PNG (5.46 KB, 461x193 - viewed 11 times.)
« Last Edit: May 08, 2012, 06:36:05 am by michael_x » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Many thanks,
Mark
Logged

Canada
Offline Offline
Full Member
***
Karma: 0
Posts: 246
Code Monkey
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I yield() for co-routines.

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5144
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley

Thanks,
Mark
Logged

Pages: [1]   Go Up
Jump to: