Hi, today I am going show a tutorial of how to use an Arduino(basics):
There two parts of arduino code:
Void setup() and void loop()
Void setup() - The initial code run by the Arduino
Void loop() - The code that runs forever till the Arduino is disconnect
Arduino has two different types of pins:
Digital and Analog pins
Digital pins are numbered 0-13
Analog pins are numbered as A0-A6
Remember, after a line of code, use a semicolon.
A basic program uses two commands called digitalWrite or analogWrite and pinMode
digitalWrite is used to give an output to a specific digital pin
analogWrite is used to give an output to a specific analog pin
pinMode defines whether the device connected is an output or input device
Circuit diagram:
Here is some example code that makes an led blink:
intled= 2; // defines that led is connected to digital pin two
voidsetup(){
pinMode(led, OUTPUT); //defines led as a output device
}
void loop(){
digitalWrite(led,HIGH); //turns on led
delay(400) //waits for 400 milliseconds
digitalWrite(led,LOW); //turns off led
}
There is a whole library for servomotor
It is called Servo.h
there are 4 parts of code to make a servo move:
#include<Servo.h>-it adds the servo library to the code
Servo servo-renames Servo as servo
servo.attach()-attaches servo to desired digital pin
servo.write()-moves servo in the typed degree
Circuit diagram:
Here is the code to move the servo in 180 degree angle:
#include<Servo.h>;
Servo servo
void setup(){
servo.attach(9)
}
void loop(){
servo.write(180)
}
I hope you liked this tutorial!
Please respect the project!



_ztBMuBhMHo.jpg?auto=compress%2Cformat&w=48&h=48&fit=fill&bg=ffffff)




Comments