Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Manufacturing Technology >> Manufacturing process

Arduino Tutorial 02: Buttons & PWM – Master Digital I/O & LED Control

Welcome to the second Arduino Tutorial from our Arduino Tutorial Series. In this tutorial we will learn how the Digital Input and Output pins work and we will make few examples using Buttons and LEDs. Also we will learn what is PWM (Pulse Width Modulation) and make examples for controlling the LED brightness using PWM.

This is a Step by Step Video Tutorial which is easy to be followed. Also, below the video you can find what Parts do we need for this tutorial and the Source Codes of the Examples in the video.

Components needed for this tutorial


  • Arduino Board …………………………… / AliExpress
  • Breadboard and Jump Wires ………  / AliExpress
  • LED ……………………………………………
  • 220 Ohm Resistor ……………………..

Circuit schematic of the examples


 

Arduino Tutorial 02: Buttons & PWM – Master Digital I/O & LED Control

Source code of the first example


int button = 12;
int led = 13;

int buttonState = 0;

void setup() {
pinMode(led, OUTPUT);
pinMode(button, INPUT);
}

void loop() {
buttonState = digitalRead(button);
if (buttonState == HIGH)) {
digitalWrite(led, HIGH);
}
else {
digitalWrite(led, LOW);
}
}Code language: Arduino (arduino)

Source Code of the second example


int led = 13;
int button = 12;

int buttonState =0;
int brightness = 0;
int brightup = 2;

void setup() {
pinMode(led, OUTPUT);
pinMode(button, INPUT);
}

void loop() {
analogWrite(led, brightness);

buttonState = digitalRead(button);

if ( buttonState == HIGH ) {
brightness = brightness + brightup;
}
if ( brightness == 255 ) {
brightness = 0;
}
delay(30);
}Code language: Arduino (arduino)

Manufacturing process

  1. Build a Smart Arduino Quadruped Robot: Step‑by‑Step Guide
  2. Build Stunning Web-Driven LED Animations with Raspberry Pi & Arduino
  3. Master the MPU6050: Accelerometer & Gyro Tutorial for Arduino
  4. Arduino Data Logging with SD Card & DS3231 RTC – Step‑by‑Step Tutorial
  5. Mastering Arduino with DS3231 RTC: Step‑by‑Step Tutorial
  6. Master Arduino Bluetooth: HC‑05 Module Tutorial for Smartphone & PC Control
  7. Master Arduino Control with MATLAB GUI: Step-by-Step Tutorial
  8. Master Arduino & MATLAB Integration: Step‑by‑Step Serial Communication Tutorial
  9. Arduino Tutorial 06: Connecting Arduino to Processing via Serial Communication
  10. Arduino Tutorial 02: Buttons & PWM – Master Digital I/O & LED Control