Published on

Level 1

Table of Contents

Basic Components

This text will aim to give a basic introduction of the components that will be used in the workshop and to familiarise with their general uses.

  • Breadboard

    IR

    A breadboard is a construction base for prototyping of electronics. It is used to build and test circuits quickly before finalizing any circuit design. It has many holes into which circuit components like ICs and resistors can be inserted.

  • LED

    IR

    A Light Emitting Diode or LED is a semiconductor diode that produces light when a voltage is applied across it. It is primarily used for lighting purposes in electronics and automative industries.

  • Resistors

    IR

    A resistor is a passive two-terminal electrical component that implements electrical resistance as a circuit element.

  • Multimeter

    IR

    A Multimeter is a device that can measure multiple electrical properties. It is mostly used in debugging our circuits.

  • Arduino Uno

    Arduino is basically an open source electronics platform providing both software and hardware. Arduino Uno is perhaps the most widely used microcontroller developed by Arduino.

    On a personal note, the board is pretty robust and is easy to work around.

    Your board looks like this,

    IR
  • Arduino Cable

    IR

    This is a Cable For Arduino UNO/MEGA (USB A to B). You can use it to connect “Arduino Uno”, “Arduino Mega 2560″ or any board with the USB female A port of your computer.

  • LDRs

    IR

    A Light Dependent Resistor or LDR is basically a resistor whose resistance varies depending on the intensity of light falling on it. It can be used in building alarm clocks, burglar alarm circuits, etc. We would be using these to build a Light Follower robot in the workshop.

  • IR Module

    IR

    IR Sensors are crucial components for building the Line Follower robot. These sensors will be required to keep our bot on the path and is pretty much what will guide our bot.

  • BO Motors

    IR

    Bo motor (Battery Operated) lightweight DC geared motor which gives good torque and rpm at lower voltages. We will be using 2 BO motors for our purpose. These motors will be connected to the L293D motor driver which will help us control the direction of motion of the motor as well as the torque generated.

  • L293D Motor Driver

    IRIR

    A motor driver is an integrated circuit chip which is usually used to control motors in autonomous robots. Motor driver act as an interface between Arduino and the motors . L293D, the motor driver included in your kit, is one of the most popular motor drivers.

  • HC-SR04

    IR

    HC-SR04 is an Ultrasonic Sensor that is used for detecting the distance to an object. This sensor would be a key component in building the Obstacle Avoidance robot.

  • HC-05

    IR

    HC-05 is a bluetooth module that gives bluetooth properties to your robot. It enables you to wirelessly control your robot using your phone. This would be a key component in building the Bluetooth Controlled Bot.

  • Jumper Wires

    IR

    Jumper wires are simply wires that have connector pins at each end, allowing them to be used to connect two points to each other without soldering. Jumper wires are typically used with breadboards and other prototyping tools in order to make it easy to change a circuit as needed.

  • Chassis

    A chassis is basically the load bearing framework of an artificial object, say a car or in our case a robot. It provides structural support to our framework. Following are few pictures to give an idea what a chassis would look like -

    IR 

    IR

How to make connections on a Breadboard?

As mentioned before, a breadboard is a circuit board that is used to make temporary circuits. It is a device having electronics and test circuit designs. The electronic elements inside the electronic circuits can be interchanged by inserting the terminals and leads into holes and later connecting it with the help of appropriate wires.

The metal strips are laid out as shown below. Note that the top and bottom rows of holes are connected horizontally and split in the middle while the remaining holes are connected vertically.

IR

In the below image, you can see how all holes in the selected row and selected column are connected together. The set of connected holes can be called a node.

IR

To interconnect the selected row (node A) and column (node B) a cable going from any hole in the row to any hole in the column is needed:

IR

Now the selected column (node B) and row (node A) are interconnected:

IR

Thus, in a Breadboard

IR

You can refer to the following video for more information - Understanding How Breadboards Work

Basic LED - Breadboard connection

The below image shows how to make a simple LED - Breadboard connection.

IR

Explanation

Power connections:

  • The positive terminal of the 9V battery is connected to one of the horizontal rails on the breadboard, in this case the one marked with the + sign, through a Red wire.
  • Similarly, the negative terminal of the 9V battery is connected to the other horizontal rail on the breadboard, in this case the one marked with the - sign, through a Black wire.

LED connections:

  • The positive terminal of the LED, which is longer and bent, is connected to the positive rail (+) on the breadboard through a Red wire.
  • The negative terminal of the LED, which is shorter and straight, is connected to a resistor.

Resistor connections:

  • One end of the resistor is connected to the negative terminal of the LED.
  • The other end of the resistor is connected to the negative rail (-) on the breadboard through a Black wire.

You can take a look at the TinkerCAD Simulation here.

Introduction to Arduino

Arduino is an open-source electronics platform based on easy-to-use hardware and software. It consists of both a physical programmable circuit board (a microcontroller) and a piece of software, or IDE (Integrated Development Environment) that runs on your computer and allows you to write and upload computer code to the physical board.

Arduino boards are able to read inputs such as lights on a sensor, pressure on a button, etc., and turn them into desired outputs such as activating a motor or turning on an LED. The set of instructions required to perform such tasks are given to the Arduino board using the IDE.

Unlike most previous programmable circuit boards, the Arduino does not need a separate piece of hardware (called a programmer) to load new code onto the board - you can simply use a USB cable. Additionally, the Arduino IDE uses a simplified version of C++, making the programming easier.

Arduino manufactures a wide range of boards. These have different sizes, different microcontrollers, and different processing capabilities. The Uno is one of the most popular boards in the Arduino family and an excellent choice for beginners.

Main components

IR
  1. Power (USB): The Arduino UNO is connected to a power source via a USB cable that is terminated in a barrel jack. The USB connection is also used to load code onto your Arduino board. The recommended voltage for most Arduino models is between 6 and 12 Volts. A power supply greater than 20 Volts will damage the Arduino board.

  2. Pins: The pins on the Arduino board are where the connections are made in order to construct the required circuit (in conjunction with a breadboard and connecting wires). The Arduino has several kinds of pins, each of which is used for a different purpose.

    • 5V and 3.3V Pins: These pins are used for power supply to the Arduino. 5V or 3.3V is sufficient for most of the simple components used.
    • GND: These pins are used to 'ground' the circuit.
    • GPIO (General Purpose Input Output Pins): These are specific pins that are programmed to input/output signals.
  3. RX and TX LEDs: RX and TX stand for Receiving and Transmitting, and these LEDs are used to indicate Serial communication (like when we're loading a new program onto the board). The TX and RX LEDs blink whenever there is communication between the onboard microcontroller and the computer through the USB to serial converter chip present near the USB port. The lighting up of the LEDs indicates the direction of the flow of data. When a bit of data goes from the Arduino board to the computer, the TX LED glows. The RX LED glows when a bit of data goes from the computer to the Arduino board.

  4. Reset Switch: This functions as a reset button. Pushing it will temporarily connect the reset pin to ground and restart any code that is loaded on the Arduino. This can be very useful if your code doesn't repeat, but you want to test it multiple times.

  5. Main IC: This functions as the brain of the Arduino. The main IC on the Arduino is slightly different from board type to board type but is usually from the ATmega line of IC's from the ATMEL company. This can be important, as you may need to know the IC type (along with your board type) before loading up a new program from the Arduino software. This information can usually be found in writing on the top side of the IC.

  6. Voltage regulator: It is used to regulate the power supply to the Arduino board. The regulator still has limitations, and hence a supply greater than 20 Volts must not be used as it may damage the board.

Arduino Uno

Arduino Uno is a microcontroller board based on the ATmega328P. It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a USB connection, a power jack, an ICSP header, and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable to get started.

General Purpose Input Output Pins (GPIO)

IR

GPIO pins are programmed to input/output signals. These bridge the gap between programming and electronics. There are two types of GPIO pins:

  • Digital GPIO pins
  • Analog GPIO pins
IR

1. Digital Pins

The digital pins in the Arduino are labelled 0-13 (14 pins). These pins can be used for both digital input as well as digital output.

The pins on the Arduino that are marked with a tilde symbol (~) are known as PWM pins, and are used for analog output. On most Arduino boards (those with the ATmega168 or ATmega328), the PWM pins are 3, 5, 6, 9, 10, and 11 (6 pins). More information about PWM will be provided later.

Pin 13 of the Arduino Uno has a special function. It has an LED and a resistor attached to it. This makes it difficult to configure in the input modes.

Pins 0 and 1 (named RX and TX) are for serial connection and should not be used for other uses.

IR

In order to use the pins for digital input, the digitalRead() function is used. In order to use the pins for digital output, the digitalWrite() function is used.

NOTE - The digitalRead() and digitalWrite() functions will be explained later.

2. Analog Pins

The analog pins in the Arduino are labeled A0-A5 (6 pins). The Arduino has an analog-to-digital (A/D) converter. The converter has 10 bit resolution, returning integers from 0 to 1023. Hence the pins can read analog input voltages between 0 and the operating voltage (usually 5 V). This input is mapped to a value between 0 and 1023 appropriately using the analog to digital converter.

The analog pins are primarily used for analog input signals. But they can also be used like digital GPIO pins (HIGH or LOW input/output). Thus, pins marked as "ANALOG IN" on the board can work either as analog input (using the Analog to Digital Converter), digital input, or digital output.

IR

In order to use the pins for reading analog input signals, analogRead() function is used. NOTE - You will learn more about the analogRead() function in the further sessions.

NOTE - The analogWrite() function is reserved to PWM pins. A more detailed explanation of PWM pins, their function, and the analogWrite() function will be provided later.

Digital/AnalogPin NumberFunction used
Digital Input0-13, A0-A5digitalRead()
Digital Output0-13, A0-A5digitalWrite()
Analog InputA0-A5analogRead()
Analog Output3,5,6,9,10,11analogWrite()

Digital Vs Analog

By the time you are reading this, you would be having a fair idea of what an Arduino is, and what exactly are GPIO pins. On a brief note, Arduino is a microcontroller, while GPIO pins stand for General Purpose Input Output pins. These GPIO pins are further classified into Digital and Analog pins. Now let’s look into what these are and by the end of this document let’s try to make a small circuit using Arduino and a LED.

Before we look into Digital and Analog pins, let's see what are Digital and Analog Signals.

Signals

Signals, in electrical engineering, mean time-varying quantities, usually voltages. These signals are of two types, one is Digital Signal, other is Analog Signal.

Digital Signals

Digital signals refer to signals which are finite or discrete. Meaning different values passed by these signals are finite. For example, in Arduino the digital signals that can be passed are two, **5V5V and 0V0V**. They can be more than two too. But remember, Digital signals are never infinite.

IR

This is how a Digital Signal looks like.

Analog Signals

Unlike Digital signals, Analog Signals are infinite. Meaning it can take any number of values, but usually restricted in an continues interval. For example, in Arduino, the Analog signals sent can vary between 0V0V and 5V5V, both inclusive.

IR

This is how a Analog Signal looks like.

Getting Started With Arduino

How Not To Blowup Your Laptop

The Arduino Uno has undergone many revisions, and hence the Arduino power supply circuit has evolved to an almost foolproof design. In this project, we will learn about the three different ways in which we can power up the Arduino Uno. While making any Arduino project, it is necessary to know these techniques, since there are instances when flexibility with regards to the power supply is required.

Modern Arduino Uno boards allow the board to have more than one source of power to be connected simultaneously. An intelligent switching circuitry ensures that the highest available voltage is selected and sent to the onboard voltage regulator, and eventually powers up the board.

Power Scheme 1

Using the USB Cable The USB port of the Arduino Uno can be connected to a desktop/laptop. If the computer recognizes the device, the current supplied to the board is 500mA at 5V. If the connection is not enumerated, 100mA is supplied at 5V.

IR

Power Scheme 2

Using an AC to DC adapter plugged into the barrel connector The barrel connector can be supplied with an input of 7-12V. This is regulated to 5V by the onboard voltage regulator, and the board is powered on.

IR

Power Scheme 3

Using Vin pin Connect a 9V battery with the positive terminal connected to the Vin pin and the negative terminal connected to the GND pin. The Vin port allows an input between 7 and 12 Volts, and the current should not exceed 500mA.

IR

NOTE - If the Vin / 5V and GND pins are being used to power up the Arduino, double-check the polarity because if the GND and 5V/Vin pins are mixed up, it can potentially damage the Arduino board.

You will be learning how to talk to your Arduino and interface it with other sensors to make it smarter.

The Sketch

Every individual program that is written for the Arduino is called as a "sketch", the most basic of all the sketches is the "blank sketch" its the first sketch you see when you open a new IDE page. Which kinda looks like this

void setup(){
    // Code written here will be only be executed once

}

void loop(){
    // Code written here will be run indefinitely

}

Go ahead and open your IDE, open a new sketch in case you have some other sketch pre-loaded.

Every (mostly) arduino sketch has two components and they are the void setup() and the void loop().

void setup() The setup() function is called when a sketch starts. Use it to initialise variables, pin modes, start using libraries, etc. The setup() function will only run once, after each power up or reset of the Arduino board.

In layman terms, the setup() part of the sketch contains code that needs to be only run once.

void loop() After creating a setup() function, which initialises and sets the initial values, the loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond. Use it to actively control the Arduino board.

In layman terms, the loop() part of the sketch contains code that is to be run indefinitely.

Now that you understand the basic layout of a sketch, lets start learning how to code.

Input/Output

Like the laptop/desktop through which your currently reading this walk-through can be connected to external devices like keyboards, mouse, printers, joysticks. The Arduino which is a microcontroller can also be connected to external input/output devices (input devices are usually called sensors) and just like devices for your laptop most of these sensors can be classified into two categories.

  1. Input
  2. Output

The names are self-explanatory but lets go through a few examples for better understanding.

CategoryLaptopArduino Uno
InputMouse, Keyboard, JoystickPush Button, Keypad, IR Sensor, Temp Sensor, LDR
OutputMonitor, PrinterMotors, LED, LCD Display

Just like your laptop has USB, HDMI and microUSB ports that can be used to connect external devices, the Arduino has a set of pins called the GPIOs (General Purpose Input/Output pins) that can be used to connect external devices to the Uno.

pinMode()

Now that you know what kinda external devices you will be working with its high time you also learn how to let your arduino know what device it is about to work with using pinMode().

pinMode() Configures the specified pin to behave either as an input or an output. See the description of digital pins for details on the functionality of the pins.

Example Sketch

void setup(){
    // The "8" refers to the digital pin 8 on the arduino board
    pinMode(8,INPUT); // for an INPUT device
    // The "9" refers to the digital pin 9 on the arduino board
    pinMode(9,OUTPUT); // for an OUTPUT device
}

void loop(){

}

Since the nature of a device (input/output) and the pin its connected to, doesn't change mid-program, its often sufficient to let the Arduino know about the devices its dealing with once at the start of the sketch, hence pinMode() is placed inside the void setup() and not inside the void loop().

The pin numbers for the Arduino board are mentioned on the board and can be used as it is inside the pinMode() function.

TV Serial

TV Serial

Sometimes its really useful to see what's going on inside the brain of a microcontroller. Whilst there are many ways to send and receive information to and from a microcontroller and the computer, using the Serial port turns out to be the easiest. Serial communication is the process of sending one bit of data at a time, sequentially from one device to another. The main purpose of this serial communication is to transfer the sketch from computer to Arduino, to send information to computer etc. All Arduino boards have at least one serial port and it communicates on digital pins 0 (RX) and 1 (TX). The serial port is connected to the USB port on the board, and we can use the built-in Arduino Serial library to send data to the serial monitor in the Arduino IDE or to an external serial monitor.

Monitor

The Serial Monitor is basically a window in the Arduino IDE that allows you to send messages from your computer to an Arduino board (over USB) as well as receive messages from the Arduino.

Here's how you can access the Serial Monitor

  1. Open your Arduino IDE. Click on 'Tools' in the Menu bar, and select 'Serial Monitor'.
  2. Alternatively, you can use the hotkey Ctrl+Shift+M

This is how your Serial Monitor will typically look like

IR

begin()

The Serial.begin( ) function is a part of the serial object in the Arduino. It tells the serial object to perform initialization steps to send and receive data on the Rx and Tx (pins 1 and 0). It sets the baud rate for serial communication between your Arduino board and another device.

The most common reason to use serial.begin() is when you want to output some information from your Arduino to your computer screen. 99% of the time, you’ll be putting the Serial.begin() function inside of the setup() function. As you may know, setup() only runs once, and since you’ll only need to establish the Serial Communication one time – it makes sense to have it there.

Syntax: Serial.begin(speed)

speed: It signifies the baud rate. The default baud rate in Arduino is 9600. We can specify other baud rates as well, such as 4800, 14400, 38400, 28800, etc.

Probably the most important practical thing you need to know is that for serial communication to work, the baud rate in Serial.begin() and the baud rate set on the receiving device need to match. If you are using the Arduino IDE Serial Monitor window to read the information from your Arduino, then you can use the baud rate drop down to set the baud rate. But remember! If these two values don’t match – then anything you try to send over serial will not work right.

Basic program to print your name

As you know whatever we do in the void setup() is only run once whereas as the part in the void loop() keeps on runing until Arduino is powered. This is an example to print your name once when the board is powered.

void setup()
{
  Serial.begin(9600);  //Begin serial communication at 9600(Baud rate)
  Serial.println("Hi, I'm Bhavya Jain");  //Print text
}

void loop(){ }

Serial.print() is used to print in a single line. Serial.println() moves to next line after printing.

Add delay to your program

delay() function is used to add some time delay to your program. For example if you want to print "1" and thenafter 1 second you want to print "2" and so on. You will need delay function.

The function takes milliseconds as input.

void setup(){
	Serial.begin(9600);
}
void loop(){
	//This will print 1,2,1,2...infinitely
	Serial.print(1);
	delay(1000); // Do nothing for 1 second
	Serial.print(2);
	delay(1000); // Do nothing for 1 second
}

The Serial.print( ) function in Arduino prints data to the serial port. It allows you to send information from your Arduino to your computer, so that you can see the value displayed on your Serial Monitor.

Syntax: Serial.print(value, format)

value: It signifies the value to print, which includes any data type value.

format: It consists of number bases, such as OCT (Octal), BIN (Binary), HEX (Hexadecimal), etc. for the integral data types. It also specifies the number of decimal places.

You can read more about this function here.

If we wish to print the data in different lines, we can use the Serial.println() function. This function is basically the same as the Serial.print() function (except that it prints data in different lines) and has the same syntax.


Assignment

Q1. Print the series of Sinx with number of terms entered by the user and value of x of your choice.

Q2. An H-bridge is an electronic circuit that switches the polarity of a voltage applied to a load. These circuits are often used in robotics and other applications to allow DC motors to run forwards or backwards. Now you have to use 2 LEDs. 1st LED should glow in one configuration & 2nd LED should glow in other configuration of the H-bridge.