Categories

Arduino and US-026 Ultrasonic Detector example

US-026 is an upgraded version of the HC-SR04, with a kind of high performance, low cost ultrasonic module. The module uses the CS100 , a high performance-cost ratio ultrasonic ranging chip.

US-026

US-026

It has high measurement accuracy and the measuring distance is farther than 6 meters. Good consistency, well stability.
It can realize 2-6m non-contact ranging. The working voltage is 3V-5.5V, working current is 5.3 mA and supporting GPIO communication mode.
US-026 has 4 Pin power supply and communication interface. It is single-side printed board. 4 pin is welded on the back side (the chip side).
Input a 10uS above high level to Trig pin, the system will emit eight 40KHZ ultrasonic impulse. The system detects the echo signal and output through Echo pin. Calculating the distance according the lasting time of high electrical level which exported by the ECHO pin.

1.This module has stable performance and accurate measurement distance.
2.Module high-precision, blind (2cm) ultra-close, stable range is the success of this product to the market a strong basis.
3.Using IO trigger ranging,to at least 10us of high-level signal.
4.The module automatically sends eight 40khz square wave, automatically detect whether there is signal return.
5.There is a signal return, through the IO output of a high, high duration is the time from the launch to the return of ultrasound.

 

Specifications:

Color:yellow
Working voltage: DC 3V-5.5V
Working current:5.3mA
Level output: High 5V
Level output: Bottom 0V
Sensing angle: not more than 15 degrees
Detection range: 2cm-600cm

 

Parts

NameLink
Arduino UNOArduino UNO R3
US-026  ultrasonic sensorUS-026 Ultrasonic Detector
Connecting areaCable Dupont Jumper Wire Dupont 30CM

Connection

The Ultrasonic sensor has four terminals – +5V, Trigger, Echo, and GND connected as follows

  • Connect the +5V pin to +5v on your Arduino board.
  • Connect Trigger to digital pin 6 on your Arduino board.
  • Connect Echo to digital pin 7 on your Arduino board.
  • Connect GND with GND on Arduino.

Code

const int pingPin = 6; // Trigger Pin of Ultrasonic Sensor
const int echoPin = 7; // Echo Pin of Ultrasonic Sensor
void setup()
{
Serial.begin(9600); // Starting Serial Terminal
}
void loop()
{
long duration, inches, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print(" in, ");
Serial.print(cm);
Serial.print(" cm");
Serial.println();
delay(100);
}
long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}

Output

Open the serial monitor and move an object to the sensor

2in, 6cm
6in, 16cm
40in, 103cm
40in, 103cm
2in, 5cm
2in, 6cm
12in, 30cm
11in, 30cm
11in, 30cm

Share

Arduino and OPEN-SMART PM2.5 Optical Dust Smoke Sensor Module example

It is a dust sensor by optical sensing system. An infrared emitting diode and an phototransistor are diagonally arranged into this device. It detects the reflected light of dust in air.

Especially, it is effective to detect very fine particle like the cigarette smoke.

In addition it can distinguish smoke from house dust by pulse pattern of output voltage. It can easily connected for Arduino board because of the PM2.5 Adapter module.

– Working voltage: 4.8-5.5VDC
– Operating current: <= 20 mA
– Output mode: analog output
– Application: Air purifier, Air conditioner, Air monitor

Parts

NameLink
Arduino UNOArduino UNO R3
OPEN-SMART PM2.5 sensorOPEN-SMART PM2.5 Optical Dust Smoke Sensor Module with Adapter Module
Connecting areaCable Dupont Jumper Wire Dupont 30CM

Code

// Demo code for PM2.5 sensor with Adapter module by OPEN-SMART Team
// Hardware:
// 1 x I2C 1602 LCD
// 1 x PM2.5 sensor with Adapter module
// Function:
// measure the PM2.5 and display on serial monitor of Arduino IDE and I2C 1602 LCD.
#include <Wire.h>
//#include <LiquidCrystal_I2C.h>
//LiquidCrystal_I2C lcd(0x38,16,2);
int VO_PIN = A0;
int LED_PIN = 2;
unsigned int samplingTime = 280;
unsigned int deltaTime = 40;
unsigned int sleepTime = 9680;
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;
void setup(){
Serial.begin(9600);
pinMode(LED_PIN,OUTPUT);
//lcd.init(); // initialize the lcd
// Print a message to the LCD.
//lcd.backlight();
}
void loop(){
digitalWrite(LED_PIN,LOW);
delayMicroseconds(samplingTime);
voMeasured = analogRead(VO_PIN);
delayMicroseconds(deltaTime);
digitalWrite(LED_PIN,HIGH);
delayMicroseconds(sleepTime);
calcVoltage = voMeasured*(5.0/1024);
dustDensity = 0.17*calcVoltage-0.1;
if ( dustDensity < 0)
{
dustDensity = 0.00;
}
Serial.println("Raw Signal Value (0-1023):");
Serial.println(voMeasured);
Serial.println("Voltage:");
Serial.println(calcVoltage);
// lcd.setCursor(0,0);
//lcd.print(calcVoltage);
//lcd.print("V");
//lcd.setCursor(0,1);
//lcd.print("Dust:");
//lcd.print(dustDensity);
Serial.println("Dust Density:");
Serial.println(dustDensity);
delay(500);
//lcd.clear();
delay(1000);
}

Output

Open the serial monitor

Raw Signal Value (0-1023):
111.00
Voltage:
0.54
Dust Density:
0.00
Raw Signal Value (0-1023):
117.00
Voltage:
0.57
Dust Density:
0.00

Share

RPI-1031 tilt sensor and Arduino example

In this article we look at a tilt sensor – this time its the RPI-1031 and we will connect it to an Arduino

The RPI-1031 tilt sensor is capable of sensing a change in orientation in four different directions: forward, back, left or right</p

This tilt sensor can be used to detect multiple orientations. Inside the sensor are infrared emitters which are either reflected or not, depending on the orientation of the sensor. By reading the output of the various pins you can easily determine the orientation of the sensor and your project.

Being a tilt sensor this is just a metal ball that rolls around inside the case. The ball is always up against one side even when it is flat.

The sensor needs power and ground, you can then connect the 2 digital pins. These 2 digital pins will output LOW/LOW, LOW/HIGH, HIGH/LOW and HIGH/HIGH depending on the wall it is touching.

Parts Required

 

NameLink
Arduino UnoUNO R3 CH340G/ATmega328P, compatible for Arduino UNO
RPI-1031RPI-1031 Angle Sensor 4DOF Attitude HM Module 4 Direction For Arduino
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

ArduinoSensor
5vVcc
GndGnd
S1D1
S1D2

 

RPI-1031_arduino

 

Code Example

The code for this sensor is really basic, it just checks the 2 pins, to see what side is being touched – The simple function simply takes the 2 digital outputs and returns 0,1,2 or 3 depending on the side.

int tilt_s1 = 2;
int tilt_s2 = 3;
void setup(){
pinMode(tilt_s1, INPUT);
pinMode(tilt_s2, INPUT);
Serial.begin(9600);
}
void loop(){
int position = getTiltPosition();
Serial.println(position);
delay(200); //only here to slow down the serial output
}
int getTiltPosition(){
int s1 = digitalRead(tilt_s1);
int s2 = digitalRead(tilt_s2);
return (s1 << 1) | s2; //bitwise math to combine the values
}

 

Output

Open the serial monitor and you should see something like this, I was moving the sensor around.

Not the most intuitive readings admittedly

3
3
3
2
0
0

 

Links

https://github.com/sparkfun/Tilt-a-Whirl_Breakout

 

 

 

 

 

Share

An Arduino and SHTC1 digital humidity sensor example

In this article we look at another digital humidity sensor – this time its the SHTC1 and we will connect it to an Arduino

The SHTC1 is a digital humidity sensor designed especially for high-volume consumer electronics applications. This humidity sensor is strictly designed to overcome conventional limits for size, power consumption, and price-performance ratio, in order to fulfill the current and future requirements of the consumer electronics market.

Sensirion’s CMOSens® technology offers a complete sensor system on a single chip, consisting of a capacitive humidity sensor, a band-gap temperature sensor, analog and digital signal processing, A/D converter, calibration data memory, and a digital communication interface supporting I2C fast mode. The ultra-small, 2 × 2 × 0.75 mm3 DFN package enables applications to be placed in even the most limited of spaces. The sensor covers a humidity measurement range of 0 to 100 %RH and a temperature measurement range of –30°C to 100°C with a typical accuracy of ±3 %RH and ±0.3°C.

The operating voltage of 1.8 V and an energy budget below 1 µJ per measurement make the SHTC1 suitable for mobile or wireless applications running on the lowest power budgets. With the industry-proven quality and reliability of Sensirion’s humidity sensors and constant accuracy over a large measurement range, the SHTC1 humidity sensor offers an unprecedented price-performance ratio. Tape and reel packaging together with suitability for standard SMD assembly processes make the SHTC1 predestined for high-volume applications.

Features

InterfaceI²C
Supply voltage1.8 V
Power consumption2µW (at 1 reading per second in low power mode)
Measuring range (RH)0 – 100% relative humidity
Measuring range (T)-30 to +100°C (-22 to +212°F)
Response time (RH)8s (tau63%)

Parts Required

 

NameLink
Arduino UnoUNO R3 CH340G/ATmega328P, compatible for Arduino UNO
SHTC1
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

ArduinoSensor
5vVcc
GndGnd
SDASDA
SCLSCL

 

Code Example

This uses the library from https://github.com/Sensirion/arduino-sht

#include <Wire.h>
#include "SHTSensor.h"
SHTSensor sht;
// To use a specific sensor instead of probing the bus use this command:
// SHTSensor sht(SHTSensor::SHT3X);
void setup() {
// put your setup code here, to run once:
Wire.begin();
Serial.begin(9600);
delay(1000); // let serial console settle
if (sht.init()) {
Serial.print("init(): success\n");
} else {
Serial.print("init(): failed\n");
}
sht.setAccuracy(SHTSensor::SHT_ACCURACY_MEDIUM); // only supported by SHT3x
}
void loop() {
// put your main code here, to run repeatedly:
if (sht.readSample()) {
Serial.print("SHT:\n");
Serial.print(" RH: ");
Serial.print(sht.getHumidity(), 2);
Serial.print("\n");
Serial.print(" T: ");
Serial.print(sht.getTemperature(), 2);
Serial.print("\n");
} else {
Serial.print("Error in readSample()\n");
}
delay(1000);
}

 

Output

Open the serial monitor and you should see something like this

init(): success
SHT:
RH: 43.97
T: 20.05
SHT:
RH: 43.99
T: 20.01
SHT:
RH: 44.01
T: 20.00

 

Links

 

 

 

 

 

Share