Senin, 24 Februari 2020

Saklar digital dengan Arduino

Dalam aplikasi kontrol, switching/pencaklaran adalah hal mutlak yang dilakukan. untuk dapat melakukan switching dengan arduino kita memerlukan bebebrapa komponen elektronik yaitu

  1. Board arduino (mini/uno)
  2. Resistor
  3. LED
  4. Sumber daya/Catu daya DC 5 volt

untuk mengaktifkan led dengan arduino ada skema yang bisa kita lakuka yaitu Polling vs interrupts

Polling is where we are always checking the status of something. In the below examples, inside the loop() function we continuously check the pin state with digitalRead(). We do not know if the pin state has changed until we look at it. Polling is like checking the front door every minute or so to see if the postman is delivering your new Arduino.
Interrupts, as the name may suggest, is where the current process is interrupted and a new process is performed. In context of this post, the Arduino reacts to a pin state whether or not we are checking it or not. This means the code does not need to worry about the pin until the Arduino tells us to. This is like watching a DVD and the door bell rings. You stop the DVD and go check who is at the door. You sign for your new Arduino and go back to watching the DVD. Because you have a doorbell, you do not need to keep checking the door. You simply react when you hear it ring.
Please note: in all examples I am using 5V ATmega based Arduinos (specifically Arduino Nanos). If you are using 3.3v or non ATmega Arduinos you may (or may not) need to make adjustments. I do not cover these at this time.
Tahapan :
In the examples below I have the switch pin connected to a 10K resister, to GND and to the button switch. This means the pin is being pulled LOW. The other side of the switch is connected to vcc (in this case +5V) so when the switch is closed, the vcc over powers the 10K resister and connects the switch pin to 5V making it HIGH. Normally connecting an Arduino pin directly to 5V can be a bad idea but we can do it here because Arduino digital pins that are set for INPUT with pinMode have a very high impedance similar to having a 100 megohm resistor in front of the pin.



berikut link youtube berkaitan dengan switching:




Tidak ada komentar:

Posting Komentar