At first glance, it may be complicated to start robotic coding with Arduino. Especially after looking at the samples and from there the cables and scattered image of this work is very difficult to create the perception. However, when we go down to the bottom of the work, we examine each piece one by one and when we divide the work into simple pieces, we actually see that it is not too difficult to do this. This article is intended to be a quick guide to remember the frequently forgotten links and simple codes, although it is aimed at people who will start coding for Arduino and project development for the first time.

It is important to note that before you start the activities, you do not have to have an Arduino set to do a project with Arduino. Offline programs such as Fritzing, virtual environments such as Tinkercad, where you can create Arduino circuits virtually. Especially with Tinkercad you can simulate the circuits you have prepared with the system.

For those who will start for the first time, we recommend that they do this in order. It is useful to create your circuit primarily in environments such as Fritzing or Tinkercad. You can leave comments, comments and suggestions in the comments section.

1) Turning on led without code with Arduino:

Objective: To light a led without writing code with Arduino.

Materials:

Arduino Uno

Led

220 Ohm Resistor

Breadboard

Jumper cables

Create the circuit structure by looking at the above circuit diagram created with Fritzing. Then lets make the connection with Arduino by connecting to the computer. As soon as Arduino works, we have to see our LEDs on. In fact, Arduino was used only as a source of electricity in this event. But with this event, we have an idea about what the GND and 5V pins on ledin and Arduino do. We use resistance to prevent the LED from burning. If we do not use resistance, our led will probably become unusable. Instead of a 220 Ohm resistor, we can use it at a resistance level of 330 Ohm or higher. The higher the resistance, the lower the brightness of the LED.

2) Turning on leds in order with Arduino

Objective: Turning on 3 leds at 0,5 seconds interval.

Materials:

Arduino Uno

3 x Led

3 x 220 Ohm Resistor

Breadboard

Jumper cables

Create the circuit according to the above scheme. Then install the following code to Arduino.

void setup() { // We must set output pins pinMode(2, OUTPUT); pinMode(4, OUTPUT); pinMode(6, OUTPUT); } void loop() { digitalWrite(2, HIGH); //Turn on electicity to pin 2 delay(500); //Delaying 0.5 seconds digitalWrite(2, LOW); //Turning off electicity at pin 2 digitalWrite(4, HIGH); delay(500); digitalWrite(4, LOW); digitalWrite(6, HIGH); delay(500); digitalWrite(6, LOW); }

In there with "delay(500)" code keeps led open for 0,5 seconds. If we write 1000 instead of 500, led will be open for 1 seconds.

3) Turning on a rgb led in three different colors with

Objective: Illumunate a rgb led in red, green, blue colors at 0.5 seconds interval

Materials:

Arduino Uno

RGB led

3 x 220 Ohm Ressistor

Breadboard

Jumper cables

The RGB led has 4 legs, unlike the normal 2-legged LED. One of these legs (2nd from the right) is connected to the ground. The other leds are used in order to obtain red, green and blue color values ​​in the order shown by the cable colors to which they are connected. We will send these pins with digital pwm pins according to the values ​​between 0-255 values.

Create the circuit according to the above scheme. Then install the following code to Arduino.

int red=2; int blue=4; int green=6; void setup() { pinMode(red,OUTPUT); pinMode(green,OUTPUT); pinMode(blue,OUTPUT); } void loop() { analogWrite(red,255); //We are giving 255 value to this pin for led only lights red analogWrite(green,0); analogWrite(blue,0); delay(500); analogWrite(red,0); analogWrite(green,0); analogWrite(blue,255); //We are giving 255 value to this pin for led only lights blue

delay(500); analogWrite(red,0); analogWrite(green,255); //We are giving 255 value to this pin for led only lights green

analogWrite(blue,0); delay(500); }

4) Switch on and off a led with button

Objective: Switching on and off with a normal led button. It will open when we press the button, it will close when we press again.

Materials:

Arduino Uno

Led

220 Ohm Resistor (for led)

Buton

10K Ohm Resistor (for button)

Breadboard

Jumper cables

In most of the sites, when the button is given the led turning on examples, the thing that is omitted is that when we press the button once, the LED is lit, once again it will go out. Usually when most of the sites are held down by pressing the button, the example goes out when the button is not pressed and the situation is slightly different. In order to achieve the desired situation, we use two variables with the name of "buttonSt" and "ledSt".

Create the circuit according to the above scheme. Then install the following code to Arduino.

int ledPin=2; int butonPin=4; int butonSt=0; bool ledSt=0; void setup(){ pinMode(ledPin,OUTPUT); // Setting led output pinMode(butonPin,INPUT); // Setting button input } void loop(){ butonSt=digitalRead(butonPin); // Reading value from button if(butonSt==HIGH){ if(ledSt==0) { ledSt=1; } else { ledSt=0; } delay(250); // Putting a little delay to prevent rapid transitions during press button }; if(ledSt==1) digitalWrite(ledPin,HIGH); else digitalWrite(ledPin,LOW); }

5) Give a led gradual brightness with potentiometer

Objective: Providing gradual brightness to a led with a potentiometer

Materials:

Arduino Uno

Led

220 Ohm Resistor (for led)

10K Potantiometer

Breadboard

Jumper cables

Potentiometer was used for the first time in this activity. The working principle of the potentiometer will be understood by this activity.In addition, the proportionality of the map function has been established..Create the circuit according to the above scheme. Then install the following code to Arduino.

int analogValue = 0; int digitalValue = 0; void setup() { pinMode(3, OUTPUT); } void loop(){ analogValue = analogRead(A0); digitalValue= map(analogValue,0,1023,0,255); //Comparing analog value from A0 to digital value analogWrite(3, digitalValue); // Giving compared value to digital pin 3 }

6)Three stage led grading according to the potentiometer value

Objective: It will be ensured that three LEDs will be burned gradually according to the value from the potentiometer. At the highest value, 3 LEDs will be lit and no LEDs will be lit at the lowest value. The leds will light according to the value of the intermediate values.

Materials:

Arduino Uno

3xLed

3x220 Ohm Resistor (for leds)

10K Potantiometer

Breadboard

Jumper cables





int analog_value = 0; int digital_value = 0; void setup() { pinMode(2, OUTPUT); //Defining output pins pinMode(4, OUTPUT); pinMode(6, OUTPUT); } void loop(){ analog_value = analogRead(A0); //Giving potentiometer value to variable digital_value= map(analog_value,0,1023,0,255); //comparing analog value to digital if(digital_value<20){ //If digital value is under 20, no led will be open digitalWrite(2, LOW); digitalWrite(4, LOW); digitalWrite(6, LOW); } if(digital_value>19 && digital_value<85) { // One led open digitalWrite(2, HIGH); digitalWrite(4, LOW); digitalWrite(6, LOW); } if(digital_value>84 && digital_value<170) { //Two led open digitalWrite(2, HIGH); digitalWrite(4, HIGH); digitalWrite(6, LOW); } if(digital_value>169){ //Three led open digitalWrite(2, HIGH); digitalWrite(4, HIGH); digitalWrite(6, HIGH); } }

7) Turning on a RGB led in three colors gradually accoording to potentiometer value

Objective: The RGB LED will be illuminated red, blue and green depending on the value from the potentiometer.

Materials:

Arduino Uno

RGB Led

220 Ohm Resistor

10K Potantiometer

Breadboard

Jumper cables





To make the RGB LED shine in 3 different colors proportionality was made with the map () function as in the previous activity. The value in the range 0-1024 from the potentiometer was divided into three, and the first section was used for red, second for blue and third for green color values. Independent "if" structures were used for each color.

Create the circuit according to the above scheme. Then load the following code into Arduino.

int red=3; int blue=5; int green=6; int analogValue = 0; int digitalValue = 0; int redValue = 0; int blueValue = 0; int greenValue = 0; void setup() { pinMode(3, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); } void loop(){ Serial.begin(9600); analogValue = analogRead(A0); digitalValue= map(analogValue,0,1023,0,255); //Rate the value 0-1024 from A0 to 0-255 with map function if(digitalValue<82) { redValue= map(digitalValue,0,81,0,255); //Rate the range of digital values ​​for red color tones analogWrite(red,redValue); //Only red tones analogWrite(green,0); analogWrite(blue,0); } if(digitalValue>81 && digitalValue<164) { blueValue= map(digitalValue,82,163,0,255); //Rate the range of digital values ​​for blue color tones analogWrite(red,0); //Only blue tones analogWrite(green,0); analogWrite(blue,blueValue); } if(digitalValue>163) { greenValue= map(digitalValue,164,255,0,255); //Rate the range of digital values ​​for green color tones analogWrite(red,0); //Only green tones analogWrite(green,greenValue); analogWrite(blue,0); } }

8) Getting straight and frequency sounds from buzzer

Objective: Getting straight and frequency sounds from the buzzer module with Arduino

Materials:

Arduino Uno

Buzzer

100 Ohm or less Resistor

Breadboard

Jumper cables

Buzzer module is a module that emits different tones according to the incoming electrical frequencies. Alarming, warning sounds can be made with buzzer. Even melodies on various notes can be played with buzzer. You can click reach an piano example. Here we will make examples that will enable us to simply understand the logic of the buzzer's operation. First, let's create our circuit as above. The reason for the use of resistance in this circuit is to prevent the noise from the buzzer. If there is not enough sound, you can use a lower resistance. You can also connect the buzz without using resistance. But then it can be a little disturbing. The sound may be low if you use a large resistor.

Source code that provides continuous sound from the buzzer:

int buzzerPin = 2; void setup() { pinMode(buzzerPin, OUTPUT); } void loop() { digitalWrite(buzzerPin,HIGH); }

Source code that provides a 1 second delayed sound from the buzzer:

int buzzerPin = 2; void setup() { pinMode(buzzerPin, OUTPUT); } void loop() { digitalWrite(buzzerPin,HIGH); delay(1000); digitalWrite(buzzerPin,LOW); delay(1000); }

9) Open and close buzzer with button

Objective: Getting sound from buzzer according to button status

Materials:

Arduino Uno

Buzzer

Press button

1K Ohm Resistor (for button)

Breadboard

Jumper cables

When controlling the buzzer module with the button, we will apply 2 different conditions in this example. In the first case, when the button is pressed, the buzzer sounds out of the buzzer amd if button is not pressed sound won't be get. In the second case when the button is pressed, the buzzer starts to sound and when we press it again, there is no sound from the buzzer. In fact, we did this in the fourth activity. Here the buzzer will be used instead of LED.

First case: When button is pressed, the buzzer sounds and when it is not pressed buzzer does not sound. Code is here:

int buttonPin=2; int buzzerPin=4; int buttonSt=0; void setup(){ pinMode(buzzerPin,OUTPUT); //Set buzzerpin output pinMode(buttonPin,INPUT); // Set buttonPin input } void loop(){ buttonSt=digitalRead(buttonPin); // Reading value from button if(buttonSt==HIGH) digitalWrite(buzzerPin,HIGH); else digitalWrite(buzzerPin,LOW); }

Second Case: When button is pressed, buzzer starts sound and when pressed again buzzer stops sound. Code is here:

int buttonPin=2; int buzzerPin=4; int buttonSt=0; int buzzerSt=0; void setup(){ pinMode(buzzerPin,OUTPUT); //buzzer pinimizi çıkıs ayarladık pinMode(buttonPin,INPUT); // buton pinimizi giriş ayarladık } void loop(){ buttonSt=digitalRead(buttonPin); // butondan değeri okuyoruz if(buttonSt==HIGH){ if(buzzerSt==0) { buzzerSt=1; } else { buzzerSt=0; } delay(250); //Putting a little delay to prevent rapid transitions during press button

}; if(buzzerSt==1) digitalWrite(buzzerPin,HIGH); else digitalWrite(buzzerPin,LOW); }

10) Receiving sound in different tones with different buttons from buzzer and lighting leds according to sound tone

Objective: Reciving 2 notes and geting light saccording to two buttons

Malzemeler:

Arduino Uno

Buzzer

2xButon

2xLed

2x10K Ohm Ressistor (for buttons)

2 x 220 Ohm ressistor (for leds)

Breadboard

Jumper cables

"Select-Case" structure was used in this event. With this structure, different codes can be made according to the different states of a variable. If appropriate, the use of the "Select-Case" structure is more practical than the "if-Else"structure. tone () function is used for the buzzer, which allows the sound to be emitted at different frequencies. Parameters of this function is;

tone(pin_number,frequency,time_delay) . In the following code, a continuous sound will be heard because of not define timing. And at pressing two buttons at the same time will cut off the buzzer sound.

#define btnlow 2 #define btnhigh 4 #define ledlow 5 #define ledhigh 6 #define buzzerPin 9 int btnlowSt=0; int btnhighSt=0; int buzzerSt=0; void setup(){ pinMode(btnlow,INPUT); pinMode(btnhigh,INPUT); pinMode(ledlow,OUTPUT); pinMode(ledhigh,OUTPUT); pinMode(buzzerPin,OUTPUT); } void loop(){ btnlowDurum=digitalRead(btnlow); btnhighDurum=digitalRead(btnhigh); if(btnlowSt==HIGH && btnhighSt==HIGH){ //For stop sound buzzerDurum=0; } if(btnlowSt==HIGH){ buzzerDurum=1; if(btnhighSt==HIGH){ buzzerDurum=2; } switch (buzzerSt) { case 0: digitalWrite(ledlow, LOW); digitalWrite(ledhigh, LOW); digitalWrite(buzzerPin, LOW); break; case 1: digitalWrite(ledlow, HIGH); digitalWrite(ledhigh, LOW); tone(buzzerPin, 264); //for low frequeced sound break; case 2: digitalWrite(ledlow, LOW); digitalWrite(ledhigh, HIGH); tone(buzzerPin, 528); //for high frequenced sound break; } }

11) Printing a message to a 16x2 LCD with Arduino

Objective: Printing desired text to 16x2 LCD module with Arduino

Malzemeler:

Arduino Uno

16x2 LCD

10K potensiometer

Breadboard

Jumper cables





As you can see schema like a bit complicated. If you do not want to deal with cables in this way, you can use the LCD module together with the I2C module. Also make sure that pin legs are soldered to the LCD module before making this connection.

Source code;

#include "LiquidCrystal.h" LiquidCrystal lcd(7, 6, 5, 4, 3, 2); void setup() { lcd.begin(16, 2); lcd.print("Hi guys"); // You can write what you want } void loop() { }

12) Print value according to button pressed on 16x2 LCD

Objective: Printing the desired value according to the button pressed on the 16x2 LCD module with Arduino

Malzemeler:

Arduino Uno

16x2 LCD ekran

10K potentiometer

Breadboard

3xbutton

3x10K Ressistors (For buttons)

1K Ressistor (For LCD)

Jumper kablolar

Source Code:

#include "LiquidCrystal.h" LiquidCrystal lcd(7, 6, 5, 4, 3, 2); #define btnApin 8 #define btnBpin 9 #define btnCpin 10 int btnAst=0; int btnBst=0; int btnCst=0; int btnValue=0; void setup() { lcd.begin(16, 2); pinMode(btnApin,INPUT); pinMode(btnBpin,INPUT); pinMode(btnCpin,INPUT); } void loop() { btnAst=digitalRead(btnApin); btnBst=digitalRead(btnBpin); btnCst=digitalRead(btnBpin); if(btnAst==HIGH){ lcd.clear(); btnValue=1; //Mod1 } if(btnBst==HIGH){ lcd.clear(); btnValue=2; //Mod2

} if(btnCst==HIGH){ lcd.clear(); btnValue=3; //Mod3

} switch (btnDeger) { case 0: lcd.setCursor(0, 0); lcd.print("LCD"); lcd.setCursor(0,1); lcd.print("Mode Test"); break; case 1: lcd.setCursor(0, 0); lcd.print("Mode 1"); break; case 2: lcd.setCursor(0, 0); lcd.print("Mode 2"); break; break; case 3: lcd.setCursor(0, 0); lcd.print("Mode 3"); break; default: lcd.setCursor(0, 0); lcd.print("LCD"); lcd.setCursor(0,1); lcd.print("Mode Test"); break; } }

13) Printing a message to the 16x2 LCD using the I2C module

Objective: Using Arduino UNO with lcd and i2c modules

Malzemeler:

Arduino Uno

16x2 LCD

i2c module

Breadboard

Jumper cables

If the library of the I2C module is not installed on your computer, you must download and install it from the following link:

https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/



Tip: After downloading library files to your computer, you need to open it in the Libraries folder in the directory where Arduino is installed, or in the My Documents / Arduino / Libraries folder if you are using Windows. Or you can download the ZIP library file from Arduino IDE by following the path below.





After intalling libraries, you can upload this source code to Arduino:

#include "Wire.h" // for i2c module #include "LiquidCrystal_I2C.h" //for lcd moule LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // defining i2c and lcd address void setup() { lcd.begin(16,2); lcd.setCursor(0, 0); lcd.print("Hello world"); lcd.setCursor(0,1); lcd.print("I2C ve LCD"); } void loop() { }

If you want the text on the LCD screen to be in marquee, you can edit this code as follows:

#include "Wire.h" // I2C modülünü kullanmak için bu kütüphaneyi ekliyoruz #include "LiquidCrystal_I2C.h" //LCD modülü kullanmak için bu kütüpnaheyi ekliyoruz LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // LCD I2C adresini tanımlıyoruz void setup() { lcd.begin(16,2); lcd.setCursor(0, 0); lcd.print("Merhaba Dünya"); lcd.setCursor(0,1); lcd.print("I2C ve LCD"); } void loop() { lcd.scrollDisplayLeft(); //keeps letters to left delay(1000 }

14)Making digital thermometer with LM 35 temperature sensor

Objective: Printing the ambient temperature on the LCD module via using i2c, Arduino UNO and LM35 temperature sensor.

Malzemeler:

Arduino Uno

LM35 temperature sensor

16x2 LCD

i2c modülü

Breadboard

Jumper cables

Source code:

#include "Wire.h" #include "LiquidCrystal_I2C.h" int lm35Pin=A0; float lm35_voltage; float lm35_temp; LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); void setup() { lcd.begin(16,2); analogReference(INTERNAL); lcd.setCursor(0, 0); lcd.print("Temperature:"); } void loop() { lm35_voltage = analogRead(lm35Pin); lm35_temp = lm35_voltage / 9.31; lcd.setCursor(0,1); lcd.print(lm35_temp); delay(500); }

15) Servo Motor Connection with Arduino

Objective: Connecting the servo motor with Arduino UNO and actuating the servo motor.

Malzemeler:

Arduino Uno

S90 Servo Motor

Breadboard

Jumper kablolar

source code:

#include "Servo.h" // Including servo motor library Servo srv; // srv named class void setup() { srv.attach(3); // connecting 3rd pin to servo } void loop() { srv.write(0); // Servo will turn 0 degree position delay(1000); srv.write(180); //Servo will turn 180 degree position delay(1000); }

with the above code, the servo motor is turning to its first and last positions with one second interval.

15) Two buttons to move the servo motor backward and forward

Objective: Servo motor connection with Arduino UNO and guiding the servo motor in forward and backward positions with 2 buttons

Malzemeler:

Arduino Uno

Servo Motor

Breadboard

Jumper cables

2 x push buton

2 x 1k Ohm ressistors(for buttons)





Create the circuit system according to the above diagram and install the sample code below.

#include "Servo.h" // Including servo library Servo srv; // srv named servo object created #define btnforward 5 //forward pin defined #define btngbackward 6 //backward pin defined int btnforwardSt=0; int btnbackwardSt=0; void setup() { srv.attach(3); // Servo motors signal pin defined pinMode(btnforward ,INPUT); pinMode(btnbackward ,INPUT);} void loop() { btnforwardSt=digitalRead(btnforward); btnbackwardSt=digitalRead(btnbackward); if(btnforwardSt==HIGH){ srv.write(0); //Servo motor turns to 0 degree } if(btnbackwardSt==HIGH){ srv.write(180); //Servo motor turns to 180 degree } }