Categories

A 1.8 inch TFT Full Color LCD Display Module with Adapter Board for Arduino UNO

In this article we look a shield which allows you to connect an Arduino Esplora TFT LCD to an Arduino Uno or Mega

The Graphic LCD screen is a backlit TFT LCD screen with headers. You can draw text, images, and shapes to the screen with the GLCD library.
There is an onboard micro-SD card slot on the back of the screen that can, among other things, store bitmap images for the screen to display.
The screen is 1.77″ diagonal, with 160 x 128 pixel resolution.
The TFT library interfaces with the screen’s controller through SPI when using the TFT library.
The screen runs on +5 VDC
The micro-SD slot is accessible through the SD card library.
The LED backlight is dimmable by PWM.

Here is a picture of the shield and TFT

Parts

Only $6 for the shield and TFT

PartLink
Arduino UnoArduino UNO R3
TFT shield and LCD1.8 inch TFT Full Color LCD Display Module with LCD Adapter Board Expansion Board

Code

The TFT uses the built-in TFT library which comes with many examples that you can use to test with. The easiest one is the TFTDisplayText example

#include <TFT.h> // Arduino LCD library
#include <SPI.h>
// pin definition for the Uno
#define cs 10
#define dc 9
#define rst 8
// pin definition for the Leonardo
// #define cs 7
// #define dc 0
// #define rst 1
// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);
// char array to print to the screen
char sensorPrintout[4];
void setup() {
// Put this line at the beginning of every sketch that uses the GLCD:
TFTscreen.begin();
// clear the screen with a black background
TFTscreen.background(0, 0, 0);
// write the static text to the screen
// set the font color to white
TFTscreen.stroke(255, 255, 255);
// set the font size
TFTscreen.setTextSize(2);
// write the text to the top left corner of the screen
TFTscreen.text("Sensor Value :\n ", 0, 0);
// ste the font size very large for the loop
TFTscreen.setTextSize(5);
}
void loop() {
// Read the value of the sensor on A0
String sensorVal = String(analogRead(A0));
// convert the reading to a char array
sensorVal.toCharArray(sensorPrintout, 4);
// set the font color
TFTscreen.stroke(255, 255, 255);
// print the sensor value
TFTscreen.text(sensorPrintout, 0, 20);
// wait for a moment
delay(250);
// erase the text you just wrote
TFTscreen.stroke(0, 0, 0);
TFTscreen.text(sensorPrintout, 0, 20);
}
Share

Arduino Uno and BMP388 barometric pressure sensor example

Another expensive visit to Aliexpress made me find this sensor listed by one of the vendors – it is a BMP388 by Bosch Sensortec, so lets crack on and try this out with an Arduino Uno again

On with the manufacturers blurb

BMP388 Information

The BMP388 is a very small, low-power and low-noise 24 bit absolute barometric pressure sensor. It enables accurate altitude tracking and is specifically suited for drone applications. The best-in-class TCO of the BMP388 between 0-65°C for accurate altitude measurement over a wide temperature range greatly enhances the drone flying experience by making accurate steering easier.

It is compatible for use with other Bosch sensors, including BMI088 for better performance, robustness and stability.

The BMP388 sensor offers outstanding design flexibility, providing a single package solution that is easy to integrate into other existing and upcoming devices such as smart homes, industrial products and wearables.

It is more accurate than its predecessors, covering a wide measurement range from 300 hPa to 1250 hPa. BMP388 exhibits an attractive price-performance ratio coupled with low power consumption. It is available in a compact 10-pin 2.0 x 2.0 x 0.75 mm³ LGA package with metal lid.

  • Operating voltage: 3.3V/5V
  • Communication interface: I2C/SPI
  • Barometric pressure operation range: 300~1250hPa
  • Barometric pressure absolute accuracy: ±0.40hPa (@900~1100hPa, 25~40℃)
  • Barometric pressure relative accuracy: ±0.08hPa (@900~1100hPa, 25~40℃)
  • Temperature coefficient offset: ±0.75Pa/K (@700~1100hPa, -20~65℃))
  • Temperature absolute accuracy: ±0.5℃ (0~65℃)
  • Possible resolution: 0.016Pa (high precision mode)
  • Possible sampling rate: 200Hz
  • Operating voltage: -40~85℃

If you purchase a module they will have a 3.3v regulator on board, you will also have the option of I2C or SPI, here is the module that I located.

Parts Required

I connected a sensor shield to an Arduino and then the sensor via connecting wire

NameLink
Arduino UnoUNO R3 CH340G/ATmega328P, compatible for Arduino UNO
BMP38824-bit low noise BMP388 digital temperature atmospheric pressure sensor
Connecting wireFree shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire
sensor shieldExpansion IO Board Sensor Shield

Schematic/Connection

I decided to use the sensor in I2C mode – I also decided to use 3.3v from the Arduino Uno but could have quite easily used 5v from the board

arduino and bmp388 layout

arduino and bmp388 layout

Code Example

I used the library from adafruit – https://github.com/adafruit/Adafruit_BMP3XX. 

This library can be installed via the library manager. This is the default example and I have removed some of the SPI code and code comments since I was using the sensor in I2C mode

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP3XX.h"
 
 
#define SEALEVELPRESSURE_HPA (1013.25)
 
Adafruit_BMP3XX bmp; // I2C
 
 
void setup() {
  Serial.begin(115200);
  while (!Serial);
  Serial.println("BMP388 test");
 
  if (!bmp.begin()) {
    Serial.println("Could not find a valid BMP3 sensor, check wiring!");
    while (1);
  }
 
  // Set up oversampling and filter initialization
  bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
  bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);
  bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
  //bmp.setOutputDataRate(BMP3_ODR_50_HZ);
}
 
void loop() {
  if (! bmp.performReading()) {
    Serial.println("Failed to perform reading :(");
    return;
  }
  Serial.print("Temperature = ");
  Serial.print(bmp.temperature);
  Serial.println(" *C");
 
  Serial.print("Pressure = ");
  Serial.print(bmp.pressure / 100.0);
  Serial.println(" hPa");
 
  Serial.print("Approx. Altitude = ");
  Serial.print(bmp.readAltitude(SEALEVELPRESSURE_HPA));
  Serial.println(" m");
 
  Serial.println();
  delay(2000);
}

 

Output

Open the serial monitor and you should see something like this

Temperature = 24.95 *C
Pressure = 1011.79 hPa
Approx. Altitude = 12.14 m

Temperature = 24.98 *C
Pressure = 1011.81 hPa
Approx. Altitude = 12.01 m

Temperature = 25.00 *C
Pressure = 1011.81 hPa
Approx. Altitude = 11.96 m

 

Links

 

 

Summary

A nice little sensor but at just over $8 but one again there are cheaper sensors available which have the same functionality and for most projects have acceptable performance.

Share

Arduino Uno and HY-SRF05 ultrasonic sensor example

The HY-SRF05 is an ultrasonic emitter/receiver used to measure distance with a precision of ~0.3cm. It sends out a 40 KHz square wave signal that reflects on objects in front of the sensor. This signal is then read back by the sensor and the duration of the received signal is reflected on the ECHO pin.

Features

Supply voltage: 4.5V to 5.5V
Supply current: 10 to 40mA
Trigger pin format: 10 uS digital pulse
Sound frequency: 40 KHz
Echo pin output: 0V-VCC
Echo pin format: digital

How to use

Send a 10Us wide pulse (low to high) to the Trigger pin.
Monitor the ECHO pin.
When the ECHO pin goes HIGH, start a timer.
When the ECHO pin goes LOW, stop the timer and save the elapsed time.
Use the elapsed time in the following formula to get the distance in cm:

Distance (in cm) = (elapsed time * sound velocity (340 m/s)) / 100 / 2

We will see a code example later

 

Parts List

NameLink
Arduino UnoUNO R3 CH340G/ATmega328P, compatible for Arduino UNO
HY-SRF05HY-SRF05 SRF05 Ultrasonic Ranging Module Ultrasonic Sensor
connecting wireFree shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

Layout

 

arduino and HY-SRF05

arduino and HY-SRF05

 

Code

/*
VCC to +5V
GND to ground
TRIG to digital pin 12
ECHO to digital pin 13
*/
 
const int TRIG_PIN = 12;
const int ECHO_PIN = 13;
 
void setup()
{
  // initialize serial communication:
  Serial.begin(9600);
  pinMode(TRIG_PIN,OUTPUT);
  pinMode(ECHO_PIN,INPUT);
}
 
void loop()
{
  long duration, distanceCm, distanceIn;
 
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  duration = pulseIn(ECHO_PIN,HIGH);
 
  // convert the time into a distance
  distanceCm = duration / 29.1 / 2 ;
  distanceIn = duration / 74 / 2;
 
  if (distanceCm <= 0)
  {
    Serial.println("Out of range");
  }
  else
  {
    Serial.print(distanceIn);
    Serial.print("in: ");
    Serial.print(distanceCm);
    Serial.print("cm");
    Serial.println();
  }
  delay(1000);
}

 

Output

Open the serial monitor and you will something like this depending how close the module is to an object

I was moving the sensor away from an object

4in, 10cm
3in, 9cm
4in, 10cm
4in, 10cm
4in, 10cm
4in, 10cm
4in, 12cm
4in, 12cm
4in, 12cm

Share

ADXL337 accelerometer Arduino Uno example

In this article we connect an ADXL337 accelerometer to an Arduino Uno

The ADXL337 is a small, thin, low power, complete 3-axis accelerometer with signal conditioned voltage outputs. The product measures acceleration with a minimum full-scale range of ±3g. It can measure the static acceleration of gravity in tiltsensing applications, as well as dynamic acceleration resulting from motion, shock, or vibration.

The user selects the bandwidth of the accelerometer using the CX, CY, and CZ capacitors at the XOUT, YOUT, and ZOUTpins. Bandwidths can be selected to suit the application, with a range of 0.5 Hz to 1600 Hz for X and Y axes, and a range of 0.5 Hz to 550 Hz for the Z axis.

 

Parts List

NameLink
Arduino UnoUNO R3 CH340G/ATmega328P, compatible for Arduino UNO
ADXL3373-axis ADXL337 GY-61 Replacement ADXL335 Module Analog Output Accelerometer
Connecting wireFree shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

Schematic

arduino and adxl337

arduino and adxl337

 

Code

No libraries required – this is a sparkfun example

// Make sure these two variables are correct for your setup
int scale = 3; // 3 (±3g) for ADXL337, 200 (±200g) for ADXL377
 
 
void setup()
{
  // Initialize serial communication at 115200 baud
  Serial.begin(115200);
}
 
// Read, scale, and print accelerometer data
void loop()
{
  // Get raw accelerometer data for each axis
  int rawX = analogRead(A0);
  int rawY = analogRead(A1);
  int rawZ = analogRead(A2);
 
  // Scale accelerometer ADC readings into common units
  // Scale map depends on if using a 5V or 3.3V microcontroller
  float scaledX, scaledY, scaledZ; // Scaled values for each axis
  scaledX = mapf(rawX, 0, 675, -scale, scale); // 3.3/5 * 1023 =~ 675
  scaledY = mapf(rawY, 0, 675, -scale, scale);
  scaledZ = mapf(rawZ, 0, 675, -scale, scale);
 
  // Print out raw X,Y,Z accelerometer readings
  Serial.print("X: "); Serial.println(rawX);
  Serial.print("Y: "); Serial.println(rawY);
  Serial.print("Z: "); Serial.println(rawZ);
  Serial.println();
 
  // Print out scaled X,Y,Z accelerometer readings
  Serial.print("X: "); Serial.print(scaledX); Serial.println(" g");
  Serial.print("Y: "); Serial.print(scaledY); Serial.println(" g");
  Serial.print("Z: "); Serial.print(scaledZ); Serial.println(" g");
  Serial.println();
 
  delay(2000); // Minimum delay of 2 milliseconds between sensor reads (500 Hz)
}
 
// Same functionality as Arduino's standard map function, except using floats
float mapf(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

 

Output

Open the serial monitor and you will see something like this

X: 384
Y: 340
Z: 281

X: 0.41 g
Y: 0.02 g
Z: -0.50 g

X: 410
Y: 345
Z: 345

X: 0.64 g
Y: 0.07 g
Z: 0.07 g

 

Links

https://www.analog.com/media/en/technical-documentation/data-sheets/ADXL337.pdf

Share