Tag Archives: Arduino

16×2 LCD interface with Arduino

A liquid-crystal display (LCD) is a flat-panel display or other electronically modulated optical device that uses the light-modulating properties of liquid crystals. Liquid crystals do not emit light directly, instead using a back-light or reflector to produce images in color or monochrome. LCDs are available to display arbitrary images (as in a general-purpose computer display) or fixed images with low information content, which can be displayed or hidden, such as preset words, digits, and 7-segment displays, as in a digital clock. They use the same basic technology, except that arbitrary images are made up of a large number of small pixels, while other displays have larger elements. In this tutorial, we are using 16×2 character LCD display where 16 is characters per line & there are two lines. It means each 16×2 LCD can represent 32 characters, you can represent more characters by scrolling the text.

LCD

LCD-RearIn this LCD each character is displayed in 5×7 pixel matrix. This LCD has two registers, command & data. Like its name, Command register stores command sent to LCD & data register stores the data to be displayed on LCD. Basically the data is ASCII characters which is sent to be displayed on LCD. For more details about LCD, check here.

Pinout

  • +Vcc: Supply voltage is 4.7V to 5.3V DC
  • GND: Ground (0V)
  • Contrast: Contrast adjustment of LCD, through variable resistor to +Vcc
  • RS: It means ‘Register Select’, Selects command register when low & command register when high
  • RW: It means ‘Read/Write’, Low to write the register and high to read from register
  • EN: It means ‘Enable’, sends data to data pins when a high to low pulse is given.
  • D0 to D7: 8 bit data pins
  • Back-light+ : Vcc (+5V) for LCD back-light
  • Back-light- : Ground (0V) for LCD back-light

Connection with Arduino UNO R3

There are two methods to interface 16×2 LCD with Arduino:

  1. Connect all pins of LCD to Arduino
  2. Use I2C module and connect to Arduino by two pins only

In first method, RS, R/W, EN and Data pins will be connected to Arduino;

As shown in above image, contrast pin is connected with pin 6 of Arduino hence contrast will be adjusted by value set in code. In the program ‘LiquidCrystal’ library so make sure you have same library installed in your Arduino IDE. (You can install libraries from Sketch>Include library>Manage libraries)

Code for direct connection method:

You can download above code from here.

In another method, an I2C module will be connected to LCD. By using I2C module only two pins SDA (Serial Data) & SCL (Serial Clock) will be used from Arduino so less wiring for this. LCD will receive commands from Arduino by I2C protocol

As shown in above image, I2C module is connected to LCD directly (For safer side, solder a female header strip on LCD and connect I2C on that so if somehow I2C module or LCD stops working then it can be easily replaced). You can connect multiple I2C device parallely on same pin. Actually A4 & A5 pins are SDA & SCL so same can be connected on A4 & A5 too(Check Arduino pinout first). There will be a jumper on I2C module which is used to turn on-off LCD backlight. You will find a potentiometer which is actually contrast set for LCD.

Code for I2C connection method:

You can download above code from here.

I2C module & its interface with LCD looks like this:

One more difference between both connection type is library. You need different library for I2C which is ‘LiquidCrystal_I2C’ and it is available here.

Before proceeding for I2C code download, you need to confirm I2C address. Each I2C module has an address which we need to mention in second line LiquidCrystal_I2C  lcd(0x3F, 16, 2); Here i’ve mentioned 0x3F because my I2C module has this address. To know your I2C module address you may need to run I2C scanner program in your Arduino and get I2C address on serial monitor like ths;

I2C scanner

Use this tutorial to know the address of your I2C device. Get I2C address, put in above code & eureka…!!!

After connecting LCD with Arduino you can display sensor & variable values, text messages & also can set values by interfacing keypad with Arduino. Give your feedback about this tutorial in Contact, Your feedback will be appreciated.

Join on FacebookTwitterInstagram & Telegram for latest updates.

HC-05 Serial Bluetooth Module interface with Arduino

HC‐05 bluetooth module is an easy to use Bluetooth SPP (Serial Port Protocol) module, designed for transparent wireless serial connection setup & can easily interface with Arduino. The HC-05 Bluetooth Module can be used in a Master or Slave configuration, making it a great solution for wireless communication, especially for Arduino. This serial port Bluetooth module is fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) 3 Mbps Modulation with complete 2.4 GHz radio transceiver and base-band. It uses CSR Bluecore 04External single chip Bluetooth system with CMOS technology and with AFH (Adaptive Frequency Hopping Feature).

HC05

The Bluetooth module HC-05 is a MASTER/SLAVE module. By default the factory setting is SLAVE. The Role of the module (Master or Slave) can be configured only by AT commands. The slave modules cannot initiate a connection to another Bluetooth device, but can accept connections. Master module can initiate a connection to other devices. The user can use it simply for a serial port replacement to establish connection between MCU and GPS, PC to your embedded project, etc. Refer Datasheet/User Manual & AT command’s list.

Features

  • Typical ‐80 dBm sensitivity
  • Up to +4Bm RF transmit power
  • 3.3 to 5 V I/O and RoHS Compliant
  • PIO (Programmable Input/Output) control
  • UART interface with programmable baud rate
  • Inbuilt/Integrated antenna
  • Auto‐connect to the last device on power as default
  • Permit pairing device to connect as default
  • Auto‐pairing pin code: ”1234” as default (which can be changed)
  • CSR Bluetooth Chip Solution
  • Bluetooth Spec v2.0 EDR Compliant with V2.0.E.2 of specification for both 2Mbps and 3Mbps modulation modes
  • Full Speed Bluetooth Operation with Full Piconet Support and Scatternet Support
  • Support for 8Mbit External Flash On-board
  • Support for 802.11 Coexistence

Pinout

HC05 Pin

State: It is status indicator pin. When the HC05 is not connected to or not paired with any other Bluetooth device, signal at this pin goes Low. During this state the on-board LED flashes continuously which indicates that the module is not paired with any device. When HC05 is paired or connected with any Bluetooth device, the pin status goes High. During this state, on-board LED blinks with a constant delay say for example 2 seconds delay which indicates that the module is paired.

RXD: Receive pin of UART interface for communication

TXD: Transmit pin of UART interface for communication

GND: Ground pin

Vcc: Supply voltage of 3.3V or 5VDC

Key (or EN): When this pin is high, the module is disabled & will not be connected with any module. When this pin is open or connected to ground or kept open, the module is enabled & it can be connected/communicate.

Apart from pins, you will find a small push button on HC05. When you press the button for 1 second, HC05 will enable AT command mode. During AT command mode you can change different parameters of HC05, but while changing parameters the HC05 shouldn’t be connected/paired with any device.

Arduino Connection

HC05 Arduino
Vcc 5V
GND GND
TXD D10
RXD D11

Normally, people connects HC05 TXD & RXD to Arduino RX(D0) & TX(D1), but in that case if you want to upload any code using USB port then you have to remove connection from D0 & D1 otherwise you will get code upload error. To avoid this issue there is one best solution as library called ‘SoftwareSerial’. Using  SoftwareSerial library we can configure any two DIO as Tx & Rx. In above connection diagram, HC05 Tx & Rx are connected to Arduino pins D10 & D11 which to be assigned as Rx & Tx respectively.

Arduino Code

You can download above code from here.

Explanation of code:

#include : As you can see SoftwareSerial library is included, it is available in Arduino IDE

SoftwareSerial BTserial(10, 11); : anyname(RX, TX); i’ve give name BTserial, D10 pin as RX & D11 as Tx

char data; : variable where incoming data will be stored, for better execution data will be first stored in a variable then will be processed.

Serial.begin(9600); begin serial communication with Arduino IDE

Serial.println(“Beat Your Bit”); print custom message on serial monitor to confirm serial communication has been initiated

BTserial.begin(9600); begin serial communication using dedicated pins (D10 & D11)

BTserial.println(“Beat Your Bit”); transmit custom message on HC05 paired device to confirm serial communication with HC05 has been initiated

if (BTserial.available()) [if any data available from HC05 then]
data=BTserial.read(); [store received data in ‘data’ variable]
Serial.print(data); [print received data on serial monitor of Arduino IDE]
if (Serial.available()) [if any data available from serial monitor then]
data=Serial.read(); [store received data in ‘data’ variable]
BTserial.print(data); [transmit received data on HC05]

As explained, this code exchanges data between HC05 and Arduino IDE serial monitor. We can see data received on serial monitor but to read the data received on HC05, we have to use an android app or any terminal application which can be connected with HC05 using Bluetooth. Here we are going to use android app to test Arduino-HC05 connection & data exchange. I used Arduino Bluetooth Control app which have many add on features & easy to use. It has serial terminal, arrow keys, buttons, slider, accelerometer & voice control features.

Connect circuit as shown in connection diagram, upload code and connect/pair HC05 with your smartphone. If you are using/pairing HC05 for first time then default pairing PIN may be 1234, you can change it later using AT commands. Open Arduino Bluetooth Control App & select paired HC05. Open terminal windows in app & serial monitor in Arduino IDE with mentioned baud-rate. Write any text in Arduino IDE serial monitor & press enter, you will receive same text in terminal window of Arduino Bluetooth Control app. Vice versa, write in app and send it to Arduino IDE serial monitor.

Change HC05 settings

You can change HC05 default settings like Bluetooth display name, pairing PIN, baud rate etc. As mentioned in Pin-out details, you have to put HC05 in AT command mode by pressing the push button while power up the module but make sure it is not connected with any other Bluetooth device.

How to put HC05 in AT command mode: 

1. Disconnect HC05 form power, Remove the +5V connection to HC05.
2. Press and hold the push button switch on HC05
3. Re-connect HC05 Vcc to +5V (while still pressing the button switch), HC05 on-board LED should turn ON.
4. Release the push button switch and the LED should be blinking at interval of two seconds. It indicates that your are now in AT command mode. Now open serial monitor & give AT commands from there.

Some useful AT commands:

AT : Simple feedback request. If communication is working fine then it will return “OK”

AT+VERSION : This returns the firmware version.
For Example:
“+VERSION:2.0-20100601
OK”

AT+STATE : This returns the current state of the module.
For Example:
“+STATE:INITIALIZED
OK”

AT+ROLE : Valid values are 0~Slave, 1~Master, 2~Slave-Loop.
Return example:
“+ROLE:0
OK”
(To change to Master Mode, enter AT+ROLE=1, returns “OK”)

AT+UART : It returns the baud rate used by the HC05 in communication mode. Default it will be 9600 mostly.
Return example:
“+UART:9600,0,0
OK”
(To change the baud rate to 19200 : AT+UART=19200,0,0. Returns “OK”)

AT+NAME : The command AT+NAME? only works in AT command mode. If HC05 is not responding on AT+NAME? then put HC05 in AT command mode as procedure mentioned in tutorial.
Return when AT+NAME? is given:
“+NAME:HC-05
OK”
(To change name : AT+NAME=BeatYourBit, Returns “OK”)

You can find all AT commands list from here.

I hope you liked this tutorial, now you can add Bluetooth interface in your project & expand the features. Further you can display values on display, data exchange with another wireless modules like RF & WiFi. Give your feedback about this tutorial in Contact, Your feedback will be appreciated.

Subscribe BYB on FacebookTwitterInstagram & Telegram for latest updates.

LM35 temperature sensor interface with Arduino

LM35 is a precision IC temperature sensor which gives an output proportional to the temperature in °C. The operating temperature range is from -55°C to 150°C.  Compared to thermistor, LM35 can measure temperature more accurately hence better for Arduino projects. The LM35’s low output impedance, linear output, and precise inherent calibration make interfacing to readout or control circuitry especially easy & useful in may applications like power supplies, battery management, temperature control appliances etc. LM35 sensor can easily interface with Arduino.

Features

  • No Calibration Required: Calibrated Directly in Celsius (Centigrade)
  • Linear scale: Linear + 10-mV/°C Scale Factor (Non-linearity Only ±¼°C Typical)
  • Good accuracy: 0.5°C Ensured Accuracy (at 25°C)
  • Operating range: Rated for Full −55°C to 150°C Range
  • Cheaper: Low-Cost Due to Wafer-Level Trimming
  • Operating voltage: Operates From 4 V to 30 V
  • Current consumption: Less Than 60-μA Current Drain
  • Low Self-Heating: 0.08°C in Still Air (0.1°C Max.)
  • Low-Impedance Output: 0.1 Ω for 1-mA Load

(For more detail, click here for datasheet)

Connection with Arduino

LM35 has 3 pins, +Vs (1) & GND (3) for power supply and OUT (2) which gives analog output. It consumes approximately +5VDC. The output pin provides an analog voltage output that is linearly proportional to the Celsius (centigrade) temperature. Pin 2 gives an output of 1 millivolt per 0.1°C (10 mV per degree), So to get the degree value in Celsius  voltage output to be divide it by 10.

Arduino Code

You can download this code from here.

How this code works: Arduino will read temperature from LM35 on analog pin in line temp = analogRead(tempPin);. The reading received on analog pin is actually millivolts scaled from 0-5000mV for 0-5VDC which need to be converted in Celsius in line  temp = temp * 0.48828125;. In this, 0.48828125=(+Vcc*1000/1024)/10 Where +Vcc is the supply voltage +5V, 1024 is 2^10, value where the analog value can be represented by Arduino the actual voltage obtained by Voltage_Get/1024. 1000 is used to change the unit from V to mV & 10 is a constant as each 10 mV is directly proportional to 1 Celsius in LM35. So (5.0 * 1000 / 1024) / 10 = 0.48828125. Rest of the lines are to print temperature reading on serial monitor. Upload the code in Arduino, open serial monitor & get temperature reading from LM35 at every one second.

In further expansion to this you can add LCD to display values & relay & make temperature control equipment. I hope this tutorial will be helpful for temperature measurement in your Arduino projects. In future I will upload more tutorials with LCD and such sensor interfaces with Arduino. Give your feedback about this tutorial in Contact, Your feedback will be appreciated.

Subscribe BYB on FacebookTwitterInstagram & Telegram for latest updates.