HOW TO CONTROL INPUT AND OUTPUT ARDUINO
Tutotial arduino this time we try to learn about how the arduino pin works in input mode, input pullup and output In this arduino tutorial we use Arduino Uno, as we know arduino uno has as many as 14 digital pin input-output that is on pin 0 sd 13.
So every time we will use an arduino digital pin as input or as an output, we must first set the pin mode. This pin mode is set at void setup() by using the pinMode(pin, mode) syntax. Here we discuss each output input mode on the arduino.
Mode Input High Impedance
Syntax : pinMode(pin, INPUT);
note This high impedance input mode is the default or default mode of the arduino pin. In this mode it is as if there is a 100 Mega ohm resistor mounted series against the pin. This means that in these conditions pins need a slight current to change logic conditions, this mode is either used to read capacitive touch sensors or read LEDs as photodiodes.
Mode Input Pullup
Syntax : pinMode(pin, INPUT_PULLUP);
In this mode there is an internal resistor of 20K on the atmega arduino chip set through the program. This pull-up resistor is accessed by setting pinMode() as the INPUT_PULLUP. This means inversely proportional to high impedance input mode, HIGH logic means off condition and LOW logic means on.
So when using a pin as a pull-up input, the other end of the sensor component device or for example on the button must be connected to the ground. An example is used push button, if the button is not pressed or the condition is open then the arduino will read the high condition, and the LOW condition when the button is pressed. The following image shows an illustration of pull-up input.
Syntax : pinMode(pin, OUTPUT);
When the pin is set in output mode, the pin will be in a low impedance state. This means that pins can deliver sufficient current output to other circuits. Atmega pins can be sourced or synced by 40 mA (milliamper) to other circuits.
If the load flow from another circuit exceeds the current of the atmega pin, it can damage the pin, it can even damage the atmega ic. Therefore to overcome it it is recommended to attach a resistor 470 ohm or 1K ohm on the output pin to another circuit.
Reference arduino.cc/reference
After we discuss some input and output modes on the arduino, next we will create a program, which is to create replicas such as the spaceship interface or spacecraft control panel with led and push button.
Required components
1x Board Arduino
1x Breadboard
1x Green LED
2x Red LED
1x Pushbutton
3x Resistor 330 ohm
1x Resistor 10K ohm
Spaceship Interface Suite
int tombol; const int pin_led_hijau = 2; const int pin_led_merah1 = 3; const int pin_led_merah2 = 4; const int pin_tombol = 5; void setup() { pinMode(pin_led_hijau, OUTPUT); pinMode(pin_led_merah1, OUTPUT); pinMode(pin_led_merah2, OUTPUT); pinMode(pin_tombol, INPUT); } void loop() { tombol = digitalRead(pin_tombol); if (tombol == 1) { // Tombol di tekan digitalWrite(pin_led_hijau, LOW); digitalWrite(pin_led_merah1, LOW); digitalWrite(pin_led_merah2, HIGH); delay(250); digitalWrite(pin_led_merah1, HIGH); digitalWrite(pin_led_merah2, LOW); delay(250); } else { // Tombol tidak di tekan digitalWrite(pin_led_hijau, HIGH); digitalWrite(pin_led_merah1, LOW); digitalWrite(pin_led_merah2, LOW); } }
1 Comments