Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Arduino Boards Articles
Found 99 articles
Calculate time of operation in Arduino
Often, you need to measure the time your microcontroller takes to perform a particular task. You can use the millis() function of Arduino to measure the time. This function returns the number of milliseconds passed since your board started running the current program. Therefore, to calculate the time taken by an operation, you can call millis() before and after your operation, and take the difference of the two values.An example implementation is given below −Examplevoid setup() { // put your setup code here, to run once: Serial.begin(9600); long int t1 = millis(); task_whose_time_is_to_be_measured(); long int ...
Read MoreStructs in Arduino program
A struct is simply a collection of different types of variable. Structs in Arduino mimic the structs in C language. So, if you are familiar with C structs, Arduino structs shouldn’t be an issue. The struct declaration syntax is as follows −Syntaxstruct structName{ item1_type item1_name; item2_type item2_name; . . . itemN_type itemN_name; }An example is given below −Examplestruct student{ String name; int age; int roll_no; }The elements of a struct are accessed using the . (dot) notation. This notation can be used for both reading the elements of a struct, or changing ...
Read MoreInterfacing an ultrasonic sensor with Arduino
In this tutorial, we will interface the ultrasonic sensor HC-SR04 with the Arduino to get the distance from a surface in centimetres.Circuit DiagramAs you can see, you need to connect the Vcc pin of HC-SR04 to 5V, GND to GND, Trig pin to pin 7 of Arduino Uno, and Echo pin to pin 6 of Arduino. You can actually choose any GPIO instead of pins 7 and 6. You just have to make sure that the definitions in the code are proper.Working of HC-SR04The HC-SR04 emits ultrasonic waves at 40, 000 Hz. In order to make it emit waves, we ...
Read MoreRead a specific bit of a number with Arduino
Each number has a specific binary representation. For example, 8 can be represented as 0b1000, 15 can be represented as 0b1111, and so on. If you wish to read a specific bit of a number, Arduino has an inbuilt method for it.SyntaxbitRead(x, index)where, x is the number whose bits you are reading, index is the bit to read. 0 corresponds to least significant (right-most) bit, and so on.This function returns either 0 or 1 depending on the value of that bit in that number.ExampleThe following example will illustrate the use of this function −void setup() { // put your setup ...
Read MoreInterfacing a speaker with Arduino
In this tutorial, we will interface a simple piezo-buzzer with Arduino to create beeping sounds. Such an arrangement can be used in applications like burglar alarms, or water level indicators or such similar projects.Circuit DiagramAs you can see, the circuit diagram is quite straightforward. You need to connect the buzzer’s GND to Arduino’s GND, and the other wire to one GPIO of the Arduino (we have chosen pin 7). You can optionally add a small resistor (~100 Ohm), between the GPIO and the buzzer.Code WalkthroughThe entire code is given below −#define buzzerPin 7 ...
Read MoreGetting data from temperature and humidity sensor using Arduino
In this tutorial, we will interface Arduino DHT-22 Temperature and Humidity Sensor and print the obtained temperature and humidity values on the Serial Monitor.Circuit DiagramWhen the DHT-22 is facing you, the first pin from the left, the VCC pin is connected to 5V, the next pin is the DATA pin, and it is connected to pin 2 on Arduino Uno. The third pin is Not Connected. The 4th pin, GND, is connected to GND on Arduino. A 10K resistor is to be connected between the DATA pin and the Vcc pin of DHT22, as you can see in the above ...
Read MoreGetting data from Vibration sensor using Arduino
In this tutorial, we will interface Arduino with the MPU6050 Vibration sensor.Circuit DiagramAs you can see, we connect Vcc to 3.3V, GND to GND, SDA to A4 and SCL to A5. A4 and A5 also serve as SDA and SCL on Arduino Uno.Code WalkthroughThe code is given below −#include const int MPU_ADDR = 0x68; // I2C address of the MPU-6050 int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ; void setup() { Serial.begin(9600); Wire.begin(); Wire.beginTransmission(MPU_ADDR); Wire.write(0x6B); // PWR_MGMT_1 register Wire.write(0); // set to zero (wakes up the MPU-6050) Wire.endTransmission(true); Serial.println("Setup complete"); } ...
Read MoreDisplaying data on OLED Screen using Arduino
In this tutorial, we will interface Arduino with the SSD 1306 OLED Display.Circuit DiagramAs you can see, we connect Vcc to 3.3V, GND to GND, SDA to A4 and SCL to A5. A4 and A5 also serve as SDA and SCL on Arduino Uno.Required LibrariesThe following libraries will be required for interfacing Arduino Uno with the OLED Display −Adafruit SSD1306Adafruit GFXAdafruit BusIO (required by Adafruit GFX)Go to Tools → Manage Libraries, search for these libraries and click Install.ExampleThe code is given below −#include #include #include #define WIDTH 128 // OLED width (pixels) #define HEIGHT 64 // ...
Read MoreInterfacing GNSS receiver with Arduino to get speed
In this tutorial, we will interface Arduino with a GNSS Receiver and obtain the speed. If possible, you can run this code in a moving vehicle, because otherwise you will get 0 speed if your GNSS receiver is stationary. Any GNSS receiver generally uses UART for communication. We will be using the ublox Neo-6M GNSS module for thisCircuit DiagramAs you can see, we connect Vcc to 5V, GND to GND, RX of the Neo 6M to pin 3 of Arduino Uno, and TX of Neo 6M to pin 4 of Arduino Uno.Required LibrariesTinyGPS library will be required for interfacing Arduino ...
Read MoreMap a 10-bit number to 8-bit in Arduino
Mappings often have to be performed in Arduino for a variety of reasons. One example would be mapping the 10-bit ADC output to 8-bit to save on storage. A 10-bit number would occupy 2-bytes for storage, whereas an 8-bit number would occupy just one byte and still preserve most of the information of the 10-bit number.Arduino has a readymade map() function for achieving this.Syntaxmap(value, fromLow, fromHigh, toLow, toHigh)where, value is the value to be mapped; fromLow and fromHigh are the bounds of the range of the current value; toHigh and toLow are the bounds of the range of the new ...
Read More