Categories

Follow Us

Arduino and ISL29125 RGB color light sensor

In this example we look at the ISL29125 RED, GREEN and BLUE color light sensor

Here is some info about the sensor

The ISL29125 is a low power, high sensitivity, RED, GREEN and BLUE color light sensor (RGB) with an I2 C (SMBus compatible) interface. Its state-of-the-art photodiode array provides an accurate RGB spectral response and excellent light source to light source variation (LS2LS). The ISL29125 is designed to reject IR in light sources allowing the device to operate in environments from sunlight to dark rooms. The integrating ADC rejects 50Hz and 60Hz flicker caused by artificial light sources. A selectable range allows the user to optimize sensitivity suitable for the specific application.

In normal operation mode the device consumes 56µA, which reduces to 0.5µA in power-down mode. The ISL29125 supports hardware and software user programmable interrupt thresholds. The Interrupt persistency feature reduces false trigger notification. The device operates on supplies (VDD) from 2.25V to 3.63V, I2 C supply from 1.7V to 3.63V, and operating temperature across the -40°C to +85°C range.

FEATURES

  • 56µA operating current, 0.5µA shutdown current
  • Selectable range (Via I2C)
  • I2C (SMBus compatible) output
  • ADC resolution 16 bits
  • Programmable interrupt windows
  • Two optical sensitivity ranges
  • Range 0 = 5.7m lux to 375 lux
  • Range 1 = 0.152 lux to 10,000 lux
  • Operating power supply 2.25 to 3.63V
  • I2C power supply 1.7V to 3.63V
  • 6 Ld ODFN (1.65×1.65×0.7mm) package

 

Connection

 

Arduino Uno CJMCU-0401 module
3v3 Vcc
Gnd Gnd
A4 – SDA SDA
A5 – SCL SCL

Parts List

Here are the parts I used

Part name Link
Arduino Uno UNO R3 CH340G/ATmega328P, compatible for Arduino UNO
ISL29125 module ISL29125 Red/Green/Blue RGB Color Light Sensor with IR Blocking Filter Module
Dupont cable Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire Dupont cablefor Arduino

 

Code

This example requires the https://github.com/sparkfun/SparkFun_ISL29125_Breakout_Arduino_Library

#include <Wire.h>
#include "SparkFunISL29125.h"
 
// Declare sensor object
SFE_ISL29125 RGB_sensor;
 
void setup()
{
  // Initialize serial communication
  Serial.begin(115200);
 
  // Initialize the ISL29125 with simple configuration so it starts sampling
  if (RGB_sensor.init())
  {
    Serial.println("Sensor Initialization Successful\n\r");
  }
}
 
// Read sensor values for each color and print them to serial monitor
void loop()
{
  // Read sensor values (16 bit integers)
  unsigned int red = RGB_sensor.readRed();
  unsigned int green = RGB_sensor.readGreen();
  unsigned int blue = RGB_sensor.readBlue();
 
  // Print out readings, change HEX to DEC if you prefer decimal output
  Serial.print("Red: "); Serial.println(red,HEX);
  Serial.print("Green: "); Serial.println(green,HEX);
  Serial.print("Blue: "); Serial.println(blue,HEX);
  Serial.println();
  delay(2000);
}

 

Output

Open the serial monitor – this is what you should expect to see

 

 

Links

 

Share

Arduino and CJMCU-0401 example

In this example we look at the CJMCU-0401, this is the module in question its a 4-bit Button Capacitive Touch Proximity Sensor With Self-locking Function

Description:

CJMCU-0401 is a touch IC designed with capacitive sensing principle.
Its stable sensing method can be applied to a variety of electronic products, the panel dielectric can be completely insulated material,
designed to replace the traditional mechanical structure switch or ordinary buttons.
Provides four touch inputs and four direct output pins and four LED indicators.

Features:

1. Operating voltage: 2.0V ~ 5.5V
2. The highest power consumption is 11.5uA, low power mode is only 4uA ( in 3V and no load)
3. External configuration pin is set to multiple modes
4. High reliability, the chip built-in debounce circuit, which can effectively prevent external noise interference caused by the malfunction
5. Can be used for glass, ceramics, plastics and other media surface
6. With automatic calibration function, when no keys are touched, the system recalibration cycle is about 4.0 Sec

The CJMCU-0401 uses a CT8224

Connection

 

Arduino Uno CJMCU-0401 module
5v Vcc
Gnd Gnd
D4 Out1
D5 Out2
D6 Out3
D7 Out4

Parts List

Here are the parts I used

Part name Link
Arduino Uno UNO R3 CH340G/ATmega328P, compatible for Arduino UNO
CJMCU-0401 1PC CJMCU-0401 4-bit Button Capacitive Touch Proximity Sensor With Self-locking Function For Arduino Sensor Board
Dupont cable Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire Dupont cablefor Arduino

 

Code

This example does not require any libraries

const int Pins[4] = {4, 5, 6, 7};
 
void setup() 
{
  Serial.begin(9600);
  for (int i = 0; i < 4; i++) 
  {
    pinMode(Pins[i], INPUT_PULLUP);
  }
}
 
void loop() 
{
  boolean sensorVal = false;
 
  // Set sensorValue to 'true' if any pin reads HIGH
  for (int i = 0; i < 4 && sensorVal == false; i++) 
  {
    sensorVal = digitalRead(Pins[i]);
 
    //print out the value of the pushbutton
    Serial.print("Pin ");
    Serial.print(Pins[i]);
    Serial.print(": ");
    Serial.println(sensorVal);
  }
 
  // Set the LED to opposite of 'sensorValue' (on unless at least one pin reads HIGH)
  delay(250);
}

 

Output

Open the serial monitor – this is what you should expect to see

Pin 4: 0
Pin 5: 0
Pin 6: 0
Pin 7: 1
Pin 4: 0
Pin 5: 0
Pin 6: 0
Pin 7: 1
Pin 4: 0
Pin 5: 0
Pin 6: 0
Pin 7: 1
Pin 4: 0
Pin 5: 0
Pin 6: 1
Pin 4: 0
Pin 5: 1
Pin 4: 0
Pin 5: 1
Pin 4: 1
Pin 4: 1
Pin 4: 1
Pin 4: 1
Pin 4: 1
Pin 4: 1
Pin 4: 1
Pin 4: 0
Pin 5: 0
Pin 6: 0
Pin 7: 0

 

Links

datasheet

Share

A look at various temperature sensors for your Arduino projects

I have used many temperature sensors in my time using Arduino’s and other microcontrollers, in this article let’s look at some of the options that are available, we will also have links to example code or articles of the sensors we have picked out.

This is a table of the sensors that we will cover

Name Link Cost
DHT11 module DHT11 Module with Cable for Diy Kit $0.90
BMP280 sensor BMP280 Digital Barometric Pressure Altitude Sensor $0.60
TMP36 sensor TMP36 sensor $1
LM35D sensor LM35D analog temperature sensor $1.10
LM75 Temperature Sensor LM75 Sensor Module Temperature Sensor $0.80
TMP102 Digital Temperature Sensor TMP102 Digital Temperature Sensor $1.43
DS18B20 Temperature Sensor DS18B20 Temperature Sensor Module $1.01
SHT30 Digital Output Temperature and Humidity Sensor SHT30 Digital Output Temperature and Humidity Sensor $2.10
MCP9808 temperature Sensor Module MCP9808 temperature Sensor Module $1.78

Now let’s look at the sensors

DHT11 and DHT22 and others


These are very common sensors made by Aosong, there is very good support for them with a few libraries and examples available for them online. There are several variations some add an I2C interface on the end, some are in different cases and there are other slight differences between them. Quite a slow sensor to use in the fact that you need to give it a couple of seconds between readings, I’ve also found it to be not quite as accurate as others but it is low cost with the DHT11 coming in at $0.55

Example : http://arduinolearning.com/learning/basics/dht11-sensor-example.php

 

BMP180 and BMP280 and others


I could have added the evergreen BM085 in here as well as others, these sensors by Bosch Sensortech also have the added bonus of being able to measure barometic pressure and altitude. There are many shields, modules, libraries and examples for these sensors and they are easy to work with and reliable. You can still get the BMP085 and BMP180 online although they are not recommended for new designs they still work well. The prices vary and you can pick up a BMP180 for only $0.40 (yep, you read that correctly)

Examples : http://arduinolearning.com/code/bmp180-barometric-pressure-sensor-example.php

 

TMP36


An analog sensor with a wide range of operating voltage ranges between 2.7 and 5.5 making it ideal for many microcontrollers and its easy to use simply requiring 5v, Gnd and an analog pin with your arduino. You read in this analog value and withs imple calculations you can work out the temperature. A sensor will cost about $0.80

Example : http://arduinolearning.com/code/arduino-tmp36-example.php

 

LM35


A bit like the TMP 36 but its a little cheaper and has better accuracy . This is an analog temperature sensor which is calibrated in celsius, its easy to use with plenty of code examples available. The device can measure negative temperatures but that means that you will need to be able to read negative voltages. It has a wider operating voltage range than the TMP36 and it also has slightly better accuracy. You can pick up a module for about $1, an individual sensor will cost you slightly less

Example : http://arduinolearning.com/code/lm35-temperature-sensor.php

 

LM75


Another I2C temperature sensor that has a readily available module and there are libraries available for the arduino making it easy to work with. It can be powered from 3 to 5.5v and the address system means that 8 devices can be connected by setting a specific address to the chip. You can get a module for $0.80, so another excellent low cost option.

Example : http://arduinolearning.com/code/arduino-lm75-temperature-sensor-example.php

 

TMP102


The tmp102 is another common sensor but be careful as this one is 1.4 to 3.6v powered, don’t connect 5v to this. This does mean you may need to use a level convertor with the sensor, we typically buy a module as the part is difficult to work with otherwise as its a SOT563 package. This is priced around the $1.40 mark or lower

Example : http://arduinolearning.com/code/arduino-and-tmp102-digital-sensor-example.php

 

DS18B20


This sensor works slightly different from some of the others on the list as it is a one-wire interface. This means that only needs one data wire to communicate with an arduino or other microcontroller. Each device has a unique serial number which means in theory you can connect multiple devices to an Arduino and refer to them via the serial number which is useful for temperature monitoring systems say indoors or outdoors. You can get a simple module for under $1 and there is also a version which has leads attached and is in the format of a waterproof probe

Example : http://arduinolearning.com/learning/basics/ds18b20-temperature-sensor.php

 

SHT21 and SHT30 and others


The SHT family by sensiron is a commonly used collection of temperature and humidity sensors, one of the most commonly used is the SHT30. Again these devices are easy to use with very good library support, code examples and simple little modules for the Arduino. One of these will cost you about $1.80. Other members of the family like the SHT21 are also common and like the newer SHT31 they work just as well with an abundance of resources online, its up to you which you pick you will struggle to see any real performance difference.

Example :  http://arduinolearning.com/code/arduino-sht31-module.php

 

MCP9808


Another temperature sensor that will not break the bank is the MCP9808 by microchip it can measure temperatures between -20°C and +100°C with ±0.5°C accuracy, you can power this from 2.7 to 5.5v meaning a wide range of microcontrollers can use this device and not just an Arduino, which is handy if like me you use a wide range of them. Again there are several libraries and examples available online and the sensor comes in at under $0.80 for a module

Example : http://arduinolearning.com/code/mcp9808-digital-temperature-sensor-example.php

 

Conclusion

There are many sensors available, there are quite a few I haven’t even touched on in this article that we have examples for on this website but I would plump for the following two

SHT30 – This gives you temperature and also humidity readings at a good price and I have tested this with many microcontrollers and had no problems, the SHT21 also works just as well.

BMP280 – This sensor gives you barometic pressure and altitude as well and I have tested this again on multiple microcontrollers and it works fine. If you have a BMP180 module or want to buy one of them that is OK as well, you will not see any difference.

For my usage I have never really had any issue with readings from these, the accuracy is more than adequate for my needs

Share

Selecting an Arduino board and some shields for only $30

I was recently asked to recommend a variety of arduino shields and boards for someone who wished to start learning but with a budget of only $30. Here are the boards and modules that I picked then I will explain some rationale and why I didn’t pick some of the other shields and boards that are available

First of all the boards and shields – all of these come from Aliexpress. i have checked Amazon, Ebay, Banggood, Dx and others and for me in the UK you cannot beat Aliexpress – you may have to wait a few weeks to get the parts, if that’s an issue buy from a local source in your country but you cannot beat the prices that I see. I also did not pick the cheapest price I found and these do not include shipping which is very cheap. Also I did not look for one vendor so these would be multiple deliveries – you can look for a single source if you desired.

I got these for under $25- so a little leeway with shipping and price changes.

Link Price Description
UNO R3 MEGA328P CH340 CH340G for Arduino UNO R3 + USB CABLE $2.91 Arduino Uno
Rich Shield + IR Remote $5.66 Rich Shield
UNO Shield Ethernet Shield $4.58 Ethernet Shield
LCD Keypad Shield For Arduino $2.60 LCD Keypad Shield
V5 Sensor Shield Expansion Board Shield $2 Sensor Shield
Clock Shield $5.24 Clock Shield

So there you go, first of all some of the shields I didn’t pick and decisions I made with the list above

I decided to avoid one of the all in one kits that contain breadboards, components and sensors – these kits are good but I wanted a simple and easy experience of simply plugging in a shield to an Arduino without worrying about poor connections, correct polarity of components, reading values of components like resistors and some of the other minor issues that can occur.

We did not pick any shields that required any external components, there are many excellent motor shields but you obviously need a motor and a key thing here – you need an external power supply for the motor. I looked at the relay shield but again without external components. There are prototyping shields you can buy but again you need extra components to fully use these.

I did not select any niche shields – this is a shield for me like a Neopixel shield, MP3 shield or a CANbus shield to name a couple of examples. They are very good but slightly limited in what you can do with them. The MP3 shield ideally needs an SD card and a display for example to make it more useful.

With a limited budget we obviously ruled out any expensive shield – a Yun shield is great but at over $20 its a little costly if you are on a  tight budget.

Arduino Uno

You can pick up an Arduino Uno clone like the one in the image below for under $3, you can obviously pick up a mega for a few extra dollars but I would start with an Uno just to get you up and running.


I have never had a problem with a clone board – this one comes with a USB cable, in case you do not have one.

Rich Shield

In my opinion the best shield for beginners – you can pick up the Uno above and this for under $10 and that would be a great start for learning.

Full of useful components like a DHT11, display, LEDs, buttons, ldr, buzzer and even an EEPROM that you can see in the picture above. A great shield and this one even comes with a  basic IR remote to use the IR receiver.

This is a great shield for a great price

Ethernet Shield

This is the most basic way to connect to the net or set up a basic webserver for controlling sensors. You need a wired network connection but its a very easy shield to use with many examples online and many built into the Arduino IDE


Now you may prefer a wireless shield if you do not have a network connection, in that case there is a CC3000 and ESP8266 shield but these cost a little more

LCD Keypad shield

A nice, basic introduction to working with an LCD. This shield also contains a few buttons that you can use. Many examples online and you can then expand in the future to connect sensors and displays the values on the LCD or upgrade to a more advanced shield.


There are more advanced shields that have TFT displays but these cost a few more dollars and I have had problems with getting libraries to work, the LCD shield is very easy to use

Sensor shield

OK, this is actually only useful if you want to connect external sensors and modules, it makes it easier to connect these using female to female dupont cables


If you don’t plan on ever using other sensors or modules – you will not need this and can remove it from the list

Clock shield

Another shield which is aimed at beginners, this one actually was designed to be a clock/alarm.


As you can see from the image above it contains a few components that are very useful for beginners – a display, buzzer, buttons, ntc thermistor and an RTC. So you can create a few experiments with this shield as well as a clock/alarm or timer

 

Conclusion

You can see what I picked – I think this is great for beginners and you can complete a good amount of experiments with  an Arduino before you delve into more complex shields, sensors and prototyping.

Share