Build Your Own Arduino Library

Introduction: Build Your Own Arduino Library

About: I am an Electric Electronic Engineer student and freelancer . I want to share staff what i build with you.

Hey everyone . In some projects you may have to create your own library when you are not able to use the ready libraries. Or you can create your own library by its own standards. Today , I will show you how easily you can build your own library and use in your code...

Step 1: Introduce

=>WHAT IS .H FİLE?

An H file is a header file referenced by a C, C++ or Objective-C source code document. It may contain variables, constants, and functions that are used by otherfiles within a programming project. H files allow commonly used functions to be written only once and referenced by other source files when needed.

=>WHY DO WE USE C OR C++ FOR CREATING OUR LIBRARY ?

Arduino software consists of a development environment (IDE) and libraries. The IDE is written in Java and is based on the environment of the language Processing. The libraries are written in C and C ++ and compiled with AVR-GCC and AVR Libc. .

Step 2: EXAMPLE CODE

In this project we create the library of the HC-SR04 sensor.

#include "mylibrary.h"

HC HC,HC1;

void setup() { Serial.begin(9600); HC.trigPin(A0); HC.echoPin(A1); HC1.trigPin(A2); HC1.echoPin(A3); }

void loop() { double distance1 = HC.calculate(A1,A0); double distance2 = HC1.calculate(A3,A2);

Serial.print("distance1 = "); Serial.println(distance1); Serial.print("distance2 = "); Serial.println(distance2); delay(500); }

Step 3: PARTS

Here is a list of parts that i used to make this project:

  • Arduino UNO
  • Breadboard
  • HC-SR04 *2 (you can use only one)
  • Jumper Wires (male to male and male to female)

Step 4: SCHEMA

Step 5: RESULT

THANKS FOR VIEWING

Be the First to Share

    Recommendations

    • Make it Glow Contest

      Make it Glow Contest
    • First Time Author Contest

      First Time Author Contest
    • PCB Challenge

      PCB Challenge

    2 Discussions

    0
    davidgoadby
    davidgoadby

    1 year ago

    I have often created chunks of code that I reused many times and ought to have been in a library. Now I can. Thank you.

    0
    Azmi Deliaslan
    Azmi Deliaslan

    Reply 1 year ago

    You're welcome