Categories

Arduino and HS1011 sensor example

The HS1101 humidity sensor is a cost-effective solution for measuring relative humidity within ±5% accuracy. The sensor’s design is based on a unique capacitive cell; therefore, by using simple RC circuit wiring it is easy to interface with any Parallax microcontroller, including the BASIC Stamp® and Propeller chip.

Specifications

Power requirements: 5 to 10 VDC
Communication: Analog output of varying capacitance in response to change in relative humidity
Humidity Measuring Range: 1 to 99% RH
Operating temperature: -40 to 212 °F (-40 to 100 °C)

 

Connection

Connect 5v and Gnd to the module

I used Pin 4, you can use any I/O pin you will need to change the code below if you do

Code

/*
 
Demonstration of the Parallax HS1101 relative humidity sensor (#27920)
 
The HS1101 sensor acts as a capacitor, and uses the circuit described in the 
product documentation to derive an RC (resistor-capacitor) time delay. By
measuring the decay of the capacitor through a resistor, it is possible to
obtain the current relative humidity.
 
This demo shows the relative humidity (accuracy: +/-3.5%, as noted in product 
documentation), along with the RC delay timing. Readings repeat once every ½ 
second, and are displayed in the Arduino Serial Monitor window.
 
This example code is for the Arduino Uno and direct compatible boards, using the
Arduino 1.0 or later IDE software. It has not been tested, nor designed for, other 
Arduino boards, including the Arduino Due.
 
Please note: Environmental factors - including use indoors or outdoors, and
above and below typical room temperature ranges -- may affect the accuracy of 
the readings. The demo includes an RCdelay calibration value that can be 
adjusted against a known working humidity sensor used in the same environment.
 
Important: the result is based on the clock speed of Arduino microcontroller.
Other versions of Arduino (running at faster or slower clocks) will need
recalibration of the RCdelay value. See comment below.
 
Refer to the HS1101 product documentation for the connection diagram and
circuit. The output of the sensor is connected to Arduino pin D4.
 
Tips: The sensor is sensitive to stray capacitance. Keep lead lengths short.
Results may vary when the test circuit is built on a solderless breadboard.
Leads from sensor are slightly undersized for breadboard holes. Make sure
they make adequate contact. When taking readings avoid contact or close
proximity to sensor or bare circuit wires.
 
*/
 
int sensorPin = 4;                        // RC circuit with HS1101 sesnor connected to digital pin D4
long result = 0;
int const RHconstant = 12169;             // RH constant
 
void setup() {
   Serial.begin(9600);                   // Use Serial Monitor window at 9600 baud
   Serial.println("Humidiy reading start");
   Serial.print("RC delay");
   Serial.print("\t");
   Serial.println("Humidity");
}
void loop() {
   long RCdelay = RCTime(sensorPin);     // Take RC time reading of sensor
   Serial.print(RCdelay);                // Display RC time delay
   Serial.print("\t\t"); 
 
   RCdelay = RCdelay * 215;               // Calibation to RC time delay; experiment with literal value
   int humidity = (RCdelay - RHconstant) / 24;
   Serial.println(humidity / 100, DEC);  
   delay(500);                           // Wait 1/2 second for the next read
}
 
// Standard RC time function
long RCTime(int sensePin){
   long result = 0;
   pinMode(sensePin, OUTPUT);       // Make pin OUTPUT, and turn HIGH
   digitalWrite(sensePin, HIGH);    
   delay(1);                        // Wait 1 ms delay
   pinMode(sensePin, INPUT);        // Make sensor INPUT
   digitalWrite(sensePin, LOW);     // Turn off Arduino internal pullup resistor
   while(digitalRead(sensePin)){    // Loop until pin goes low
      result++;
   }
   return result;
}

 

Link

https://www.parallax.com/sites/default/files/downloads/27920-Humidity-Sensor-Datasheet.pdf

https://www.parallax.com/sites/default/files/downloads/27920-Humidity-Sensor-Documention-S1101-v1.0.pdf

CJMCU-1101 HS1101 humidity sensor RELATIVE, HUMIDITY, SENSOR

Share

Arduino and TEMT6000 light sensor

TEMT6000X01 ambient light sensor is a silicon NPN epitaxial planar phototransistor in a miniature transparent 1206 package for surface mounting. It is sensitive to visible light much like the human eye and has peak sensitivity at 570 nm.

Here is a picture of a module

 

Here is a schematic of the module

APPLICATIONS

Ambient light sensor for control of display backlight dimming in LCD displays and keypad backlighting of mobile devices and in industrial on/off-lighting operation.

• Automotive sensors
• Mobile phones
• Notebook computers
• PDA’s
• Cameras
• Dashboards

 

Connection

 

arduino and TEMT6000

arduino and TEMT6000

 

Code

 

#define LIGHTSENSORPIN A1 //Ambient light sensor reading
 
void setup() 
{
pinMode(LIGHTSENSORPIN, INPUT); 
Serial.begin(9600);
}
 
void loop() 
{
float reading = analogRead(LIGHTSENSORPIN); //Read light level
float square_ratio = reading / 1023.0; //Get percent of maximum value (1023)
square_ratio = pow(square_ratio, 2.0); 
Serial.println(reading); 
delay(1000); 
}

 

Output

Open the serial monitor and you should see something like this

41.00
42.00
4.00
1.00
21.00
38.00
41.00
41.00
40.00

 

Links

TEMT6000 Light Sensor

https://www.vishay.com/docs/81579/temt6000.pdf

Share

Arduino and MMA7660 accelerometer

The MMA7660FC is a digital output I²C, very low-power, low-profile capacitive micro-machined accelerometer featuring a low pass filter, compensation for zero-g offset and gain errors and conversion to six-bit digital values at a user configurable output data rate. The device can be used for sensor data changes, product orientation and gesture detection through an interrupt pin (INT).

Communication is handled through a 2 pin I2C interface, available on a wide range of microcontrollers. The I2C address by default is 0x4c.

 

Pin Description

Connection

  • Pinout for Arduino UNO
  • GND = GND
  • VCC = 5v
  • SDA = A4
  • SCL = A5

 

Code

I used this library – https://github.com/mcauser/Grove-3Axis-Digital-Accelerometer-1.5g-MMA7660FC

This is the default example

 

#include <Wire.h>
#include "MMA7660.h"
MMA7660 acc;
 
void setup()
{
acc.init();
pinMode(13, OUTPUT);
Serial.begin(115200);
}
 
void loop()
{
 
static long cnt = 0;
static long cntout = 0;
float ax,ay,az;
int8_t x, y, z;
 
acc.getXYZ(&x,&y,&z);
 
Serial.print("x = ");
Serial.println(x);
Serial.print("y = ");
Serial.println(y);
Serial.print("z = ");
Serial.println(z);
 
 
if(acc.getAcceleration(&ax,&ay,&az))
{
Serial.print("get data ok: ");
}
else
{
Serial.print("tiem out: ");
}
 
Serial.println("accleration of X/Y/Z: ");
Serial.print(ax);
Serial.println(" g");
Serial.print(ay);
Serial.println(" g");
Serial.print(az);
Serial.println(" g");
Serial.println();
delay(50);
 
}

 

Link

https://www.nxp.com/docs/en/data-sheet/MMA7660FC.pdf

1PCS NEW MMA7660 Replace MMA7260 3 Axis Triaxial accelerometer sensor module

Share

Arduino and LSM6DS3 accelerometer and gyroscope example

The LSM6DS3 is a system-in-package featuring a 3D digital accelerometer and a 3D digital gyroscope performing at 1.25 mA (up to 1.6 kHz ODR) in high-performance mode and enabling always-on low-power features for an optimal motion experience for the consumer.

The LSM6DS3 supports main OS requirements, offering real, virtual and batch sensors with 8 kbyte for dynamic data batching.

ST’s family of MEMS sensor modules leverages the robust and mature manufacturing processes already used for the production of micromachined accelerometers and gyroscopes.

The various sensing elements are manufactured using specialized micromachining processes, while the IC interfaces are developed using CMOS technology that allows the design of a dedicated circuit which is trimmed to better match the characteristics of the sensing element.

The LSM6DS3 has a full-scale acceleration range of ±2/±4/±8/±16 g and an angular rate range of ±125/±250/±500/±1000/±2000 dps.

High robustness to mechanical shock makes the LSM6DS3 the preferred choice of system designers for the creation and manufacturing of reliable products.

The LSM6DS3 is available in a plastic land grid array (LGA) package.

Key Features

Power consumption: 0.9 mA in combo normal mode and 1.25 mA in combo high-performance mode up to 1.6 kHz.
“Always-on” experience with low power consumption for both accelerometer and gyroscope
Smart FIFO up to 8 kbyte based on features set
Compliant with Android K and L
Hard, soft ironing for external magnetic sensor corrections
±2/±4/±8/±16 g full scale
±125/±250/±500/±1000/±2000 dps full scale
Analog supply voltage: 1.71 V to 3.6 V
Independent IOs supply (1.62 V)
Compact footprint, 2.5 mm x 3 mm x 0.83 mm
SPI/I2 C serial interface with main processor data synchronization feature

 

Code

I used the sparkfun library –https://github.com/sparkfun/SparkFun_LSM6DS3_Arduino_Library

This is the minimal example, there are many others

 

#include "SparkFunLSM6DS3.h"
#include "Wire.h"
#include "SPI.h"
 
LSM6DS3 myIMU; //Default constructor is I2C, addr 0x6B
 
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(1000); //relax...
Serial.println("Processor came out of reset.\n");
 
//Call .begin() to configure the IMU
myIMU.begin();
 
}
 
 
void loop()
{
//Get all parameters
Serial.print("\nAccelerometer:\n");
Serial.print(" X = ");
Serial.println(myIMU.readFloatAccelX(), 4);
Serial.print(" Y = ");
Serial.println(myIMU.readFloatAccelY(), 4);
Serial.print(" Z = ");
Serial.println(myIMU.readFloatAccelZ(), 4);
 
Serial.print("\nGyroscope:\n");
Serial.print(" X = ");
Serial.println(myIMU.readFloatGyroX(), 4);
Serial.print(" Y = ");
Serial.println(myIMU.readFloatGyroY(), 4);
Serial.print(" Z = ");
Serial.println(myIMU.readFloatGyroZ(), 4);
 
Serial.print("\nThermometer:\n");
Serial.print(" Degrees C = ");
Serial.println(myIMU.readTempC(), 4);
Serial.print(" Degrees F = ");
Serial.println(myIMU.readTempF(), 4);
 
delay(1000);
}

 

 

Output

Open the serial monitor

Accelerometer:
X = -6.5480
Y = 2.1936
Z = -4.5135

Gyroscope:
X = 0.2800
Y = 0.0000
Z = 125.4400

Thermometer:
Degrees C = 25.0000
Degrees F = 77.0000

 

Link

1.71 V to 5 V LSM6DS3 SPI/I2C 3 Axis Accelerometer 3 Axis Gyroscope 6 Axis Inertial Breakout Board Embedded temperature sensor

Share