Mudanças entre as edições de "ESTE: Automatic Dimmer with PWM and ADC"
(Criou página com 'This experiment is part of this project. This experiment is based on contents of [http://www.lisha....') |
|||
(3 revisões intermediárias pelo mesmo usuário não estão sendo mostradas) | |||
Linha 11: | Linha 11: | ||
<syntaxhighlight lang=c> | <syntaxhighlight lang=c> | ||
int main() { | int main() { | ||
+ | set_point = 127; | ||
+ | duty_cycle = 0; | ||
while(1) { | while(1) { | ||
− | + | light = adc->read(); | |
− | if( | + | if (light > set_point && duty_cycle >= 0) |
− | + | duty_cycle = 0; | |
− | + | else if (light <= set_point && duty_cycle <= 255) | |
− | + | duty_cycle = adc->read(); | |
− | + | pwm->write(duty_cycle); | |
− | + | delay(); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | delay( | ||
} | } | ||
return 0; | return 0; | ||
− | } | + | } |
</syntaxhighlight> | </syntaxhighlight> | ||
− | The pseudo-code is self-explaining: an infinite loop reading the ADC channel to which the potentiometer has been connected and | + | The pseudo-code is self-explaining: an infinite loop reading the resistance value of the LDR Photoresistor (that indicates the ambient light), a composed conditional to switch on/off the LED according to the necessity of luminosity, and an ADC channel to which the potentiometer has been connected and determinates the light intensity of the LED. |
==Schematic== | ==Schematic== | ||
− | [[Arquivo: | + | [[Arquivo:Pwm_dimmer_ldr_Esquemático.png|600px|thumb|center|Schematic of the circuit]] |
==Part List== | ==Part List== | ||
− | * | + | *1 LED |
− | * | + | *1 220 ohm resistor to the led |
+ | *1 10k ohm resistor to the ldr photoresistor | ||
+ | *1 10k ldr photoresistor | ||
*1 10k potentiometer | *1 10k potentiometer | ||
*1 Protoboard | *1 Protoboard | ||
Linha 50: | Linha 42: | ||
==Assembly== | ==Assembly== | ||
− | [[Arquivo: | + | [[Arquivo:Pwm_dimmer_ldr_bb.png|600px|thumb|center|Assembly of the circuit]] |
==Solutions== | ==Solutions== | ||
− | *[https://drive.google.com/open?id=0B_chZ- | + | *[https://drive.google.com/open?id=0B_chZ-d1CkpCQnZDMTd3dFBzajQ C - AVR] |
− | *[https://drive.google.com/open?id=0B_chZ- | + | *[https://drive.google.com/open?id=0B_chZ-d1CkpCNzlWSDU5cUUtNkU Arduino UNO] |
==Tools== | ==Tools== | ||
Linha 61: | Linha 53: | ||
==References== | ==References== | ||
− | *[http:// | + | *[http://www.lisha.ufsc.br/teaching/esl/exercises/dimmer.html Lisha - Automatic Light Dimmer] |
− | *[http:// | + | *[http://wiki.sj.ifsc.edu.br/index.php/ESTE:_Analog_Light_Sensor_%28LDR_-_Light_Dependent_Resistor%29 ESTE - Analog Light Sensor (LDR)] |
− | *[http:// | + | *[http://wiki.sj.ifsc.edu.br/index.php/ESTE:_Analog-to-Digital_Converter_%28ADC%29_and_Sensor_Reading ESTE - Analog-to-Digital Converter (ADC) and Sensor Reading] |
+ | *[http://wiki.sj.ifsc.edu.br/index.php/ESTE:_Dimmer_with_PWM_and_ADC ESTE - Dimmer with PWM and ADC] | ||
+ | *[http://wiki.sj.ifsc.edu.br/index.php/ESTE:_Pulse_Width_Modulation_%28PWM%29 ESTE - Pulse Width Modulation (PWM)] |
Edição atual tal como às 10h31min de 24 de novembro de 2015
This experiment is part of this project.
This experiment is based on contents of this UFSC project.
Here we are going to build an experiment with an led and a LDR sensor and the same concepts seen on the Dimmer with PWM and ADC Script. Here we will use a potentiometer to turn 1 LED on and off, only if we need luminosity. To know how much luminosity(light) do we need in our surrounding we will use the LDR sensor, that indicates according to it's resistance, how should be the light intensity of the led. If our surrounding is to dark the specific led is turned on according to the potentiometer value. If it is bright enough, the led is turned off.
Pseudo code
Let's begin with a solution. The pseudo code (actual coding is up to you) is below:
int main() {
set_point = 127;
duty_cycle = 0;
while(1) {
light = adc->read();
if (light > set_point && duty_cycle >= 0)
duty_cycle = 0;
else if (light <= set_point && duty_cycle <= 255)
duty_cycle = adc->read();
pwm->write(duty_cycle);
delay();
}
return 0;
}
The pseudo-code is self-explaining: an infinite loop reading the resistance value of the LDR Photoresistor (that indicates the ambient light), a composed conditional to switch on/off the LED according to the necessity of luminosity, and an ADC channel to which the potentiometer has been connected and determinates the light intensity of the LED.
Schematic
Part List
- 1 LED
- 1 220 ohm resistor to the led
- 1 10k ohm resistor to the ldr photoresistor
- 1 10k ldr photoresistor
- 1 10k potentiometer
- 1 Protoboard
- 7 copper wires (tinned) or jumpers
Assembly
Solutions
Tools
- AVR GCC and tools
- Arduino IDE