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.


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)



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


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");
void loop() {
   long RCdelay = RCTime(sensorPin);     // Take RC time reading of sensor
   Serial.print(RCdelay);                // Display RC time delay
   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
   return result;



CJMCU-1101 HS1101 humidity sensor RELATIVE, HUMIDITY, SENSOR


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


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




arduino and TEMT6000

arduino and TEMT6000




#define LIGHTSENSORPIN A1 //Ambient light sensor reading
void setup() 
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); 



Open the serial monitor and you should see something like this




TEMT6000 Light Sensor


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


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



I used this library –

This is the default example


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



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


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



I used the sparkfun 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:
delay(1000); //relax...
Serial.println("Processor came out of reset.\n");
//Call .begin() to configure the IMU
void loop()
//Get all parameters
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(" X = ");
Serial.println(myIMU.readFloatGyroX(), 4);
Serial.print(" Y = ");
Serial.println(myIMU.readFloatGyroY(), 4);
Serial.print(" Z = ");
Serial.println(myIMU.readFloatGyroZ(), 4);
Serial.print(" Degrees C = ");
Serial.println(myIMU.readTempC(), 4);
Serial.print(" Degrees F = ");
Serial.println(myIMU.readTempF(), 4);




Open the serial monitor

X = -6.5480
Y = 2.1936
Z = -4.5135

X = 0.2800
Y = 0.0000
Z = 125.4400

Degrees C = 25.0000
Degrees F = 77.0000



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