Published on

Level 2

Table of Contents

Arduino Uno

Arduino is a platform used for building electronic projects, it consists of a physical programmable circuit board (often referred to as a microcontroller ), and a software (called the IDE) which runs on the computer and allows you to write programs to the physical board.

Arduino boards are useful in reading inputs (Ex: light on a sensor, finger on a button) and turn it into desirable outputs (Ex: turning on an LED, or running a motor). This process can be done by providing a set of instructions to the Arduino board using the IDE. Arduino provides several microcontrollers, but our focus will remain on the most popular one i.e. Arduino Uno

What’s in an Arduino Uno?

arduinouno

Microcontroller

This part is the brain of the Arduino. It processes the code written and executes the input and output commands. So it includes a memory that stores your code, a processor that processes your code. The Arduino uses ATMega microcontrollers and the Arduino Uno has the ATMega328 microcontroller.

USB Port

The USB port allows you to connect to the computer to establish a medium of communication between communication has to follow a set of rules called a uses to communicate with the computer is called Receptor & Transmitter).

Power pins

The Arduino Uno can output 5 volt and 3.3 volt from the pins “5V” and “3.3V”. This can be used to power other sensors or components.

GND or Ground pins

These pins are at 0 volt. They are used to complete and form a closed circuit.

Reset Push Button

By clicking this button restarts your Arduino Uno.

GPIO (General Purpose Input Output) Pins

They are specific pins on the arduino that can be programmed to input/output signals. They bridge the programming with the electronics. They are of two types: Digital GPIO: Strictly outputs two values i.e. HIGH or LOW. Analog GPIO: Reads an analog signal within a defined precision.

digitalvsanalog

Serial Communication

On the software side, let’s look into how the Uno actually communicates with the computer and the serial monitor.

A video on the serial port and print commands can be found here.

The serial monitor can also be used to take inputs from the user.

Here is Paul McWhorter’s amazing tutorial on this topic.

Pay special attention to parseInt() and parseFloat() commands.

There are two important functions related to the serial input in the code, and that is Serial.available() and Serial.read().

Serial.available() returns the number of characters (i.e. bytes of data) which have arrived in the serial buffer and that are ready to be read.

Serial.read() returns the first (oldest) character in the buffer and removes that byte of data from the buffer.

So when all the bytes of data are read and no new serial data has arrived, the buffer is empty and Serial.available() will return 0.


int arrivingdatabyte = 0; // initializing the incoming serial byte
void setup(){
	Serial.begin(9600); // 9600 is the data rate in bps (bits per second).
}
void loop(){ // loop function that executes repeatedly
	if(Serial.available( ) > 0){  //  It will only send data when the received data is greater than 0.
		arrivingdatabyte = Serial.read( );  // It will read the incoming or arriving data byte
		Serial.print("data byte received:");
		Serial.println(arrivingdatabyte, DEC); // here, DEC means Decimal
	}
}

If else Conditional Statements

The if… else allows greater control over the flow of code than the basic if statement, by allowing multiple tests to be grouped.

An else clause (if at all exists) will be executed if the condition in the if statement results in false. The else can proceed another if test, so that multiple, mutually exclusive tests can be run at the same time. Each test will proceed to the next one until a true test is encountered. When a true test is found, its associated block of code is run, and the program then skips to the line following the entire if/else construction. If no test proves to be true, the default else block is executed, if one is present, and sets the default behavior.

Note that an else if block may be used with or without a terminating else block and vice versa. An unlimited number of such else if branches are allowed.

if(condition1){

}
else if(condition2){

}
else{

}

Binary System and Decimal System

Computers count different from us. They count with the digits 1 and 0. A computer uses the binary numeral system which is also known as base 2. And in this system, there are only two digits, 1 and 0. This system is used in all modern computers and digital devices like mobile phones.

On the other hand, the decimal system is the oldest and the most widely used numbering system which is also known as base 10. Numbers based on 10 were commonly used in ancient cultures too. This system was derived because we could use our fingers to count.

A bit (short for binary digit) is the smallest and basic unit of data in a computer, and it is usually represented by one of these values, 0 or 1. There are 8 bits in a byte.

An introduction to Binary number system and Decimal number systems is explained well in these links :

binaryquestion

Bit Math

Working on bytes, or data types comprising of bytes like ints, floats, doubles or even data structures which stores large amount of bytes is normal for a programmer. In some cases, a programmer needs to go beyond this - that is to say that in a deeper level where the importance of bits is realized.

There are different bitwise operations used in the bit manipulation. These bit operations operate on the individual bits of the bit patterns. Bit operations are fast and can be used in optimizing time complexity. Some common bit operators are discussed in this section and in this video

Oscilloscope

An oscilloscope is a type of electronic test instrument that can graphically display signal voltage changes. Other signals (such as sound or vibration) can be converted to voltages and displayed on the screen of the oscilloscope.

Engineers use oscilloscopes to study the changing process of various electrical phenomena for laboratory work. It can be used to capture, process, display and analyze the waveform and bandwidth of electronic signals.

They graph an electrical signal as it varies over time and produces a 2D graph with the x-axis being time and y-axis being voltage.

You can learn more about an oscilloscope through these videos :

Measuring Voltage and Current using a Multimeter

A multimeter or a multitester, also known as a VOM (volt-ohm-milliammeter), is an electronic measuring instrument that combines several measurement functions in one unit. A typical multimeter can measure voltage, current, and resistance.

OnShape

We recommend you watch the videos first to get started with OnShape.