Introduction: Create Your Own Arduino Header

About: Hi There, U may find lot of useful stuffs and some awesome ideas here in Gundu Bulbu, So, Don't be lazy hit subscribe and stay tuned. #GunduBulbu

Hey there,

Today i'm gonna share you an awesome tips every Arduino user wish to know sooner. when i was learning Arduino no one ever told me these tricks, so i ended up learning the Arduino in a complex way. Then only after 7-8 months later i figured it out and realized how much time and resources i wasted without knowing these tips. lets dive in to the tutorial.

Tutorial Summery

  1. Using "analogWrite" Function effectively to avoid complex circuitry
  2. Create Your Own Header Files to simplify the coding
  3. Pass data as parameter to increase code re-usability

Supplies

  1. Arduino with USB
  2. 3V LED
  3. Some Jumping Wires

Step 1: Using "analogWrite" to Minimize Circuit Design

On your Arduino code you can't normally control the amount of power you supply to the LED or any other device using digitalWrite but Using analogWrite will help you control the amount of power to the circuit. The image below shows the circuit designed for both analog and digital output.

int R_LED = 9;
void setup() 
{
  pinMode(R_LED, OUTPUT);
}

void loop() 
{
  analogWrite(RED_LED, 10);
  delay(delay_value);
  analogWrite(RED_LED, 255);
  delay(delay_value);
}

The Above code will blink the LED with LOW and HIGH brightness instead of toggle between ON and OFF

Step 2: Create Your Own Header & Pass Arguments

To create your Own Header click on the arrow button on the right corner in Arduino IDE then select "New tab". Then type a file name for header and click OK button on the bottom, this will create a header file in your code directory. all you need to do is import that header in main code and use the function calls.

Main Code:

#include"GunduBulbu.h"
int R_LED = 9;
void setup() 
{
  pinMode(R_LED, OUTPUT);
}

void loop() {
  Blink(R_LED,1000);
}

Header Code:

void Blink(int RED_LED,int delay_value)
{
  analogWrite(RED_LED, 10);
  delay(delay_value);
  analogWrite(RED_LED, 255);
  delay(delay_value);
  analogWrite(RED_LED, 0);
  delay(delay_value);
}