This tutorial explains Digital input and digital output. Digital input is taken through push button and that is detected by Arduino Nano. This input is processes by Arduino Nano and it send digital command to attached LED.
When the button is pressed LED glows.
1. Introduction:
A step by step illustrated basic tutorial for Arduino Nano. In this tutorial we are taking digital input from a push button switch. That input is read by Arduino Nano board and decision is taken accordingly. When we press the button LED glows. Thus this tutorial is for both digital input and digital output.
2. Required Hardware
S.No. | Item | Quantity |
1. | Arduino Nano | 1 |
2. | Mini USB Cable | 1 |
3. | Breadboard | 1 |
4. | LED | 1 |
5. | Resistor 220 Ohm | 1 |
5. | Resistor 10K | 1 |
6. | Push Button | 1 |
7. | Male to Male Jumper Wires | 6 |
3. Building Circuit
Schematic Diagram:
Circuit Layout:
4. Programming:
Once we are done with circuit part, here is our programme to this circuit.
You may download codes (Arduino Sketch) from here.
This code has a simple function to perform, if Button is pressed glow the LED.
const int BUTTON = 4; // Naming switch button pin const int LED = 3; // Namin LED pin int BUTTONstate = 0; // A variable to store Button Status / Input void setup(){ pinMode(LED, OUTPUT); pinMode (BUTTON, INPUT); } void loop() { BUTTONstate = digitalRead(BUTTON); // Reading button status / input if (BUTTONstate == HIGH) // Condition to check button input { digitalWrite(LED, HIGH); } else { digitalWrite(LED, LOW); } }
5. Output:
After successful uploading of the code, try pressing and releasing the button, the LED glows if the button is pressed and gets off when the button is released.
If you have any query please write us at support@roboindia.com
Thanks and Regards
Content Development Team
Robo India
https://roboindia.com