Categories

B4R Arduino TM1637 7 segment display example

A few of the code examples and projects on this site use modules containing the Tm1638 driver chip, I was interested in this one which is the TM1637 which appears to be a more basic version which can only control a display, the other one can also control LEDs, buttons and two displays at the same time.

This is a common anode 4-digit tube display module which uses the TM1637 driver chip; Only 2 connections are required to control the 4-digit 8-segment displays

Here is the module

Features of the module

  • Display common anode for the four red LED
  • Powered supply by 3.3V/5V
  • Four common anode tube display module is driven by IC TM1637
  • Can be used for Arduino devices, two signal lines can make the MCU control 4 8 digital tube. Digital tube 8 segment is adjustable

Here is how to hook the module up

 

Code Example

Library is available from here – https://www.b4x.com/android/forum/threads/tm1637-4-digits-display.67733/

This is the examples

Sub Process_Globals
Public Serial1 As Serial
Private tm As TM1637Display
Private timer1 As Timer
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
tm.Initialize(2, 3)
timer1.Initialize("timer1_Tick", 1000)
timer1.Enabled = True
End Sub
Sub Timer1_Tick
tm.ShowNumberDec2(Millis / 1000, True, 4, 0)
End Sub

Links

4 Bits Digital Tube LED Display Module With Clock Display TM1637 for Arduino Raspberry PI FZ1435

B4R Arduino and BH1750 Ambient Light Sensor example

BH1750FVI is an digital Ambient Light Sensor IC for I2C bus interface. This IC is the most suitable to obtain the ambient light data for adjusting LCD and Keypad backlight power of Mobile phone. It is possible to detect wide range at High resolution.  1 – 65535 lux (lx).

Features

1) I2C bus Interface ( f / s Mode Support )
2) Spectral responsibility is approximately human eye response
3) Illuminance to Digital Converter
4) Wide range and High resolution. ( 1 – 65535 lx )
5) Low Current by power down function
6) 50Hz / 60Hz Light noise reject-function
7) 1.8V Logic input interface
8) No need any external parts
9) Light source dependency is little. ( ex. Incandescent Lamp. Fluorescent Lamp. Halogen Lamp. White LED. Sun Light )
10) It is possible to select 2 type of I2C slave-address.
11) Adjustable measurement result for influence of optical window ( It is possible to detect min. 0.11 lx, max. 100000 lx by using this function. )
12) Small measurement variation (+/- 20%)
13) The influence of infrared is very small.

What is lux

The lux (symbol: lx) is the SI unit of illuminance and luminous emittance, measuring luminous flux per unit area. It is equal to one lumen per square metre. In photometry, this is used as a measure of the intensity, as perceived by the human eye, of light that hits or passes through a surface. It is analogous to the radiometric unit watts per square metre, but with the power at each wavelength weighted according to the luminosity function, a standardized model of human visual brightness perception. In English, “lux” is used in both singular and plural

Typical Lux values

These were taken from Wikipedia

Examples
Illuminance Surfaces illuminated by:
0.0001 lux Moonless, overcast night sky (starlight)
0.002 lux Moonless clear night sky with airglow
0.27–1.0 lux Full moon on a clear night[3][4]
3.4 lux Dark limit of civil twilight under a clear sky
50 lux Family living room lights (Australia, 1998)
80 lux Office building hallway/toilet lighting]
100 lux Very dark overcast day
320–500 lux Office lighting
400 lux Sunrise or sunset on a clear day.
1000 lux Overcast day; typical TV studio lighting
1000025000 lux Full daylight (not direct sun)
32000100000 lux Direct sunlight

Typically to use this sensor you will need to purchase a module, here is a picture of one

 

For those that are interested this is a schematic of the module

 

 

Layout

An easy module to connect being an I2C one

 

Code

The library and this code example are available from – https://www.b4x.com/android/forum/threads/rbh1750fvi-digital-ambient-light-sensor.75663/

Sub Process_Globals
Public Serial1 As Serial
Private bh As BH1750FVI
Private Timer1 As Timer
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
'Init the sensor with low I2C address 0x23 and the recommended high resolution mode
bh.Initialize(bh.Device_Address_L, bh.Continuous_H_resolution_Mode)
Timer1.Initialize("Timer1_Tick", 1000)
Timer1.Enabled = True
End Sub
Sub Timer1_Tick
Log(bh.LightIntensity, " lx")
End Sub

 

Testing

108 lx
102 lx
358 lx
357 lx
7 lx
1 lx
1 lx
167 lx

 

Links

BH1750 BH1750FVI light intensity illumination module 3V-5V

B4R Arduino and ADXL335 accelerometer example

The ADXL335 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 ±3 g. 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 ZOUT pins. 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.

Here is a typical module that makes it easy to work with the ADXL335

 

 

Features:

Name: ADXL335 module (triaxial accelerometer analog output)
Model: GY-61
Power supply :3-5v
Analog X, Y, Z three-axis output

Schematic

The following layout shows how to wire the ADXL335 module up to an Arduino UNO

 

 

 

Code

You need to install the following library https://github.com/Tijndagamer/ADXL335-Arduino

 

Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Public timer1 As Timer
Public adx_xvalue As Float
Public adx_yvalue As Float
Public adx_zvalue As Float
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
RunNative("setup",Null)
timer1.Initialize("timer1_Tick",1000)
timer1.Enabled = True
End Sub
Private Sub Timer1_Tick
RunNative("loop",Null)
Log("X is: ", adx_xvalue)
Log("Y is: ", adx_yvalue)
Log("Z is: ", adx_zvalue)
End Sub
#if C
#include "ADXL335.h"
ADXL335 adxl335(A0, A1, A2, 3.3);
void setup(B4R::Object* o){
}
void loop (B4R::Object* o) {
b4r_main::_adx_xvalue =adxl335.readX();
b4r_main::_adx_yvalue =adxl335.readY();
b4r_main::_adx_zvalue =adxl335.readZ();
}
#End if

 

Output

X is: -1.6258
Y is: -2.0458
Z is: -1.7403
X is: -1.0790
Y is: -2.2997
Z is: -1.2325
X is: -2.1532
Y is: -1.1180
Z is: -1.3301
X is: -0.9227
Y is: -1.0594
Z is: -1.0079
X is: -0.9422
Y is: -1.4989
Z is: -1.4180
X is: -0.8543
Y is: -1.7528
Z is: -1.7598

 

Links

http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL335.pdf

The sensor costs under $2

GY-61 ADXL335 Module Triaxial Acceleration Gravity Angle Sensor

B4R Arduino and SHT11 digital humidity sensor example

The SHT1x digital humidity sensor is a reflow solderable sensor. The SHT1x series consists of a low-cost version with the SHT10 humidity sensor, a standard version with the SHT11 humidity sensor, and a high-end version with the SHT15 humidity sensor. As with every other Sensirion sensor type from the SHTxx humidity sensor family, they are fully calibrated and provide a digital output.

The humidity sensors are seamlessly coupled to a 14-bit-analog-to-digital converter and a serial interface circuit. This results in superior signal quality, a fast response time, and insensitivity to external disturbances (EMC).

One thing to note is that these sensors have been effectively replaced by others in sensirion’s range such as the SHT31 but they still work and have good performance for hobbyists

Layout

 

Code

You need to install the library from – https://github.com/practicalarduino/SHT1x

#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Public timer1 As Timer
Public sht11humi As Float
Public sht11tempc As Float
Public sht11tempf As Float
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
RunNative("setup",Null)
timer1.Initialize("timer1_Tick",1000)
timer1.Enabled = True
End Sub
Private Sub Timer1_Tick
RunNative("loop",Null)
Log("Celsius is: ", sht11tempc, "°C")
Log("Fahrenheit is: ", sht11tempf, "°C")
Log("Humidity is: ", sht11humi, " %")
End Sub
#if C
#include "SHT1x.h"
#define dataPin 10
#define clockPin 11
SHT1x sht1x(dataPin, clockPin);
void setup(B4R::Object* o){
}
void loop (B4R::Object* o) {
float temp_c;
float temp_f;
float humidity;
b4r_main::_sht11humi =sht1x.readHumidity();
b4r_main::_sht11tempc =sht1x.readTemperatureC();
b4r_main::_sht11tempf =sht1x.readTemperatureF();
}
#End if

 

Testing

Celsius is: 18.9300°C
Fahrenheit is: 67.2260°C
Humidity is: 42.7808 %
Celsius is: 21.4300°C
Fahrenheit is: 71.6900°C
Humidity is: 43.6952 %
Celsius is: 23.3600°C
Fahrenheit is: 74.8400°C
Humidity is: 47.3777 %
Celsius is: 24.7400°C
Fahrenheit is: 77.1440°C
Humidity is: 51.5196 %
Celsius is: 25.8100°C
Fahrenheit is: 78.9260°C
Humidity is: 54.9967 %
Celsius is: 26.6800°C
Fahrenheit is: 80.3840°C
Humidity is: 57.6510 %

 

Links

SHT11 Digital Temperature and Humidity Sensor,Single bus output temperature and humidity module

B4r and Arduino SHT21 humidity and temperature sensor example

The digital SHT2x humidity sensor series is used in high volumes in a wide variety of applications and has today become the de facto industry standard. The SHT2x series consists of a low-cost version with the SHT20 humidity sensor, a standard version with the SHT21 humidity sensor, and a high-end version with the SHT25 humidity sensor. Its an I2C device so again is very simple to connect to any arduino

Features

Size 3 x 3 x 1.1 mm
Output I²C digital, PWM, SDM
Supply voltage range 2.1 to 3.6 V
Energy consumption 3.2µW (at 8 bit, 1 measurement / s)
RH operating range 0 – 100% RH
T operating range -40 to +125°C (-40 to +257°F)
RH response time 8 sec (tau63%)

This is the breakout for the sensor that I bought.

Here is a simple schematic, again be careful as Vcc is 3.3v with this device

 

Schematic

 

Lets look at the required libraries and a basic code example, there is not much to this to be honest most of the work is done in the library

 

Code

 

You need to install the following library – https://github.com/markbeee/SHT21

#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Public timer1 As Timer
Public sht21humi As Float
Public sht21temp As Float
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
RunNative("setup",Null)
timer1.Initialize("timer1_Tick",1000)
timer1.Enabled = True
End Sub
Private Sub Timer1_Tick
RunNative("loop",Null)
Log("Temperature is: ", sht21temp, "°C")
Log("Humidity is: ", sht21humi, " %")
End Sub
#if C
#include <Wire.h>
#include "SHT21.h"
SHT21 SHT21;
void setup(B4R::Object* o){
SHT21.begin();
}
void loop (B4R::Object* o) {
b4r_main::_sht21humi =SHT21.getHumidity();
b4r_main::_sht21temp =SHT21.getTemperature();
}
#End if

 

Output

In the log view

Temperature is: 20.9541°C
Humidity is: 47.1311 %
Temperature is: 25.0403°C
Humidity is: 48.8706 %
Temperature is: 26.7027°C
Humidity is: 51.6553 %
Temperature is: 27.8289°C
Humidity is: 50.8161 %
Temperature is: 28.6547°C
Humidity is: 50.0150 %
Temperature is: 29.2982°C
Humidity is: 50.1371 %
Temperature is: 29.7915°C
Humidity is: 49.0003 %
Temperature is: 30.2420°C
Humidity is: 49.0079 %
Temperature is: 30.1562°C
Humidity is: 59.5365 %

 

Links

these come in at about $7 for a useful breakout board with this sensor

Humidity Sensor – SHT21 Breakout Board