LED Brightness Control
In this project, we vary the intensity of an LED light with a potentiometer to have manual control over it's lumens.
Circuit
Components
- 1 Smowboard Think Mini
- 1 LED
- 1 potentiometer
- 1 100 ohm resistor
- 2 male-to-male jumper wires
- 4 male-to-female jumper wires
- 1 screw driver
In this circuit, we use an LED. The cathode pin of the LED (i.e the longest pin) is connected to Smowboard's Ground via the negative rail of the breadboard. The anode pin of the LED is connected to pin number 2 of the Smowboard that provides PWM signal to control its brightness. We also use a potentiometer in the circuit that connected with 3.3V and GND pins of Smowboard. It's signal pin is connected to Smowboard's pin 13 that supports Analog to Digital conversion. Using this circuit, the analog signal from the potentiometer is scaled and provided to the LED to operate between 0% and 100% brightness.
Flow
[{"type":"system","config_props":{"global_vars":[]}},{"id":"32932ce8.706b14","type":"common/on interval","z":"1e696429.3f2dec","config_props":{"name":"","interval":"0.01"},"outputProps":{},"dependency_set":{},"x":150,"y":180,"wires":[["fa6c2496.2b9c08"]]},{"id":"12423b96.65b8b4","type":"smow_pulse/analog write","z":"1e696429.3f2dec","config_props":{"name":"","config":"cc5ea4d.28f0a58","duty_cycle":"mapped","frequency":"1000","h_point":"0"},"outputProps":{},"dependency_set":{},"x":770,"y":180,"wires":[[]]},{"id":"fa6c2496.2b9c08","type":"smow_adc/analog read","z":"1e696429.3f2dec","config_props":{"name":"","config":"30bddb4b.f46814"},"outputProps":{},"outputs":[{"variables":[{"name":"digital value","value":"digital_value"}]}],"dependency_set":{},"x":350,"y":180,"wires":[["a2799c0d.322e8"]]},{"id":"a2799c0d.322e8","type":"smow_util/map","z":"1e696429.3f2dec","config_props":{"name":"","input":"digital_value","x1":"0","x2":"4095","y1":"0","y2":"100"},"outputProps":{},"outputs":[{"variables":[{"name":"mapped","value":"mapped"}]}],"dependency_set":{},"x":570,"y":180,"wires":[["12423b96.65b8b4"]]},{"id":"cc5ea4d.28f0a58","type":"smow_pulse/analog write config","z":"","config_props":{"name":"","pin":"2","duty_resolution":"11","timer_num":"0","led_channel":"0","clk_config":"0","speed_mode":"0"},"outputProps":{},"dependency_set":{}},{"id":"30bddb4b.f46814","type":"smow_adc/adc config","z":"","config_props":{"name":"","input_type":"0","pin":"13","non_gpio_input":"0","atten":"3","adc_bit_width":"3","samples":"2","v_ref":"1100","unit":"1","channel":"4"},"outputProps":{},"dependency_set":{"false_dep":false,"input_type_pin":true,"input_type_non_gpio_pad":false,"adc_unit1":false,"adc_unit2":true,"adc_ch0":false,"adc_ch1":false,"adc_ch2":false,"adc_ch3":false,"adc_ch4":true,"adc_ch5":false,"adc_ch6":false,"adc_ch7":false,"adc_ch8":false,"adc_ch9":false}}]
To import this code to the Studio, copy it and paste it into the import nodes dialog box in the import section.
Lets understand the code,
- The flow starts with an
on interval
node. All next nodes connected to it get triggered repeatedly after the specified interval of time. - Double click on the node to change its properties.
- We set the time interval of the
on interval
node to 0.05 seconds to keep updating the brightness of the LED frequently. - The
on interval
is followed by theanalog read
node that detects the value of voltage on its set pin and outputs it between a specified range, in our case between 0 to 4095. - Double click on the
analog read
node to set its Input property. Now click on the pencil icon button to configure its input. A new dialog will appear with its config node's properties. - Set the pin number to 13 and make sure the voltage range is set to maximum and digital range is set to 0 to 4095.
- We will now connect a
map
node that converts a variable's value from one range(X1 to X2) to another(Y1 to Y2). Set its ranges as X1=0, X2=4095, Y1=0 and Y2=100. - We set its input property to the
digital_value
variable that is output by theanalog read
node. - This will convert digital values from 0-4095 range, to 0-100 range that can be fed to our
analog write
node that we will connect to themap
node. - In the
analog write
node, we set the output property by clicking the pencil icon button. A new dialog will appear with its config node's properties. We set the output pin to pin 2, set timer to timer0 and LEDC channel to channel0. - Now coming back to the properties of the
analog write
node, we set intensity=mapped. - The flow is ready, it will repeatedly take the analog value from the potentiometer, scale it to 0-100 and set voltage intensity of the pin connected to our LED.
- Now, we upload the code to the Smowboard using the
upload
button on the Studio. - Now, change brightness of the LED by turning the potentiometer between 0 and 360 degrees and your project is done.
Learn Coding and Electronics easily using Smowcode.