Arduino Serial Communication Basics : Learn Arduino

Arduino serial communication is one of the many ways Arduino talks to other devices. Arduino uses asynchronous serial communication to send-receive data to and from other devices. Arduino Uno supports serial communication via on-board UART port and Tx/Rx pins. Generally this transmission happens at 9600 bits per second which is termed as baud rate. [caption id=”attachment_840” align=”aligncenter” width=”424”] Arduino Uno Shown with UART port and Tx,Rx Pins[/caption] Arduino may communicate with many devices including:

  • Another Arduino
  • A computer
  • LCD display
  • Modem
  • Or any device that supports serial communication

How to do it? In this example we’ll connect Arduino and a computer using UART port. For this we are going to use Arduino IDE’s Serial Monitor. Serial Monitor will display data we sent from Arduino Uno. Code:

void setup() {
Serial.begin(9600);
}

void loop() {
Serial.println(“Hello World…”);
delay(1000);
}

Upload this code and select Tools > Serial Monitor (Shift+Ctrl+M). You should see this output. [caption id=”attachment_841” align=”alignnone” width=”579”] Serial Monitor output on the computer[/caption] Further Reading:

  1. Wikipedia: Serial communication
  2. Arduino Reference: Serial

Arduino Pushbutton Example : Learn Arduino

Arduino pushbutton example shows how to read a pushbutton with Arduino Uno. Pushbuttons (also spelled push-buttons) are widely used in calculators, phones and appliances. It closes the circuit when pushed and keeps it close until it is pressed. As soon as you release the button the circuit is open again. Here, we are going to use a push-button to flash built-in LED on Arduino Uno. The circuit is pretty simple! [caption id=”attachment_832” align=”alignright” width=”300”]Circuit diagram Circuit Diagram Showing Connection of Arduino Uno and a Push-button[/caption] Parts needed:

  1. Arduino Uno
  2. A push-button

Approximate Cost: ₹ 30 ($ 0.50)

         

Code:

// Declare the pins for the Button and the LED
int buttonPin = 12;
int LED = 13;

void setup() {
// Define pin #12 as input and activate the internal pull-up resistor
pinMode(buttonPin, INPUT_PULLUP);
// Define pin #13 as output, for the LED
pinMode(LED, OUTPUT);
}

void loop(){
// Read the value of the input. It can either be 1 or 0
int buttonValue = digitalRead(buttonPin);
if (buttonValue == LOW){
// If button pushed, turn LED on
digitalWrite(LED,HIGH);
} else {
// Otherwise, turn the LED off
digitalWrite(LED, LOW);
}
}

References:

  1. What is internal pull-up resistor?
  2. Wikipedia: Push-button
  3. Same project with an external pull-up resistor

Displaying Hello World on LCD : Learn Arduino

In this article we’ll learn displaying hello world on LCD; Interfacing 16x2 LCD with Arduino Uno and display some text on it. Writing Hello World pleases the gods of any new programming language that you want to learn. But in case of Arduino it is the LED blinking program that is generally written first. Any ways, Hello World can certainly be second if not the first so let’s roll!

Parts needed:

  1. Arduino Uno
  2. 16 x 2 LCD
  3. Some jumper wires

Approximate Cost: ₹ 125 ($ 2)

The Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include   

//Initialize LCD with interface pins
//Pin Description: REGISTER SELECT PIN,ENABLE PIN,D4 PIN,D5 PIN, D6 PIN, D7 PIN
LiquidCrystal lcd(0, 1, 8, 9, 10, 11);

void setup() {
//Initialize LCD's number of columns and rows (16,2)
lcd.begin(16, 2);
}

void loop() {
//Set the cursor to column 0, line 0
lcd.setCursor(0, 0);

lcd.print("Hello World to Circuitry!");

//Delay of 0.75 sec
delay(750);

//Shift data to the left
lcd.scrollDisplayLeft();
}

Finally check and upload the code. Read this article to know how to upload and run the code.

References:

  1. 16 x 2 LCD Datasheet
  2. My simulation of this project on Tinkercad
  3. Arduino Howto

LED Blinking on Arduino : Learn Arduino

LED Blinking on Arduino Uno should be your first Arduino project. Arduino Uno has an on-board or built-in LED, in this project we will see how to blink it.

Parts you will need:

  1. An Arduino Uno

Steps:

  1. Connect Arduino with your computer.
  2. Download, install and open Arduino IDE. (See how)
  3. Within IDE chooose File Menu > Examples > 01. Basics > Blink
  4. Now click Verify button and wait for it finish the verification
  5. Finally click on Upload button, and you’re done!
  6. See the LED blinking!

Explanation:

  • Built-in LED is referenced by pin number 13.
  • In setup(), we declare this pin as output pin as we want to use it as so.
  • Next, in loop(), we turn it on, then wait for some time (delay) and than turn it off.
  • This process repeats infinitely.

Remember that this is your first Arduino project, do not worry much if you don’t understand every piece of it. If you are facing difficulties and need help, use comments section below.

An Introduction to Arduino Platform : Learn Arduino

Arduino is an open-source hardware prototyping platform. It is widely used today in electronics projects because it is easy to learn, simple in design, well documented and cheaper. We call it platform because it is both hardware circuit as well as piece of software, the IDE. It also has its own programming language. All these open-source components collectively makes the Arduino platform.

Bit of History: It all started at IDII, Ivrea, Italy in 2003 when some students at the institute started working on creating a low cost prototyping tool for digital projects. Arduino’s sturdy design tells us that it is created by design people and not hardcore electronics guys. You know how bad they are :P! The project witnessed steady rise in its popularity and today it has become the most popular prototyping tool.

Arduino Circuits: As of writing this there are 58 different types of Arduino circuits (simply referred to as Arduinos). You can choose from this variety of circuits the one which fits your application needs. The most popular of them is Arduino Uno.

Arduino IDE: This piece of software helps you write application logic with a fancy editor, compile it and burn it on the circuit board. It can be installed on Windows, Linux and Mac OS platforms. There is also a web based IDE (if you just want to try).

Arduino Programming Language: Arduino programs are called sketches. A sketch is divided into two parts setup() and loop(). Numerous built-in functions are available to make the job easy. The language is largely inspired by C, try to see the code displayed in IDE!

Arduino Culture and Community: Arduino has a strong community helping each other on forums and sharing project ideas. The official website itself is a great resource for learning basics. Arduino day is a world-wide event celebrated in April each year that brings together developers, enthusiasts, students, teachers and novices.

Suggested Reading:

  1. The Untold History of Arduino by Hernando Barragán
  2. Arduino - Products
  3. Arduino Language Reference
  4. Arduino Web Editor
  5. Arduino Forums
  6. Arduino Day at Department of Computer Science, KSKVKU
  7. Download this Article as PDF

Hello World in 10 Different Programming Languages

Writing Hello World is a custom I dare not to break as I start off with this brand new blog. Here are Hello World programs in ten different programming languages.

1. The C Not only C can be termed as mother of most high level languages but it remains relevant till date. It is undoubtedly the most popular language of all times.

1
2
3
#include void main() {
printf("Hello World!");
}

2. C ++ Bjarne Stroustrup’s language gave programmers a new world view with Object Oriented Programming.

1
2
3
#include void main() {
cout << "Hello World!";
}

3. UNIX Shell Shell is like a Ninja’s sword! You need to see this.

1
2
#!/bin/sh
echo "Hello World!"

4. Java Java is perhaps the only ubiquitous multi platform language we have seen.

1
2
3
4
5
public class HelloWorld {
public static void main(String args \[\]) {
System.out.print("Hello World!");
}
}

5. Hello World in C# C# is a great programming language based on C from Microsoft.

1
2
3
4
5
public class HelloWorld {
static void Main() {
System.Console.Write("Hello World!");
}
}

6. JavaScript JS shaped platforms which employ half of the Indian programmers.

1
alert ("Hello World");

7. PHP PHP makes great front-ends for web applications.

1
echo "Hello World!";

8. Python My favourite! Python is simple, readable and powerful.

1
print ('Hello World!')

9. PL/SQL When you cannot think in SQL, you use PL/SQL!

1
2
3
begin
dbms\_output.put\_line ('Hello World!');
end;

10. Arduino C Arduino propels IoT development with affordable open source prototyping boards for everyone. Arduino-C is indeed C!

1
2
3
4
5
6
7
8
9
10
11
12
13
// setup () function runs only once
void setup() {
// Use on-board LED as output
pinMode(LED\_BUILTIN, OUTPUT);
}

// loop function runs forever
void loop() {
digitalWrite(LED\_BUILTIN, HIGH); // turn the LED on
delay(1000); // wait a sec (or 1000 ms)
digitalWrite(LED\_BUILTIN, LOW); // turn the LED off
delay(1000); // wait a sec (or 1000 ms)
}

So this is how journey at iDevji starts, I hope it will create value, may be little, for everyone specially my students!