Categories

VCNL4010 proximity and ambient light sensor Arduino example

In this article we look at another acceleration sensor – this time its the VCNL4010 and we will connect it to an Arduino Uno

First lets look at the sensor

The VCNL4010 is a fully integrated proximity and ambient light sensor. Fully integrated means that the infrared emitter is included in the package. It has 16 bit resolution. It includes a signal processing IC and features standard I2C communication interface. It features an interrupt function.

PROXIMITY FUNCTION
• Built-in infrared emitter and photo-pin-diode for proximity
function
• 16 bit effective resolution for proximity detection range
ensures excellent cross talk immunity
• Programmable LED drive current from 10 mA to 200 mA in
10 mA steps
• Excellent ambient light suppression by modulating the
infrared signal
• Proximity distance up to 200 mm

AMBIENT LIGHT FUNCTION
• Built-in ambient light photo-pin-diode with close-tohuman-eye sensitivity
• 16 bit dynamic range from 0.25 lx to 16 klx
• 100 Hz and 120 Hz flicker noise rejection

FEATURES

• Integrated modules: infrared emitter (IRED), ambient light sensor (ALS-PD), proximity sensor (PD), and signal conditioning IC
• Interrupt function
• Supply voltage range VDD: 2.5 V to 3.6 V
• Supply voltage range IR anode: 2.5 V to 5 V
• Communication via I2C interface
• I2C Bus H-level range: 1.7 V to 5 V
• Low stand by current consumption: 1.5 μA

 

Parts Required

 

NameLink
Arduino UnoUNO R3 CH340G/ATmega328P, compatible for Arduino UNO
VCNL4010Multiple Function Sensor Development Tools Proximity/Light Sensor VCNL4000 (1 piece)
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

 

arduino and vcnl4010

arduino and vcnl4010

 

Code Example

This uses the library from https://github.com/adafruit/Adafruit_VCNL4010

This is the default example

#include <Wire.h>
#include "Adafruit_VCNL4010.h"
Adafruit_VCNL4010 vcnl;
void setup()
{
Serial.begin(9600);
Serial.println("VCNL4010 test");
if (! vcnl.begin())
{
Serial.println("Sensor not found :(");
while (1);
}
Serial.println("Found VCNL4010");
}
void loop()
{
Serial.print("Ambient: ");
Serial.println(vcnl.readAmbient());
Serial.print("Proximity: ");
Serial.println(vcnl.readProximity());
delay(100);
}

 

Output

Open the serial monitor and you should see something like this

Proximity: 3628
Ambient: 76
Proximity: 5509
Ambient: 66
Proximity: 6417
Ambient: 63
Proximity: 7181
Ambient: 54
Proximity: 8347
Ambient: 53
Proximity: 9443
Ambient: 52

 

Links

https://www.vishay.com/docs/83462/vcnl4010.pdf

 

 

Share

MS1100 Formaldehyde Benzene Concentration Gas Sensor Module and Arduino example

The sensor is mainly used for the detection of formaldehyde, toluene, benzene and other VOC gas. The sensor is a type of semiconductor products, widely used in equipment, ventilation equipment, ventilation fan, air filter, hood, hood etc..With high sensitivity and stability, it can detect more than 0.1ppm of the gas. It is suitable for the detection of formaldehyde, benzene, xylene and other volatile organic compounds in the air,small size, cheap, widely used in a variety of small appliances.

The sensor has two pins A0 and D0.
The A0 pin represents the detection of other content. The larger the amount of content detected, the larger the A0 analog value is. Unfortunately this can ve various VOC’s, you cannot detect individual ones.
The D0 pin represents whether the gas content exceeds the zero threshold. When it exceeds the threshold then D0 outputs a HIGH level; when it does not exceed the threshold value then D0 outputs LOW. You are able to adjust the zero threshold value by the potentiometer on the back.
The sensor has an LED to indicate whether the gas content exceeds the set zero limit.

Specs

Operating voltage: DC 5V
Operating current: 100mA
Maximum power: 1W
Operating temperature range: -25°C to 65°C

heating voltage: 5V + 2% (AC . DC)
Working current: 100mA (max)
circuit voltage: < DC12V
load resistance: 1K (adjustable)
detection concentration range :0-1000ppm (different gases different scope)
clean air voltage: < 1V
Sensitivity: > 3%
response time: < 5S (preheat 3-5 minutes)
response time:> 10S
component power consumption: �430mW
Working temperature: -10 ~ 60 oC (nominal temperature 20 oC)
Humidity: 90% RH (nominal humidity 65% RH)
lifespan : 5 years

Application:

For the home environment and other air fresheners detection. smoke control ventilation fans and other equipment suitable for testing the concentration range: 0 to 1000ppm qualitative detection of the gas

Parts

I used a sensor shield and connected the sensor to this – the sensor costs about $7.23

NameLink
Arduino UnoArduino UNO R3
MS1100 sensorMS1100 VOC Gas Sensor Module
Sensor shieldArduino Sensor Shield
Connecting wiremale to male + male to female and female to female DuPont cable

Connection

ArduinoModule
5vVcc
GndGnd
D2DOUT
A0AOUT

Code

Fairly simple, no libraries just checking the values of D2 and A0 – you can use other pins you would have to change the code

#define Aout A0
#define Dout 2
void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(Aout,INPUT);
  pinMode(Dout,INPUT);
}
void loop()
{
  // put your main code here, to run repeatedly:
  int a=analogRead(Aout);
  int b=digitalRead(Dout);
  Serial.print("D0:");
  Serial.print(b);
  Serial.print("   A0:");
  Serial.println(a);
  delay(500);
}

 

Output

Open the serial monitor. The greater the measured gas concentration, the greater the A0 value is.
When the detected gas exceeds the set zero limit, D0 is 1, the D1 LED on the sensor lights up; otherwise D0 is 0, and the D1 LED on the sensor is off.

This is what I saw

D0:0 A0:770
D0:0 A0:757
D0:0 A0:755
D0:0 A0:764
D0:0 A0:767
D0:0 A0:760
D0:0 A0:765
D0:0 A0:769

Share

A 315Mhz transmitter and receiver module for an Arduino

In this article we look at a pair of modules that can be used for communication between 2 Arduino’s. These are a 315Mhz transmitter and receiver module, they are very similar to the 433Mhz modules we looked at in a previous article – the only difference is that they use a different pairing frequency. They are an excellent low cost solution for communication coming in at only $3.20 for a pair of these

The kit includes one pair of transmitter and receiver modules and one pair of spring antennas for increasing the communication distance. And the frequency is 315MHz. It is very popular for remote control systems, such as wireless doorbell, remote control rolling gates, smart car, smart home, etc.

About transmitter module (onboard square module)

– Compatible with Arduino
– Working voltage: 4 – 12VDC
– Working current: 40mA
– Transmit power: 27dBm@12V (large power)
– Working frequency: 315MHz
– Transfer rate: 4.8kbps (max)
– Transmission distance: When supply poower is 5V, the open area transmission distance can be increased to 150 meters. The supply voltage is larger, the transmission distance farther.
– Antenna: Onboard 315MHz dedicated PCB Antenna.

 

About receiver module (rectangle shape):

– Compatible with Arduino
– Arduino Library: VirtualWire
– Operating voltage: 2 – 5.5VDC
– Working frequency: 315MHz
– Working Current: 2mA
– Sensitivity: -110db

– Antenna: Onboard 315MHz dedicated PCB Antenna

 

Parts

You will need 2 Arduino’s – one for the transmitter and one to be the receiver. I used 2 Arduino Uno’s in testing

NameLink
Arduino UNOArduino UNO R3
315mhz modulesOPEN-SMART Long Range 315MHz RF Wireless Transceiver Kit
Connecting areaCable Dupont Jumper Wire Dupont 30CM

Code

The code needs the virtualwire library to be installed, we have this in the download below

VirtualWire

Here is the receiver part of the code

#include <VirtualWire.h>
int RF_RX_PIN = 11;//connect the sent module to D11 to use
//you can change it to the idle port you want.
void setup()
{
Serial.begin(9600);
Serial.println("setup");
vw_set_rx_pin(RF_RX_PIN); // Setup receive pin.
vw_setup(2000); // Transmission speed in bits per second.
vw_rx_start(); // Start the PLL receiver.
}
void loop()
{
String comdata = "";
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if(vw_get_message(buf, &buflen)) // non-blocking I/O
{
int i;
// Message with a good checksum received, dump HEX
Serial.print("Got: ");
for(i = 0; i < buflen; ++i)
{
comdata += (char)buf[i];
//Serial.print(" ");
//Serial.print(buf[i]);
}
Serial.print(comdata);
Serial.println("");
}
}

 

And now for the transmit test example

#include <VirtualWire.h>
int RF_TX_PIN = 12;//connect the transmit module to D12
void setup()
{
Serial.begin(19200);
vw_set_tx_pin(RF_TX_PIN); // Setup transmit pin
vw_setup(2000); // Transmission speed in bits per second.
}
unsigned char buffer[64]; // buffer array for data recieve over serial port
int count=0; // counter for buffer array
void loop()
{
if (Serial.available()) // if date is comming from softwareserial port ==> data is comming from gprs shield
{
while(Serial.available()) // reading data into char array
{
buffer[count++]=Serial.read(); // writing data into array
if(count == 64)break;
}
vw_send(buffer, count); // Send 'hello' every 400ms.
clearBufferArray(); // call clearBufferArray function to clear the storaged data from the array
count = 0;
}
// const char *msg = "hello";
// vw_send((uint8_t *)msg, strlen(msg)); // Send 'hello' every 400ms.
delay(400);
}
void clearBufferArray() // function to clear buffer array
{
for (int i=0; i<count;i++)
{ buffer[i]=NULL;} // clear all index of array with command NULL
}
Share

A 433Mhz transmitter and receiver module for an Arduino

In this article we look at a pair of modules that can be used for communication between 2 Arduino’s. These are a 433Mhz transmitter and receiver module

The kit includes one pair of transmitter and receiver modules and one pair of spring antennas for increasing the communication distance. And the frequency is 433MHz. It is very popular for remote control systems, such as wireless doorbell, remote control rolling gates, smart car, smart home, etc.

In the image below you can see the 2 modules in question, you simply need to supply these with VCC, Gnd and a signal pin.

About the transmitter module

– Compatible with Arduino
– Working voltage: 4 – 12VDC
– Working current: 40mA
– Transmit power: 27dBm@12V (large power)
– Working frequency: 433MHz
– Transfer rate: 4.8kbps (max)
– Transmission distance: When supply power is 5V, the open area transmission distance can be increased to 150 meters.
– Antenna: Onboard 433MHz dedicated PCB Antenna.

About the receiver module (rectangle shape):

– Compatible with Arduino
– Operating voltage: 2 – 5.5VDC
– Working frequency: 433MHz
– Working Current: 2mA
– Sensitivity: -110db
– Antenna: Onboard 433MHz dedicated PCB Antenna

Parts

You will need 2 Arduino’s – one for the transmitter and one to be the receiver. I used 2 Arduino Uno’s in testing

NameLink
Arduino UNOArduino UNO R3
433mhz modulesLong Range 433MHz RF Wireless Transceiver Kit with Antenna
Connecting areaCable Dupont Jumper Wire Dupont 30CM

Code

The code needs the virtualwire library to be installed, we have this in the download below

VirtualWire

Here is the receiver part of the code

#include <VirtualWire.h>
int RF_RX_PIN = 11;//connect the sent module to D11 to use
//you can change it to the idle port you want.
void setup()
{
Serial.begin(9600);
Serial.println("setup");
vw_set_rx_pin(RF_RX_PIN); // Setup receive pin.
vw_setup(2000); // Transmission speed in bits per second.
vw_rx_start(); // Start the PLL receiver.
}
void loop()
{
String comdata = "";
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if(vw_get_message(buf, &buflen)) // non-blocking I/O
{
int i;
// Message with a good checksum received, dump HEX
Serial.print("Got: ");
for(i = 0; i < buflen; ++i)
{
comdata += (char)buf[i];
//Serial.print(" ");
//Serial.print(buf[i]);
}
Serial.print(comdata);
Serial.println("");
}
}

 

And now for the transmit test example

#include <VirtualWire.h>
int RF_TX_PIN = 12;//connect the transmit module to D12
void setup()
{
Serial.begin(19200);
vw_set_tx_pin(RF_TX_PIN); // Setup transmit pin
vw_setup(2000); // Transmission speed in bits per second.
}
unsigned char buffer[64]; // buffer array for data recieve over serial port
int count=0; // counter for buffer array
void loop()
{
if (Serial.available()) // if date is comming from softwareserial port ==> data is comming from gprs shield
{
while(Serial.available()) // reading data into char array
{
buffer[count++]=Serial.read(); // writing data into array
if(count == 64)break;
}
vw_send(buffer, count); // Send 'hello' every 400ms.
clearBufferArray(); // call clearBufferArray function to clear the storaged data from the array
count = 0;
}
// const char *msg = "hello";
// vw_send((uint8_t *)msg, strlen(msg)); // Send 'hello' every 400ms.
delay(400);
}
void clearBufferArray() // function to clear buffer array
{
for (int i=0; i<count;i++)
{ buffer[i]=NULL;} // clear all index of array with command NULL
}
Share