How to use Arduino Uno?

Arduino is a popular electronics device in this period. As we explained in the previous course, it can help you to improve your life in technology. read more information about it. What is Arduino?

Arduino is an open-source hardware and computer system used to build electronic projects/ devices.

Arduino Uno

If you don’t have it, please click here and get your easy and affordable. Buy it here

The Arduino Development Board consists of many components that together make it work. Here are some of those main component blocks that help in its functioning:  

 • Microcontroller: First, the microcontroller serves as the heart of the development board, acting as a mini-computer that both receives and sends information or commands to connected peripheral devices. Furthermore, because the specific microcontroller varies from board to board, each one brings its own unique set of specifications. 

 • External Power Supply: An external power supply provides the Arduino development board with a regulated voltage ranging from 9 to 12 volts.

• USB plug: This plug is a very important part of this board. Upload (burn) a program to the microcontroller using a USB cable. It also has a regulated power of 5V which also powers the Arduino board in cases when the External Power Supply is absent.  

Internal Programmer: Use the USB port to program the microcontroller without an external programmer.

Reset Button: Located on the board, this button instantly resets the Arduino microcontroller.

Analog Pins: Equipped with inputs A0–A7 (typical), these pins read variable voltages for sensors and other signals. Use these pins for analog input and output. The no. of analog pins also varies from board to board.  

• Digital I/O Pins: Pins 2–16 (typical) handle digital input and output functions.The no. of these digital pins also varies from board to board.  

 • Power and GND Pins: There are pins on the development board that provides 3.3, 5 volts and ground through them.

Arduino combines tangible hardware—primarily the microcontroller—with the Arduino IDE (Integrated Development Environment), software you run on your computer to write code that controls the physical board.

What is an IDE and what is a Compiler?

An IDE, or Integrated Development Environment, is what they call a package that includes all the tools we need to program. Therefore, it brings everything into one package for convenience. The IDE combines all the necessary tools into one package, making it easier to get started, and Arduino offers the software for free.

Arduino boards are able to read inputs – light on a sensor, a finger on a button and turn it into an output- activating a motor, turning ON a LED…

You can tell an Arduino board what you want to do by sending a set of instructions to the microcontroller on the board.

LetterPurpose
AVerify – Verify Code
B Upload – Verify, Compile and Upload to Arduino
C New – Create New Sketch
D Open – Open existing Sketch
ESave – Save Sketch

A SKETCH stores the Arduino source code in a file.

This is the interface you view when you open your Arduino IDE.

1.2 Some advantages

  • Inexpensive
  • a simple and clear programming environment
  • open-source and extensible software…

1.3 Bare minimum code

void setup(){ 
     // put your setup code here, to run once: 
                     }
void loop(){ 
     // put your main code here, to run repeatedly:
}
  • setup: It is called only when the Arduino is powered on or reset. It is used to initialize variables and pin modes
  • loop: The loop functions run continuously; therefore, they keep executing until the device is powered off. The main logic of the code goes here.

Pin configuration and architecture.

1.4 PinMode

You can set a pin on Arduino as input or output using the pinMode function.

pinMode(13, OUTPUT); // sets pin 13 as output pin
pinMode(13, INPUT); // sets pin 13 as input pin

1.5 Reading/writing digital values

digitalWrite (13, LOW); // Makes the output voltage on pin 13, 0V
digitalWrite (13, HIGH); // Makes the output voltage on pin 13, 5V 
int buttonState=digitalRead(2); // reads the value of pin 2 in buttonState
  • Device and platform features.

The features of the Arduino Uno ATmega328 include the following:

  • The operating voltage is 5V
  • The recommended input voltage will range from 7v to 12V
  • The input voltage ranges from 6v to 20V
  • Digital input/output pins are 14
  • Analog i/p pins are 6
  • DC Current for each input/output pin is 40 mA
  • DC Current for 3.3V Pin is 50 mA
  • Flash Memory is 32 KB
  • SRAM is 2 KB
  • EEPROM is 1 KB
  • CLK Speed is 16 MHz
  1. Pin1 (TX) & Pin0 (RX) (Serial): This pin transmits and receives TTL serial data, and it connects to the equivalent pins of the ATmega8U2 USB to TTL Serial chip.
  2. Pin 2 & Pin 3 (External Interrupts):Connect External Pins 2 and 3 to trigger interrupts based on a low value or a change in value.
  3. Pins 3, 5, 6, 9, 10, & 11 (PWM): This pin gives 8-bit PWM o/p by the function of analogWrite().
  4. SPI Pins (Pin-10 (SS), Pin-11 (MOSI), Pin-12 (MISO), Pin-13 (SCK): These pins maintain SPI communication. However, even though the fundamental hardware offers it, the Arduino language does not currently include it.
  5. Pin-13(LED): Connect the inbuilt LED to pin 13 (digital pin). The LED activates when the pin is HIGH; conversely, it turns off when the pin is LOW.
  6. Pin-4 (SDA) & Pin-5 (SCL) (I2C): It supports TWI-communication with the help of the Wire library.
  7. AREF (Reference Voltage): The reference voltage is for the analog i/ps with analogReference().
  8. Reset Pin: This pin resets (RST) the microcontroller.
  • Familiarizing with Arduino Interfacing Board

Experiment 1: Controlling the Brightness of an LED

Hardware Required

  • 1 x LED
  • 1 x resistor
  • 1 x Arduino UNO R3
  • 1 x breadboard
  • 2 x jumper wires

Wiring Diagram

As shown in the diagram below, an LED is connected to pin 2 of the Arduino. To change the brightness of the LED, the program will vary the duty cycle of the PWM signal output of pin 2.

Codes of lighting a LED

const int pwm = 2 ; //initializing pin 2 as ‘pwm’ variable
void setup()
{
     pinMode(pwm, OUTPUT) ; 	//Set pin 2 as output
}
void loop()
{
     analogWrite(pwm,25); 		 //setting pwm to 25 
     delay(50); 			//delay of 50 ms
     analogWrite(pwm,50); 	
     delay(50); 
     analogWrite(pwm,75); 
     delay(50); 
     analogWrite(pwm,100); 
     delay(50); 
     analogWrite(pwm,125); 
     delay(50); 
     analogWrite(pwm,150); 
     delay(50); 
     analogWrite(pwm,175); 
     delay(50);
     analogWrite(pwm,200); 
     delay(50); 
     analogWrite(pwm,225); 
     delay(50); 
     analogWrite(pwm,250); 
}

Experiment 2: Arduino Traffic Light

Codes of TRAFFIC LIGHT

int red = 10;
int yellow = 9;
int green = 8;
void setup(){
    pinMode(red, OUTPUT);
    pinMode(yellow, OUTPUT);
    pinMode(green, OUTPUT);
}
void loop()
 {  
// green and red off, yellow on for 3 seconds
    digitalWrite(green, LOW);
    digitalWrite(red, LOW);
    digitalWrite(yellow, HIGH);
    delay(3000);

    // turn off yellow, then turn red on for 5 seconds
    digitalWrite(yellow, LOW);
    digitalWrite(green, LOW);
    digitalWrite(red, HIGH);
    delay(5000);

    // red and yellow on for 2 seconds (red is already on though)
    digitalWrite(green, LOW);
    digitalWrite(red, LOW);
    digitalWrite(yellow, HIGH);
    delay(2000);

    // turn off red and yellow, then turn on green
    digitalWrite(yellow, LOW);
    digitalWrite(red, LOW);
    digitalWrite(green, HIGH);
    delay(3000);
}
 

Experiment 3: LCD Screen

An LCD, or liquid crystal display, is capable of displaying text on its screen. Additionally, it offers a clear and efficient way to present information visually.  In this project, you should see the words “hello, world!” displayed on the screen.  The potentiometer is used to adjust the contrast of the display.

Parts Needed:

  • (1) Arduino Uno
  • (1) USB A-to-B cable
  • (1) Half-size breadboard
  • (1) LCD screen
  • (1) Potentiometer
  • (16) Jumper Wires

Circuit Diagram

Codes of LCD display

/*
  LiquidCrystal Library - Hello World

 This sketch prints "Hello World!" to the LCD
 and shows the time.

  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * LCD VSS pin to ground
 * LCD VCC pin to 5V
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

*/

// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}
void loop() {
  // set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}