Arduino Tutorials – Lesson 9 – Joystick Interface on Arduino UNO

Creating position of Joy Stick program using Arduino UNO

Required Components

  1. Arduino UNO -1 no
  2. Joystick Module -1 no
  3. LEDs -5 no
  4. Resistor: 150 ohm -5 no
  5. Breadboard -1 no
  6. Connecting wires -1 set

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect the 150 Ohm Resistor and Arduino Uno gnd to the LED.
  3. Connect the Arduino Uno Board 2nd pin to the Joy stick.
  4. Connect the Arduino Uno 8 ,9 ,10 ,11th pins to the Joy stick.
  5. Connect the Arduino Uno 5V & gnd to the Joy stick controller.
  6. Connect the Arduino Uno Board A0 & A1 pins to the X -axis & Y-axis.
  7. Check the Circuit Connections.
  8. Check the Arduino program.
  9. Run the Arduino program.

Arduino Program

int joyX=A0;
int joyY=A1;
int button=2;
int buttonState = 0;
int buttonState1 = 0;

void setup(  ) 
{
  pinMode(7,OUTPUT);
  pinMode(button,INPUT);
  digitalWrite(button, HIGH);
  Serial.begin(9600);  
}

void loop(  ) 
{
  int xValue = analogRead(joyX);
  int yValue = analogRead(joyY);
  Serial.print(xValue);
  Serial.print("\t");
  Serial.println(yValue);
  
  buttonState = digitalRead(button);
  Serial.println(buttonState);
  if (xValue>=0 && yValue<=10)
  {
    digitalWrite(10, HIGH);
  }else
  {
    digitalWrite(10, LOW);
  }
  if (xValue<=10 && yValue>=500)
  {
    digitalWrite(11, HIGH);
  }else
  {
    digitalWrite(11, LOW);
  }
  if (xValue>=1020 && yValue>=500)
  {
    digitalWrite(9, HIGH);
  }else
  {
    digitalWrite(9, LOW);   
   }
  if (xValue>=500 && yValue>=1020)
  {
    digitalWrite(8, HIGH);
  }else
  {
    digitalWrite(8, LOW);
  }
  if (xValue>=1020 && yValue>=1020)
  {
    digitalWrite(9, LOW);
    digitalWrite(8, LOW);
  }
  if (buttonState == LOW)
  {
    Serial.println("Switch = High");
    digitalWrite(7, HIGH);
  }else
  {
    digitalWrite(7, LOW);
  }
  buttonState1 = digitalRead(7);
  Serial.println(buttonState1);
  delay(100);
}

Usage

  1. Gaming controls
  2. Air craft

Arduino Tutorials – Lesson 8 – LDR Sensor on Arduino UNO

Creating LDR Sensor program using Arduino UNO

Required Components

  1. LED -1 no
  2. LDR -1 no
  3. Resistor 10K Ω -1 no
  4. Resistor 220 Ω -1 no
  5. Bread board -1 no
  6. Arduino UNO board -1 no
  7. Connecting cables -1 set

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect the Arduino UNO A0 pin to the LDR.
  3. Connect the Arduino UNO 13th pin to the LED.
  4. Connect the Arduino Uno 5V, GND to the LDR Sensor using jumper wires.
  5. Check the Arduino program.
  6. Check the circuit connections.
  7. Run the Arduino program.

Arduino Program

const int ledPin=13;
const int ldrPin=A0;

void setup(  )
{
  Serial.begin(9600);
  pinMode (ledPin,OUTPUT);
  pinMode (ldrPin,INPUT);
}

void loop( )
{
  int ldrstatus = analogRead(ldrPin);
  if (ldrstatus<=300)
  {
    digitalWrite(ledPin,HIGH);
    Serial.print("LDR in Dark,LED is ON");
  }
  else
  {
    digitalWrite(ledPin,LOW);
    Serial.print ("LDR in Light,LED Is Off");
  }
}

Usage

  1. Alarm clocks
  2. Street lights
  3. Light intensity meters
  4. Burglar alarm circuits

Projects

  1. Shooting game

Arduino Tutorials – Lesson 7 – Three LEDs Connect With A Single Switch Blink Using Arduino UNO

Creating three LEDs blink program using push button

Required Components

  1. Led -3 no
  2. Resistor(220 ohm) -3 no
  3. Resistor(10K) -1 no
  4. Pushbutton -1 no
  5. Bread Board -1 no
  6. Arduino UNO -1 no
  7. Connecting Wires -1 set

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect Arduino board 5V and GND pin to the bread board by using wires.
  3. Connect 220 Ω Resistors to each LED Anode (+) pin and all cathode (-) pin to Gnd.
  4. Connect Arduino pin 9, 10, 11 to the 220 Ω Resistors another pin.
  5. Connect 10 k Ω Resistor to the switch.
  6. Connect switch button another pin to the Arduino pin 8.
  7. When we press the push button 1st time LED1 blinks.
  8. When we press the push button 2nd time LED1 off and LED2 blinks.
  9. When we press the push button 3rd time LED2 off and LED3 blinks.
  10. Repeated last 3steps as per the program.
  11. Check the Arduino program.
  12. Check the circuit connections.
  13. Run the Arduino program.

Arduino Program

int led1=9;
int led2=10;
int led3=11;
int btn=0;
const int buttonpin=8;

void setup (  )
{
  pinMode (led1, OUTPUT);
  pinMode (led2, OUTPUT);
  pinMode (led3, OUTPUT);

  pinMode (buttonpin, INPUT);
  Serial.begin(9600);
}

void loop (  )
{
  
  if (digitalRead(buttonpin)== HIGH)
  {
    btn ++;
    Serial.println(btn);
    Lighton(btn);
    delay (500);
  }
  if (btn >=3)
  {
    btn=0;     
  }
}

void  Lighton(int n)
{
  digitalWrite (led1, LOW);
  digitalWrite (led2, LOW);
  digitalWrite (led3, LOW);
  if (n==1){
    digitalWrite (led1, HIGH);
  }
  else if (n==2)
  {
    digitalWrite (led2, HIGH);
  }
  else if (n==3)
  {
    digitalWrite (led3, HIGH);     
  } 
}

Usage

  1. Advertising application.
  2. Decoration purposes.

Arduino Tutorials – Lesson 6 – Single LED Control With Single Pushbutton

Creating single LED blink program using push button

Required Components

  1. LED -1 no
  2. 220 Ω Resistor -1 no
  3. 10 KΩ Resistor -1 no
  4. Push button -1 no
  5. Bread Board -1 no
  6. Arduino Board -1 no
  7. Connecting wires -1 Set

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect Arduino board 5v and GND pin to the bread board by using wires.
  3. Connect 220 Ω Resistor to the LED Anode (+) pin and cathode (-) pin to Gnd.
  4. Connect 220 Ω Resistor another pin to Arduino pin 9.
  5. Connect 10 k Ω Resistor to the switch button.
  6. Connect switch button another pin to the Arduino pin 7.
  7. When we press the push button LED blinks.
  8. Check the Arduino program.
  9. Check the circuit connections.
  10. Run the Arduino program.

Arduino Program

int ledPin = 9;
int buttonPin = 7;

void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}


void loop()
{  
  int button = digitalRead(buttonPin);
  if (button==HIGH)
  {
    digitalWrite(ledPin,HIGH);
  } 
  else
  {
    digitalWrite(ledPin, LOW);
  }
}

Usage

  1. Switching operations.

Arduino Tutorials – Lesson 5- Servo Motor Angle Setup Using Arduino UNO

Creating servo motor angle program using Arduino UNO

Required Components

  1. Servo motor(5V) -1 no
  2. Arduino board -1 no
  3. Connecting wires -1 set

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect Arduino board 5v and GND pin to the servo motor 5v and GND by using wires.
  3. Connect servo motor data pin to the Arduino UNO pin 9.
  4. Write Arduino code to run motor which angle changes from +90 degree to -90 degree.
  5. Check the Arduino program.
  6. Check the circuit connections.
  7. Run the Arduino program.

Arduino Program

#include <Servo.h>
Servo myservo;
int pos=0;
int stepdelay=10;

void setup(  )
{
  myservo.attach(9);
}

void loop(  )
{
  moveFromTo(0,90);
  delay (1000);
  moveFromTo(90,180);
  delay(1000);
  moveFromTo(180,90);
  delay (1000);
  moveFromTo(90,0);
  delay (1000);
}

void moveFromTo(int From, int To)
{
  if (From <=To)
  {
    for (pos=From; pos <=To; pos +=1)
    {
      myservo.write(pos);
      delay( stepdelay);
    }
  }
  else
  {
    for(pos=From; pos >=To;pos -=1)
    {
      myservo.write(pos);
      delay( stepdelay);
    }
  }
}

Usage

  1. Conveyor Belts.
  2. Camera Auto Focus.
  3. Solar Tracking System.
  4. Metal Cutting & Metal Forming Machines.
  5. Antenna Positioning.
  6. Printing Presses/Printers.

Projects

  1. Robot-Arm.
  2. Sensor dustbin.

Arduino Tutorials – Lesson 4 – Sweep Servo Motor Control Using Arduino UNO

Creating servo motor program using Arduino UNO

Required Components

  1. Servo motor (5V) -1 no
  2. Arduino UNO board -1 no
  3. Connecting wires -1 set

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect Arduino board 5v and GND pin to the servo motor by using wires.
  3. Connect servo motor data pin to the Arduino UNO pin 9.
  4. Check the Arduino program.
  5. Check the circuit connections.
  6. Run the Arduino program.

Arduino Program

#include<Servo.h>
Servo servo1;

void setup(  )
{
  servo1.attach(9);
}

void loop(  )
{
  servo1.write(0);
  delay(1000);
  servo1.write(90);
  delay(1000);
  servo1.write(180);
  delay(1000);
}

Usage

  1. Industrial robotics.
  2. CD/DVD players.
  3. Elevators.
  4. Rudders.
  5. Automated doors.

Projects

  1. Robot-Arm.
  2. Sensor dustbin.

Arduino Tutorials – Lesson 3 – Three LED Blink Using Arduino UNO

Creating three LED blink program using Arduino UNO

Required Components

  1. LED -3 no
  2. Resistor 220Ω -3 no
  3. Arduino UNO board -1 no
  4. Bread Board -1 no
  5. Connecting wires -1 set

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect Arduino board 5v and GND pin to the breadboard by using wires.
  3. Connect 220 Ω Resistors to the each LED Anode (+) pin and both cathode (-) pin to GND through breadboard.
  4. Connect Arduino 11, 12, 13 pin to the 220 Ω Resistors another end.
  5. Check the Arduino program.
  6. Check the circuit connections.
  7. Run the Arduino program.

Arduino Program

int led1=11;
int led2=12;
int led3=13;

void setup (  )
{
  pinMode (led1, OUTPUT);
  pinMode (led2, OUTPUT;
  pinMode (led3, OUTPUT);
}


void loop (  )
{
  digitalWrite (led1, HIGH);
  digitalWrite (led2, LOW);
  digitalWrite (led3, LOW);
  delay (1000);
  
  digitalWrite (led3, LOW);
  digitalWrite (led1, LOW);
  digitalWrite (led2, HIGH);
  delay (1000);
  
  digitalWrite (led1, LOW);
  digitalWrite (led2, LOW);
  digitalWrite (led3, HIGH);
  delay (1000);
}

Usage

  1. Focused lights.
  2. Residential and business lighting.
  3. Desk lamps.
  4. Lighting for signage.

Arduino Tutorials – Lesson 2 – Double LED blink using Arduino UNO

Creating Double LED blink program using Arduino UNO

Required Components

  1. Led -2 no
  2. Resistor 220Ω -2 no
  3. Arduino board -1 no
  4. Bread Board -1 no
  5. Connecting wires -1 set

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect Arduino board 5v and GND pin to the bread board by using wires.
  3. Connect 220 Ω Resistors to the each LED Anode (+) pin and both cathode (-) pin to Gnd.
  4. Connect Arduino 9, 10 pin to the each 220 Ω Resistors another end.
  5. Check the Arduino program.
  6. Check the circuit connections.
  7. Run the Arduino program.

Arduino Program

int led1 = 9;
int led2 = 10;

void setup()
{
  pinMode (led1, OUTPUT);
  pinMode (led2, OUTPUT;
}

void loop()
{
  digitalWrite (led1, LOW);
  digitalWrite (led2, HIGH);
  delay (500);
  
  digitalWrite (led1, HIGH);
  digitalWrite (led2, LOW);
  delay (500);
}

Usage

  1. Reading lights.
  2. Night lights.
  3. Security lights.

Ball Collecting Robot – Arduino Robots

Ball collecting robot is a mobile controlled wheeled robot which can be used to collect balls in a playing area. This is a prototype project which will be useful to learn about mobile robots. This concept can be extended to build fully functional ball collecting robot.

Component Required

  1. Arduino Nano
  2. Bluetooth
  3. 12V DC Motors (2)
  4. Dc Motor Driver
  5. 12V battery
  6. Servo Motor
  7. Cables & Wires
  8. Robot Wheels
  9. Robot Gripper

Circuit Diagram

Steps

1 :Connect the DC Motors with DC Motor Drive

2: Connect the DC motor drive OUTPUT Pins with Arduino Nano Pins

   Drive Pins                Arduino Nano

      1A                        D3
      1B                        D4
      2A                        D5
      2B                        D6

3: Connect the Servo Motor with Arduino Nano

      wires                  Pins

       Red                    5V
       Black                  GND
       Yellow                 D10

4 : Connect the Bluetooth with Arduino Nano

  Bluetooth               Arduino Nano

   5V                          5V
   GND                         GND
   RX                          TX
   TX                          RX

5 : Check the Connection once

6 : Upload the arduino program

7 : Install the mobile application in the mobile device.

8: Test the robot with mobile application

Arduino Program

#include <AFMotor.h>
#include <Servo.h> 
// Check the motor driver datasheet for motor pin connections
AF_DCMotor rm(1, MOTOR12_64KHZ);  // Right motor
AF_DCMotor lm(4, MOTOR34_64KHZ);  // Left motor
Servo grServo; // Servo motor for gripper
byte incomingByte ;

void setup() 
{ 
   Serial.begin(9600);
  // Set motors speed
   rm.setSpeed(200);  
   lm.setSpeed(200);
   rm.run(RELEASE);
   lm.run(RELEASE);
	grServo.attach(10); // Attach gripper
} 
void loop()
{
   if (Serial.available() > 0) {
    incomingByte = Serial.read(); // Read the input character from bluetooth serial input buffer
  
    if (incomingByte == 'A') 
    {
         grServo.write(120);      // Gripper Open Position
    }
    else if (incomingByte =='B') 
    {
        grServo.write(180);      // Gripper Close Position
    }
    else if (incomingByte == 'C') 
    {
        rm.run(FORWARD);        // Run both motors in forward direction
        lm.run(FORWARD);
    }
    else if (incomingByte == 'D') 
    {
        rm.run(BACKWARD);       // Run both motors in backward direction
        lm.run(BACKWARD);
    }
    else if (incomingByte == 'E') 
    {
        rm.run(BACKWARD);       // Turning Left. Run right motor in backward direction and left motor in forward direction
        lm.run(FORWARD);
    }
    else if (incomingByte == 'G') 
    {
        rm.run(FORWARD);        // Turning Right. Run right motor in forward direction and left motor in backward direction
        lm.run(BACKWARD);
    }
    else if (incomingByte == 'F') 
    {
        rm.run(RELEASE);        // Stop both motors
        lm.run(RELEASE);
    }
   }
   delay(20);
}

Get the motor driver library from https://github.com/adafruit/Adafruit-Motor-Shield-library

Get the code from github : https://github.com/robolabz/ballcollectingrobot

For robot base and gripper design files and mobile application, contact “info at robolabz.com”