មេរៀនទី១៣៖ Digital Read (INPUT_PULLUP) - Tann Thona

Telecommunication and Electronic Engineering

Post

Post Top Ad

Tuesday, December 15, 2020

មេរៀនទី១៣៖ Digital Read (INPUT_PULLUP)

INPUT_PULLUP

 

1. Objective

The objective is talk about, how to use digital read by using INPUT_PULLUP method in arduino to blink LED.

2. Requirement

  • Arduino Uno x1
  • USB Cable x1 (No need in simulation)
  • Breadboard x1 (No need in simulation)
  • LED x2
  • Resistor (220Ohm or 330Ohm) x2
  • Electronic Wire (No need in simulation) 
  • Button x1

 

3. Build Circuit

Build circuit like Figure 1.

Figure 1: Arduino Connection

 

4. Coding

// Coding by Tann Thona (22/09/2019)
void setup() {
// put your setup code here, to run once:
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(2, INPUT_PULLUP);

}

void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(2) == 0)
{
for(int i = 0; i<20; i++)
{
digitalWrite(12, 1);
digitalWrite(13, 0);
delay(30);
digitalWrite(12, 0);
digitalWrite(13, 1);
delay(30);
}
}
else if (digitalRead(2) == 1)
{
digitalWrite(12, 1);
digitalWrite(13, 1);
}
}

Click Here to Download Code and Proteus Simulation File 

 

4. Result

According to code above, if we press button switching blink 20 times and unpressed LEDs is bright .

Watch Video Explain in Khmer



YouTube: ICT4D-KH
Copyright By Tann Thona

No comments:

Post a Comment

Post Top Ad