ESTE: Dimmer with PWM and ADC

De MediaWiki do Campus São José
Revisão de 08h37min de 20 de novembro de 2015 por Katharine.sf (discussão | contribs) (→‎Assembly)
Ir para navegação Ir para pesquisar

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 use some of the concepts learnt until now: PWM and ADC. Here we will use a potentiometer to turn 3 LEDs on and off. According to the potentiometer value, a specific LED is turned on or off. The main loop reads the potentiometer through the ADC, switching more LEDs on as its value increases or switching more LEDs off as its value decreases.

Pseudo code

Let's begin with a solution. The pseudo code (actual coding is up to you) is below:

int main() {
    while(1) {
        value = adc->read();
        if(value < 10%) {
            led1->off();
            led2->off();
            led3->off();
        } else if(value < 30%) {
            led1->on();
            led2->off();
            led3->off();
        } else if(value < 80%) {
            led1->on();
            led2->on();
            led3->off();
        } else if(value >= 80%){
            led1->on();
            led2->on();
            led3->on();
        }
        delay(50); //ms
    }
    return 0;
}

The pseudo-code is self-explaining: an infinite loop reading the ADC channel to which the potentiometer has been connected and a composed conditional to switch on/off the LEDs through the respective GPIO ports.

Schematic

Schematic of the circuit

Part List

  • 3 LEDs
  • 3 20 to 220 ohm resistors to the leds
  • 1 10k potentiometer
  • 1 Protoboard
  • 7 copper wires (tinned) or jumpers


Assembly

Assembly of the circuit

Solutions

Tools

  • AVR GCC and tools
  • Arduino IDE