daviestar
Posts: 4
Joined: Sun Jul 15, 2018 9:07 pm

Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Sun Jul 15, 2018 9:54 pm

How would I go about reading the values from the UK-type dimmer switch module like this?

https://www.amazon.co.uk/Varilight-2-Wa ... B01DY2XE5I

I'm hoping to use as a rotary encoder for the RPI (and also on/off switch).

I've tried some other rotary encoders and potentiometers, but they are not up to the task and I'd like to use these..

Is it possible?

Thanks

User avatar
Z80 Refugee
Posts: 358
Joined: Sun Feb 09, 2014 1:53 pm

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Sun Jul 15, 2018 10:38 pm

I don't understand what you are asking. The link you have provided is to a two-way push-on push-off switch with no dimmer function, just made to fit in a bank with other modules that may include dimmer switches.

Are you asking if you can modify it to include some kind of rotational information, when it will be providing a mains electricity switching function? Not even I would try doing something like that. I very much recommend you steer away. You could be putting lives at risk, not just your own.
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

User avatar
Paeryn
Posts: 2053
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Sun Jul 15, 2018 10:45 pm

daviestar wrote:
Sun Jul 15, 2018 9:54 pm
How would I go about reading the values from the UK-type dimmer switch module like this?

https://www.amazon.co.uk/Varilight-2-Wa ... B01DY2XE5I

I'm hoping to use as a rotary encoder for the RPI (and also on/off switch).

I've tried some other rotary encoders and potentiometers, but they are not up to the task and I'd like to use these..

Is it possible?

Thanks
The module you linked to likely doesn't have any values to read, the clue is in the name Varilight 2-Way Push-On/Off Switch Module (Dummy Dimmer Light Switch), i.e. it is an on-off switch only, used generally where you want (or need) to convert a dimmer switch into an on-off switch whilst keeping the external look of the dimmer switch. (Z80 Refugee beat me to posting, as they said it could also be used as a switch in a bank of dimmers.)
She who travels light — forgot something.

User avatar
bensimmo
Posts: 2986
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Mon Jul 16, 2018 7:04 am

What are you trying to do with it?

Mains UK dimmers work on AC.
They slice the 50Hz mains up by altering the trigger level it turns the bulb on.
This alters the time it is on and off.

At least this was how it was done the last time had a look at them.

I would guess given its working over and average 325 to -325 V peak to peak, the Pi not be about to provide the pulse to see the trigger levels
.

I could well be wrong and things may have changed.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 20059
Joined: Sat Jul 30, 2011 7:41 pm

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Mon Jul 16, 2018 8:33 am

Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Please direct all questions to the forum, I do not do support via PM.

User avatar
piglet
Posts: 872
Joined: Sat Aug 27, 2011 1:16 pm

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Mon Jul 16, 2018 8:34 am

Sounds to me like the OP is asking whether a dimmer switch can be used as/like a rotary encoder; not necessarily anything to do with mains voltages (I sure hope)

User avatar
Z80 Refugee
Posts: 358
Joined: Sun Feb 09, 2014 1:53 pm

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Mon Jul 16, 2018 8:45 am

piglet wrote:
Mon Jul 16, 2018 8:34 am
Sounds to me like the OP is asking whether a dimmer switch can be used as/like a rotary encoder; not necessarily anything to do with mains voltages (I sure hope)
If that's the case, the answer is no. But the item linked is not a dimmer switch.
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

daviestar
Posts: 4
Joined: Sun Jul 15, 2018 9:07 pm

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Mon Jul 16, 2018 6:14 pm

Thanks for the replies, and apologies for the confusion, I did indeed mean a standard UK dimmer switch module with push on/off.

Some thing like this: https://www.amazon.co.uk/Varilight-Stan ... B01N1806WY
What are you trying to do with it?
I am working on a smart light switch!
Sounds to me like the OP is asking whether a dimmer switch can be used as/like a rotary encoder; not necessarily anything to do with mains voltages (I sure hope)
Yes exactly. I don't want to go near mains voltages.. the PI (or possibly something smaller such as Pi Zero) would be powered over Ethernet, and I simply want to use a standard dimmer as a rotary encoder and on/off switch.

What about dimmers designed for low-power LEDs, would I have more luck with them?

https://www.amazon.co.uk/Varilight-JQP4 ... B007OU39QQ

drgeoff
Posts: 8340
Joined: Wed Jan 25, 2012 6:39 pm

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Mon Jul 16, 2018 7:05 pm

daviestar wrote:
Mon Jul 16, 2018 6:14 pm
Thanks for the replies, and apologies for the confusion, I did indeed mean a standard UK dimmer switch module with push on/off.

Some thing like this: https://www.amazon.co.uk/Varilight-Stan ... B01N1806WY
What are you trying to do with it?
I am working on a smart light switch!
Sounds to me like the OP is asking whether a dimmer switch can be used as/like a rotary encoder; not necessarily anything to do with mains voltages (I sure hope)
Yes exactly. I don't want to go near mains voltages.. the PI (or possibly something smaller such as Pi Zero) would be powered over Ethernet, and I simply want to use a standard dimmer as a rotary encoder and on/off switch.

What about dimmers designed for low-power LEDs, would I have more luck with them?

https://www.amazon.co.uk/Varilight-JQP4 ... B007OU39QQ
Normal dimmers take a 240 volt AC input and switch it though to the output for part of each positive and negative cycle. The control is part of a phase shift network. Phase shifters only affect AC signals. Ergo these dimmers will not work with DC inputs, even 240 volts DC. Nor will they will work properly with low voltage AC inputs (for a different reason).

I don't know the exact details of dimmers intended for LEDs but even if one could be bodged to work it sounds like a roundabout solution. If you just want something that looks like a dimmer, get a normal 240 volt dimmer and carefully dispose of all its components except the kob and the faceplate. Fit a standard potentiometer* (with or without switch function as you please) to the plate and knob. Wire the pot to an ADC chip connected to the RPi.

(* You might be able to use the pot/switch from the dimmer but all the other circuitry is unsuitable.)

PhatFil
Posts: 263
Joined: Thu Apr 13, 2017 3:55 pm

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Mon Jul 16, 2018 7:20 pm

Probably not.. google reveals
How Dimmer Switches Work. Instead of diverting energy from the light bulb into a resistor, modern resistors rapidly shut the light circuit off and on to reduce the total amount of energy flowing through the circuit. The light bulb circuit is switched off many times every second.
And afaik different lighting solutions have significantly different different dimming methods, none of which are trivial variable resistance circuits.

But to be sure test a dimmer switch with a 3.3v supply and multimeter and see if the voltage change is significant/noticable with operation of the knob. This would be an analogue signal not a digital one .

Imho Probably a lot less hassle to get a hot glue gun or a pot of epoxy resin and bodge a drilled face plate with a rotary encoder together for use or perhaps look at a 3d printed solution?

User avatar
bensimmo
Posts: 2986
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Mon Jul 16, 2018 7:22 pm

I would be looking at Sonoff-Tasmota/WeeMo setups that will do the on-off \nd also the dimming (they can certainly do the smart on/off switching.
https://github.com/arendst/Sonoff-Tasmota/wiki

and have a look at Arduino AC light dimming, it may give some insight to reading the dimmer value
e.g. http://www.instructables.com/id/Arduino ... e-circuit/

daviestar
Posts: 4
Joined: Sun Jul 15, 2018 9:07 pm

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Mon Jul 16, 2018 9:21 pm

Thanks for the great answers folks.. it looks like I'm in over my head trying to get this to work the way I want!
Imho Probably a lot less hassle to get a hot glue gun or a pot of epoxy resin and bodge a drilled face plate with a rotary encoder together for use or perhaps look at a 3d printed solution?
This is the stage I'm at - I have this rotary encoder: https://coolcomponents.co.uk/products/r ... inated-rgb, and I have it mounted on a blank faceplate. But it doesn't feel like a light switch dimmer, I couldn't whack it on and off like I do other dimmers!

Any recommendations for a rotary encoder with on/off switch that is a little more like a UK light switch dimmer?

User avatar
Z80 Refugee
Posts: 358
Joined: Sun Feb 09, 2014 1:53 pm

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Mon Jul 16, 2018 9:30 pm

daviestar wrote:
Mon Jul 16, 2018 6:14 pm
I simply want to use a standard dimmer as a rotary encoder and on/off switch.
Won't work (not without an inordinate amount of effort, and it doesn't sound like you have the experience). Inside the dimmer switch is a potentiometer and a push-on push-off switch. These are inputs to some electronics within the dimmer module which chop the mains voltage to provide the dimming function - so to us it as it is, you would have to feed it with mains and detect what it was doing to the mains. Not good.

Your next option is to dismantle the module and remove the electronics, just leaving the pot and switch. The switch is easy enough to wire to the RPi, see my article. The pot can't be read by the RPi without providing an external A/D converter (available using a HAT). However, if you need to make this match some existing equipment for appearance, this may be the way to go.

The easiest way to do what you want is simply one push switch wired to the RPi: press and release to turn on, press and release to turn off, press and hold to ramp brightness up and down (release when desired brightness is reached). Turns on at the last set brightness. You can make this more sophisticated using a second push switch.

Beginners Guide to Wiring Things to the GPIO
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

User avatar
bensimmo
Posts: 2986
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Tue Jul 17, 2018 7:10 am

So you are basically looking for a rotary potentiometer or encoder that has the shaft as a push button to turn on.

Something like this https://news.thomasnet.com/fullstory/po ... y-20006470

I would first have fun pulling apart the light switch.
As that would give you the tactile feel of the switch.

PiGraham
Posts: 3317
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Tue Jul 17, 2018 8:15 am

daviestar wrote:
Mon Jul 16, 2018 9:21 pm
Thanks for the great answers folks.. it looks like I'm in over my head trying to get this to work the way I want!
Imho Probably a lot less hassle to get a hot glue gun or a pot of epoxy resin and bodge a drilled face plate with a rotary encoder together for use or perhaps look at a 3d printed solution?
This is the stage I'm at - I have this rotary encoder: https://coolcomponents.co.uk/products/r ... inated-rgb, and I have it mounted on a blank faceplate. But it doesn't feel like a light switch dimmer, I couldn't whack it on and off like I do other dimmers!

Any recommendations for a rotary encoder with on/off switch that is a little more like a UK light switch dimmer?
It seems the issue is about feel/function. Can you say more about what want?
Many dimmers use potentiometers that turn easily without steps. Some may a bit of friction. Some may have a bot of mass in the knob for a more solid feel and enough inertia to spin. Some have a push switch action.
None of this is due to the dimming function.
What do you want?

It sounds like you want a light action potentiometer that you can turn with a flick of a finger. no click stops, low friction, low inertia. That typical of most potentiometers on the market.

You can use a potentiometer with a Pi by using an analog to digital converter (ADC).
That can be a circuit of discrete components as Z80Refugee describes or a chip, on breadboard/protoboard, a breakout board or a HAT. Lots of options. I'd go for an ADC that is supported in your preferred gpio library with a simple analog read function, just to keep things simple.
For example gpiozero.MCP3001. The gpiozero library supports a range of ADC devices.

User avatar
Z80 Refugee
Posts: 358
Joined: Sun Feb 09, 2014 1:53 pm

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Tue Jul 17, 2018 8:28 am

bensimmo wrote:
Tue Jul 17, 2018 7:10 am
So you are basically looking for a rotary potentiometer or encoder that has the shaft as a push button to turn on.

Something like this https://news.thomasnet.com/fullstory/po ... y-20006470
You would still need a way to convert the analogue potentiometer output to a digital RPi input. One way to do this is to count the time it takes to charge up a capacitor through the variable resistance of the potentiometer (this is a relatively slow process, but very inexpensive to implement). As per PiGraham above (and my previous post), you can also "keep it simple" by using an existing A-D conversion HAT.

823A02D4-DF46-4C09-911F-FB11D6C3C965.jpeg
823A02D4-DF46-4C09-911F-FB11D6C3C965.jpeg (184.67 KiB) Viewed 424 times

The way this works is that you normally have the capacitor discharged by keeping the GPIO output line HIGH. To take a measurement, make the GPIO output line LOW and count how long it takes before the GPIO input goes LOW (normally it will be HIGH). It will be around 2ms when the pot it set to maximum resistance (with the component values shown), decreasing as the pot is wound down to about 0.2ms.

For those interested: the transistor on the right (Q4) provides a discharge path for the capacitor. When it turns off, the capacitor charges through the pot and resistor (the resistor is necessary in case the pot is at zero resistance, which would short out the transistor). Q3 compares the voltage on the capacitor with a reference voltage on the 100 ohm resistor, which comes from Q2 and the potential divider on Q2's base. (Q2 & Q3 are wired in what we call a "long tailed pair", and form the basis of an op amp.) It is done this way so that variations in supply voltage do not alter the time it takes to charge the capacitor.

When the capacitor voltage exceeds the trip point, Q3 turns on and Q2 turns off, which turns off Q1 and makes the GPIO input go LOW.

Q1 is a general-purpose PNP, Q2-4 are general purpose NPN.

The above is a quality circuit, and should provide consistent timings. If you want "cheap and cheerful", it can even be done with one GPIO pin like this:

B3CED8E9-6AFB-4C8D-9BA6-E59E55CAB4CE.jpeg
B3CED8E9-6AFB-4C8D-9BA6-E59E55CAB4CE.jpeg (58.06 KiB) Viewed 424 times

To use it: make the GPIO pin an output and drive it LOW. Wait 1ms. Make the GPIO pin an input, and read how long it takes to go from LOW to HIGH.
Last edited by Z80 Refugee on Tue Jul 17, 2018 9:10 am, edited 1 time in total.
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

daviestar
Posts: 4
Joined: Sun Jul 15, 2018 9:07 pm

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Tue Jul 17, 2018 8:45 am

Thanks for all the help!

I've bought a dimmer module: https://www.ebay.co.uk/itm/130774631315

And I'll take it apart to see if I can remove the potentiometer/switch from it.
PiGraham wrote:It seems the issue is about feel/function. Can you say more about what want?
I now know after some research that the UK has some strange habits/tastes when it comes to light switches - we use a different circuit design (no earth), different sized fixings, and prefer different dimmer designs from everyone else! I've seen threads with people asking for Z-Wave dimmer switches in the UK style, and the rest of the world is saying "why would you want that? it looks so dated!".

This is part of a larger project with various sensors and an eInk display, so I'm still very interested in a range of potentiometers and rotary encoders that are similar to UK dimmers in feel - I especially would like to find a rotary encoder with clicky infinite spin and push on/off.

So to try to explain the feel... the shaft is 6-7mm, there's a little resistance to the turn making it feel a bit weighty, and there's a lot of travel in the push on/off (~5mm) switch, which means the sturdy plastic knob comes into contact with the faceplate before the switch is fully pressed in, acting as a guard and making it whack-able.

Thanks.

User avatar
bensimmo
Posts: 2986
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Tue Jul 17, 2018 8:47 am

I didn't mention other parts as I'm still not sure what he is doing (controlling a mains light and wanting dimming on/off with remote monitor of it's position OR just wanting the dial&button for something else completely unrelated).

Interfacing can come later as you (or someone) had already mentioned ADC's

Though I will.be having a read through your post. Always good for future ideas :-)
That "capacitor charge time" is also use for LDR Light intensity measurements. O vious since they are both just resistors.
I do like the look of the more complete solution.

PiGraham
Posts: 3317
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Tue Jul 17, 2018 9:13 am

daviestar wrote:
Tue Jul 17, 2018 8:45 am

I now know after some research that the UK has some strange habits/tastes when it comes to light switches - we use a different circuit design (no earth), different sized fixings, and prefer different dimmer designs from everyone else! I've seen threads with people asking for Z-Wave dimmer switches in the UK style, and the rest of the world is saying "why would you want that? it looks so dated!".

This is part of a larger project with various sensors and an eInk display, so I'm still very interested in a range of potentiometers and rotary encoders that are similar to UK dimmers in feel - I especially would like to find a rotary encoder with clicky infinite spin and push on/off.
Infinite spin encoders indents and push witch are very common. You should have no problem finding those.

You may have to arrange for a stiff spring or something with some give to get long travel push that you can whack without loading the switch contacts.

User avatar
Z80 Refugee
Posts: 358
Joined: Sun Feb 09, 2014 1:53 pm

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Tue Jul 17, 2018 9:23 am

daviestar wrote:
Tue Jul 17, 2018 8:45 am
I now know after some research that the UK has some strange habits/tastes when it comes to light switches - we use a different circuit design (no earth), different sized fixings, and prefer different dimmer designs from everyone else! I've seen threads with people asking for Z-Wave dimmer switches in the UK style, and the rest of the world is saying "why would you want that? it looks so dated!".
It's a question of history. Lighting circuits aren't supposed to need an earth, because the user is not supposed to be in contact with the lighting parts and it is cheaper to install two wires than three - this was important in the early days. The parts the user comes into contact with are earthed - ie the metal wall boxes that house the switches. But the modern trend is for mains equipment not to be earthed anyway (most kit is double-insulated with no conductor to the earth pin).

I think you will find there are some very modern switch units etc available for high-spec new builds, but most of our housing stock dates back to the '60s or earlier, so "traditional" units are still required in quantity and therefore cheaply available and therefore still used even in new builds.

"Designer" switches are a product of an over-sophisticated world where form is starting to be a more important feature than function. The result is that the first world is pricing itself out of the market by trying to sustain expensive tastes and standards.
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

drgeoff
Posts: 8340
Joined: Wed Jan 25, 2012 6:39 pm

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Tue Jul 17, 2018 10:57 am

daviestar wrote:
Tue Jul 17, 2018 8:45 am
the shaft is 6-7mm
The standard pot shaft (not just in the UK) is 1/4 inch diameter with a locating flat for the grub screw or spring bar of the knob.

User avatar
Z80 Refugee
Posts: 358
Joined: Sun Feb 09, 2014 1:53 pm

Re: Is it possible to read the value of a UK dimmer switch with Raspberry Pi?

Tue Jul 17, 2018 12:22 pm

drgeoff wrote:
Tue Jul 17, 2018 10:57 am
The standard pot shaft (not just in the UK) is 1/4 inch diameter with a locating flat for the grub screw or spring bar of the knob.
...which is 6.35mm.
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

Return to “Automation, sensing and robotics”

Who is online

Users browsing this forum: RuiC and 15 guests