I have one of these IKEA bedframes. Putting a LED strip on the back of the headboard should provide a decent amount of light. Adding a capacitive touch sensor at a sensible, easy to reach part of the frame would make a nice on/off switch, possibly concealed by a piece of matching veneer for good looks.
But what about the brightness? I'd like to be able to control the brightness without having to deal with potentiometers or reprogramming. Well, my sister in law has one of those IKEA lamps that you can turn on and off by just touching it. What's even cooler is that you can adjust its brightness by just holding it.
The logic behind it is pretty simple. Touch (a button) shortly and it will switch the light on/off. Hold it longer and the brightness increases until it reaches full brightness, after that it will decrease. If you let go and hold it again the direction of brightness change also changes. Like this:
I'm using a touch resistor here since my capacitive touch sensors haven't arrived yet, but the effect is almost the same. Touching that strip at a given place will make it have a resistance between 0 and 10KOhm. It's like a potentiometer and the strip is the wiper.
I'm using a small BC337 transistor here to drive the LED, but I can use it for LED strips as well (up to about 1.5 meter) which will be perfect.
There's also a bit of fading code in there to smoothly turn the light on and off. The PWM signal is generated in software using a timer. The code is not really worth sharing at the moment and shouldn't be hard to figure out.
really great!
ReplyDeleteArduino source of public care?
you could be interested to share with me the source?
jezus30000@gmail.com
thank you!
Here it is:
Deletehttps://www.dropbox.com/s/fweqgxqbn1qi8qc/multidimmer.zip
I'm not giving any support for it though :)
Hello! This project is pretty awesome! Can you share with me what elements did you use - transistors, chips, which arduino board?
ReplyDeleteWrite me on niki1999kir@gmail.com
Thanks in advance!
The one in the video is an Arduino Nano, but it should also work with an Uno. I'm using a variable touch resistor as input, but I've replaced that with a capacitive touch sensor (from eBay, costs $1.50). The MOSFET I'm using now is the IRF9530 (ebay, $3 for 5), it's rated for 12A, which is more than enough for 2 meters of LED strip. And 2N3904 general purpose NPN transistor to control the gate of the MOSFET. And of course a couple of resistors :)
DeleteThank you for your answer. Can you also share with me the source code if it is different now from the above one which I downloaded from dropbox? And another important question i hope you will answer me - which ports did you use for the touch sensor and which for the LED?
DeleteThanks in advance. :)
The sensor(s) are on port D, digital pins 0-7
DeleteThe LED output is on port C, those are the ADC pins, A0-A5.
The source code hasn't changed, it's still the same.
To configure the code you have to look at these lines:
#define PIRCOUNT 2
static PIR s_pir[PIRCOUNT] = { PIR( 2 ), PIR( 3 ) };
#define TOUCHCOUNT 3
static Touch s_touch[TOUCHCOUNT] = { Touch( 4 ), Touch( 5 ), Touch( 6 ) };
This defines the number of sensors (motion sensors and touch sensors) and the pins on port D they are connected to. You can only use digital input pins 0 - 7 for this.
#define CONTROLLERCOUNT 1
static Controller s_controllers[CONTROLLERCOUNT] =
{
Controller( &s_touch[0], &s_pir[0] )/*,
Controller( &s_touch[1] ),
Controller( &s_touch[2], &s_pir[1] )*/
};
This piece of code defines the controller(s). Each controller can use one touch sensor and/or one motion sensor. The logic for turning LEDs on/off and fading is located in the controller.
#define CHANNELS 6
static Channel s_channels[CHANNELS] =
{
Channel( s_controllers[0] ),
Channel( s_controllers[0] ),
Channel( s_controllers[1] ),
Channel( s_controllers[1] ),
Channel( s_controllers[2] ),
Channel( s_controllers[2] )
};
This defines the output channels. They control A0-A6. Each channel has a controller. Multiple channels can use the same controller, so you can control multiple LED strips with the same sensor.
So in the code above, I only use one controller which outputs two led strips on A0 and A1. The controller uses one motion sensor on digital pin 2, and one touch sensor on digital pin 4. If you don't want to use the motion sensor then you can just change
Controller( &s_touch[0], &s_pir[0] )/*,
to
Controller( &s_touch[0] )/*,