Category:
Ardunio
Title:
Ardunio Startup Activities for beginners

At first glance, it may be complicated to start robotic coding with Ardunio. 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 Ardunio 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 Ardunio set to do a project with Ardunio. Offline programs such as Fritzing, virtual environments such as Tinkercad, where you can create Ardunio 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 Ardunio:

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

Materials:

  • Ardunio 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 Ardunio by connecting to the computer. As soon as Ardunio works, we have to see our LEDs on. In fact, Ardunio 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 Ardunio 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 ardunio

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

Materials:

  • Ardunio 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 Ardunio.

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:

  • Ardunio 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 Ardunio.

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:

  • Ardunio 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 Ardunio.

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);
}

To be continued...

60 views
COMMENTS