Internet of Things: More About Arduino
Introduction
Arduino
Brushing things in the last chapter that we have learned. Let us explain what Arduino is.
The above is the simple Arduino Board which does miracles. Let's understand the points mentioned in the diagram and their usage!
- 1 - USB Jack
- 2 - Power Jack
- 3 - GND Pins
- 4 - 5V Supply
- 5 - 3.3 V supply
- IOREF:-Though not numbered in the diagram, this is an interesting port in the board, which provides the voltage ref. with which the microcontroller or the Arduino board operates.
- Vin:-As discussed above the external supply to the board, to pass the voltage to the circuit (external), we can use this port.
- IOREF:-Though not numbered in the diagram, this is an interesting port in the board, which provides the voltage ref. with which the microcontroller or the Arduino board operates.
- 6 - Analog Input Pins
- 7,8,9 - Digital Pins
- 10 - Reset Button
- 11 - ON
- 14 - Voltage Regulator
- 12 - RX-TX LEDs
For more info on the pins please refer to Arduino Pins.
So this is it about the Arduino board, a brief summary I would say! There is much more to this. Please refer here.
Some Prerequisites
Here are some pre-requisites required to learn and start on your work with the Arduino. After you get the Arduino board from the market, the next job is to install the Arduino IDE on your system in order to interact with the microcontroller.
To install the IDE visit the link: Arduino IDE Download. Here, you get a list of OS where you can install it, this proves it is cross-platform! :O Wow!! Another great feature.
After the installation, you need to connect the USB jack to the computer via the jack cord and get the Arduino connected.
The IDE somewhat looks like this,
Mark the highlighted portion below, it says Arduino UNO on COM3. COM3 is a serial port id, which suggests we select the Board connection on COM3 port.
For getting on with MAC, please follow the link here.
The selection is to be done under:
Tools-> Port-> "Select",
The default code as you see goes like:
Pretty simple to understand. It first does the setup and then the loop code gets executed in order to perform the main task you have configured. There are many sample programs built-in with the code, which we can find under:
- void setup()
- {
- // put your setup code here, to run once:
- }
- void loop()
- {
- // put your main code here, to run repeatedly:
- }
- // the setup function runs once when you press reset or power the board
- void setup()
- {
- // initialize digital pin 13 as an output.
- pinMode(13, OUTPUT);
- Serial.begin(9600);
- }
- // the loop function runs over and over again forever
- void loop()
- {
- digitalWrite(13, LOW);
- // turn the LED on (HIGH is the voltage level)
- delay(1000);
- // wait for a second
- digitalWrite(13, HIGH);
- // turn the LED off by making the voltage LOW
- delay(1000);
- // wait for a second
- }
- Bread Board
- Jumper Wires
- A few LEDs and resistors.
Next is to design our circuit, which looks like,
The above is the basic breadboard connection circuit. I will give a pictorial image of the entire circuit connection. In this article, I will be sharing how to take user inputs through the Serial port and use it to light the LED on and off. The circuit connection looks like below,
The connection diagram is below,
The above diagram is a reference. For any doubts, you can add your queries related to the connections. As you have seen, I have used Pin 13 to connect the Arduino program to the Breadboard. That is the programming uploaded that will be used to manipulate the LED on/off via Pin 13. Let's have a look at the code involved,
Thus the above code is simple to understand. We have used the Serial port to track the user input, which is a part of the Arduino IDE.
- int userInput = 0;
- // the setup function runs once when you press reset or power the board
- void setup()
- {
- // initialize digital pin 13 as an output.
- pinMode(13, OUTPUT);
- Serial.begin(9600);
- }
- // the loop function runs over and over again forever
- void loop()
- {
- if (Serial.available() > 0)
- {
- // read the incoming
- byte: userInput = Serial.read();
- // say what you
- got: Serial.print("Received Input: ");
- Serial.println(userInput, DEC);
- }
- if (userInput == 49)
- {
- //As checked through, if 1 is pressed, the result comes to be 49 based on the ASCII code
- digitalWrite(13, HIGH);
- // turn the LED on (HIGH is the voltage level)
- delay(1000);
- // wait for a second
- } else
- {
- digitalWrite(13, LOW);
- // turn the LED off by making the voltage
- LOW delay(1000);
- // wait for a second
- }
- }
Here, the user adds the input, and our code checks, if 1 with ASCII code 49, is hit then the LED lights ON, and if any other key is pressed the LED goes OFF.
That’s all for this chapter. I hope you enjoyed reading!!
Author
Suraj Sahoo
0
8.3k
2.7m