0

I know that in DC circuits the colour code is often (but not always) that red is positive and black is negative.

On this AC mains wiring the wires are blue and brown. Does anyone know which is which? It's for a light bulb (image below.)

I wish to switch the bulb on and off using an Arduino controlled relay.

enter image description here

enter image description here

JRE
  • 67,678
  • 8
  • 104
  • 179
Mito
  • 409
  • 9
  • 3
    The light bulb is labelled 220-240V/50-60Hz so technically neither is positive or negative; the terminology is 'line' or 'hot' for the wire used as power input, and 'neutral' for the wire connected to the neutral bus bar in your breaker panel. That being said, where I'm from black or red is hot and white is neutral. Blue and brown are meaningless to me. (edit: though apparently the Australian standard is brown = hot, blue = neutral.) Short of cutting it open or at least pulling the wires apart (or asking the manufacturer), I'm not sure anyone here can answer this. – Matt S Jan 22 '23 at 18:12
  • 4
    They are AC wires and alternate between positive and negative. Don't try and mess with these because **they might cause electrocution**. – Andy aka Jan 22 '23 at 18:12
  • I want to hook it up to an **arduino relay** and I know it's best to plug in positive first, and remove negative last. So it doesn't matter which of the wires I plug in? – Mito Jan 22 '23 at 18:14
  • 5
    @Nitro you must have not read the two comments above. There's no positive or negative. – Marcus Müller Jan 22 '23 at 18:17
  • 1
    @MattS Here in Germany, blue/gray and brown/black are standard or at least very common. Brown is "phase" or line and blue is neutral. Polarity is less important here than (say) in the U.S. But there's **no guarantee** your particular device follows that convention! – TypeIA Jan 22 '23 at 18:17
  • 4
    If you want specific answers for connecting a relay to an Arduino, you'll need to post a specific question about that, including a schematic and all parts you intend to use. Note that working with mains voltage is **not recommended for amateurs**. Many monolithic devices exist that are designed to use Arduino logic-level control signals to switch a power bar; I highly recommend finding and buying such a device that has been thoroughly safety tested by an independent authority rather than trying to build your own. – Matt S Jan 22 '23 at 18:17
  • Ok, this is the exact tutorial I'm using: https://youtu.be/puNIT8veyWU . All parts are the same. An Arduino, a relay (mine has 2 channels, not 1), and the bulb itself. Is it safe? – Mito Jan 22 '23 at 18:24
  • 5
    `I know it's best to plug in positive first, and remove negative last. So it doesn't matter which of the wires I plug in?` If you think this irrelevant falsehood is true, then you should definitely not be mucking about with mains wiring. Please don't kill yourself and cause parents and siblings to grieve. – Neil_UK Jan 22 '23 at 18:25
  • 5
    If your "2 channel relay" does not have a CE or UL rating, you should not use it. The only safe devices to use in a project like this look [something like this.](https://www.exploringarduino.com/wp-content/uploads/2019/07/AC-Relay-768x576.jpg) – Matt S Jan 22 '23 at 18:33
  • Here's the link to the actual relay: https://www.mybotic.com.my/module/relay-module/2-channels-5v-relay-module . Is it safe? Also, what are CE and UL ratings? – Mito Jan 22 '23 at 18:35
  • The relay you linked leaves mains voltage terminals exposed to touch. – Matt S Jan 22 '23 at 18:43
  • 1
    There is **no overall world standard for wiring colors**. For DC, the "black = negative and red = positive" is a sorta-kinda "standard", but wires can be any color at all (and sometimes are). If you need to know, figure out what standard applies to you (or find the wiring diagram if it's inside a product) and go with that. – TimWescott Jan 22 '23 at 18:56
  • 2
    looks like a rodent chewed on the cable ... both conductors show damage to the insulation ... just replace the whole cable – jsotola Jan 22 '23 at 19:31
  • you can use a triac output optocoupler to switch the led on/off with an Arduino, many of them allow up to 400ma. – dandavis Jan 22 '23 at 23:35
  • The idea that the "hot" wire is the supply and the "neutral" isn't comes entirely from what happens when you touch each bus bar in turn. (Note: please do not actually do that to see for yourself.) – Matt S Jan 23 '23 at 04:28
  • Question improved and then closed and reopened. – Russell McMahon Jan 23 '23 at 12:30
  • 1
    This is an important enough question to leave open. I improved it somewhat and closed then reopened it. I've provide an answer with guidance re wiring colour standards and the dangers of using cheap relays. The use of cheap Asian sourced (usually) relay modules for mains switching is "a thing". We can maybe save one person buy saying 'dont do it' but many DO do it, and knowing the dangers and ways of using cheap solutions as safely as possible seems in order. – Russell McMahon Jan 23 '23 at 12:34
  • For interest, where are you located? – Russell McMahon Jan 24 '23 at 06:48
  • I’ll add that the socket shown is a fake CE marking (“China Export”), not an actual EU-compliant device. – hacktastical Jan 24 '23 at 17:17
  • @hacktastical CE --> Indeed. May be good quality. May not. In this case a Chinese made light bulb socket has a reasonably good chance [tm] of being safe and suitable for intended purpose. Avoiding Chinese products doesn't guarantee quality and observation of standards, but increases the probability. As I know you know. – Russell McMahon Jan 25 '23 at 01:22
  • I'm from Romania @RussellMcMahon . And thank you all for your information regarding the unsafe relay and the Chinese Bulb socket. I didn't know it was fake. Just to give some more information, I wouldn't have done this project if I didn't have some experience in electronics, though most of what I did were Arduinos with Lipos, Buck converters and, overall just DC. This is the first time I stepped into AC – Mito Jan 25 '23 at 19:48
  • It is not so much that it is fake. It that the Chinese CE mark is meaningless but leads some people to believe that it meets European CE requirements. In fact, it may meet them, but nobody has checked. || I certainly do not wish to encourage people to use dangerous products, but it's worth noting that many Asian products are 'safe enough". If you have a good idea about things electrical you can usually distinguish between "absolute junk. Lethally dangerous" and "probably ok, use due care. I have seen products in the former category in China. Some get exported but not a large percentage. – Russell McMahon Jan 26 '23 at 13:01

3 Answers3

14

tl;dr: this is an AC line voltage (230/240V) bulb, screwed into a socket. There’s no ‘positive’ or ‘negative’ but rather ‘hot’ and ‘neutral’. Being line voltage, it’s potentially dangerous to work with. Mating it to a Arduino is not recommended as a beginner project.

The socket wiring color code is as follows:

  • Brown is ‘hot’ (230/240V AC)
  • Blue is ‘neutral’ (nominally 0V, but don’t count on that, see below)

This color code is for 230/240V, following the IEC wiring standard for the EU:

enter image description here

From here: http://electronink.blogspot.com/2015_09_01_archive.html

The threaded lamp socket is called an Edison base. If the socket is wired correctly, the brown wire goes to the center contact, while the blue wire goes to the threads. Best practice is to switch the center terminal (brown wire), as this keeps the threads at neutral (assuming there isn't a hot/neutral swap somewhere else.) Even better, if your relay is two-pole, switch both hot and neutral for enhanced safety.

Which brings me to this. The socket shown bears a fake CE marking (“China Export”), not a real CE mark (Conformité Européenne). You can tell this because the ‘C’ and ‘E’ are too close together. More about that here: https://www.intouch-quality.com/blog/official-ce-logo-and-fake-laboratory-ce-certificate

This means that the socket and its wiring are not verified to be compliant with EU standards. This fake marking is all too common with things bought online. Nevertheless, because it isn't real CE mark it poses additional risk to you, the user, even before you start cutting into the wires.

Back to that cutting-wires risk. Since this is full line (AC) voltage, it is potentially lethal and requires extra care in handling it with a low-voltage system like an Arduino.

First, you'll need to use appropriate logic-controlled isolated switch to control it, such as a safety-approved relay, optical relay or similar device.

Second, this isolated switch needs to be connected and boxed in a way that will prevent any contact between the line and low voltage, or contact with line by people using it. The switch needs to be in an approved enclosure, using approved, correctly-sized wiring, and physically isolated from the Arduino (not in same box).

Finally, although neutral (blue) is nominally zero volts, never count on that. Plugs can be flipped, neutral could be faulty, and so forth. Treat the blue wire it as if it were full line voltage.

That all said, as @Matt S pointed out, better to find something like this for your first line-voltage appliance control project:

enter image description here

From https://www.exploringarduino.com/wp-content/uploads/2019/07/AC-Relay-768x576.jpg

MORE: I found a how-to for this switched outlet module here: https://www.makerprojectlab.com/reliable-relay-power-strip/

hacktastical
  • 49,832
  • 2
  • 47
  • 138
  • 1
    Good answer. Mine complements yours. I agree that using a "real" relay modules is desirable, but many will use the cheap modules. Knowing wat to look for and how to do it "half safely" seems in order. Maybe not? – Russell McMahon Jan 23 '23 at 12:36
  • 1
    It depends on the person doing the integrating. The nature of the question leans toward recommending a pre-made, enclosed relay solution vs. a bare module. – hacktastical Jan 23 '23 at 20:07
  • I've answered this same question in many places to many people. I assume it comes up here a lot as well. It's always the same answer, and it always gets the same six to ten "don't do it!" responses which as @Russell McMahon notes is probably not going to discourage someone anyway. Would this instead be useful as a a community wiki and combined with Russell's answer to provide a canonical reference? I don't really know how those work, but it might be a good idea to have a complete "how do I switch a mains load with a microcontroller" answer with well-written safety warnings ready to go. – Matt S Jan 24 '23 at 15:32
3

This answer overlaps existing ones.
I'm providing it as some of the other information may be incomplete. The answers and comments that tell you that you should ideally use a safe and certified product are correct!. I have provided information on how to identify cheap relay modules that are lethally dangerous and also ones that have made a reasonable attempt at safety. I've also noted some limitations of the "safer" ones.

One possibility is to use optical isolation at the relay board input, as some do - but this is effective only if care is taken to properly maintain input and relay and driver electronics and power supplies. Even then, the relay board may be destroyed, even if the microcontroller is not.


WARNING: DEATH IS A POSSIBILITY IF MAINS WIRING IS DONE WRONGLY.

In this case you should be safe enough with due care.
Treat both wires as live, but if switching only one wire, switch the brown one.

Note that the whole relay PCB and all the bulb wiring should be regarded as mains-live at all times that it is connected to mains. The relay board should be mounted in an enclosure where it cannot be touched when connected to mains. (The enclosure should either be adequately rugged plastic that cannot be opened 'casually' or an earthed metal enclosure with the PCB securely mounted on standoffs.

This may all sound like a lot of fuss over a minor circuit.
It is if you are not concerned about safety.
It's a bare minimum if you do not want to kill yourself or someone else.


If correctly wired brown is phase/live, and blue is neutral.
If wired incorrectly switching neutral will still turn the light on and off BUT the bulb wiring will all be live at all times.

Note that the Asian sourced relay modules which are stated to be mains rated DO work on mains but are only suitable for current far lower than the rated values. These may be shown as 10A but an amp or two is the advisable limit.

A light bulb is well within their capabilities.

Note that one switched contact on the relays is often located between the two relay coil pins. This means that mains AC is in close proximity to the low voltage wiring and Arduino connection. This arrangement is usually 'safe enough' but below the level of safety that you'd ideally have and in some cases may not meed regulatory requirements.

The wiring colours shown are correct for most of Europe, the UK , Argentina, South Africa and Australia & New zealand.
The last two use Standard AS/NZS3000:2007 3.8.3.
The others use Standard IEC 60446)

This page provides substantial details.

From the above page:

enter image description here


RELAY BOARDS PROBABLY SAFE versus DANGEROUS

This relay board has slots cut to provide isolation between mains voltage and low level control voltages. Red tracks are an AC mains potential.
Green pads are at low voltage and connect electricAlly to the microcontroller. enter image description here

A DIY PCB with inadequate mains to low voltage isolation.

enter image description here

WORSE ! - This does not LOOK like a DIY product, and might be assumed to be safe. At mains voltages it's lethal.

enter image description here


VERY WELL DONE:

This is a relay board supplied by seeedstudio.
The isolation slot extends across almost the whole board width.
The Songle relays are not of marvellous quality and cannot be trusted at full claimed ratings (ask me how I know :-) ) BUT they are unlikely to breach the high voltage to low voltage isolation barrier if they do fail.
Link provided by Mito

seeedstudio also provide a Arduino Relay Tutorial: Control High Voltage Devices with Relay Modules tutorial
and a
Types of Relay – Which One Should You Use? tutorial. enter image description here

Russell McMahon
  • 147,325
  • 18
  • 210
  • 386
  • Thank you for all the information! I didn't know this critical difference between "safe" and dangerous relays before... My relay doesn't have those slot cuts. So should I replace it with something like this one: https://www.seeedstudio.com/Grove-2-Channel-SPDT-Relay.html ? I will also print a 3D PLA case to place the relay into for extra safety – Mito Jan 24 '23 at 00:36
  • @Mito The seeedstudio / grove board is a lot safer. The relays are still not as good as their specifications claim BUT in your application should work well. The board claims to be out of stock at seeedstudio, but is reported as in stock at [Digikey](https://www.digikey.co.nz/en/products/detail/seeed-technology-co.,-ltd/103020132/9369927) and at [RS components](https://nz.rs-online.com/web/p/power-motor-robotics-development-tools/1845098), and [Mouser](https://nz.mouser.com/ProductDetail/Seeed-Studio/103020132?qs=MLItCLRbWszvXAqr6XcP%2Fw%3D%3D) & probably elsewhere. – Russell McMahon Jan 24 '23 at 06:45
  • @Mito Those are NZ sites but probabkly will direct you to ones in your area. – Russell McMahon Jan 24 '23 at 06:47
  • Thanks for the help! Could you also take a look at this other question I posted and let me know what is the best approach to doing it is a safe but practical way? Link is here: https://electronics.stackexchange.com/questions/651446/can-we-connect-multiple-devices-to-the-mains-with-just-1-cable – Mito Jan 27 '23 at 19:29
0

If you got this from China or India, brown gets connected to Live and blue gets connected to Neutral of 220 VAC line.

Again, for this product or for ac voltage in general, there is no polarity. You can connect any wire to Live and any wire to Neutral and it will work just fine. However, as per new India standards, brown is live and blue for neutral in a single phase two wire system. China seems to follow something similar but I might be wrong.

Whiskeyjack
  • 7,946
  • 8
  • 53
  • 91