Wednesday, June 29, 2016

YL-83 Rain Sensor


The YL-83 is a raindrop module that consists of 4 pins: VCC, GND, D0, and A0. The connections are self-explanatory. The LM393 IC acts as a resistive divider. The board comes equipped with a power indicator light and a LED indicating lamp. The potentiometer on the board can be used to adjust the reference voltage. In this simple project, the D0 digital pin is connected to the D7 pin of an Arduino Uno. The A0 analog pin is wired to the Arduino's A0 pin. The output signal from the analog pin gets lower when raindrop is detected. The opposite applies when the sensor is dry.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
int ledPin=13;
int sensorDPin=7;
int sensorAPin=A0;
int val;

void setup() {
  Serial.begin (9600);
  pinMode(ledPin,OUTPUT);
  pinMode(sensorDPin,INPUT);
  pinMode(sensorAPin,INPUT);
}

void loop() {
  val=analogRead(sensorAPin);
  Serial.println(val);

  val=digitalRead(sensorDPin);
  if(val==HIGH){
    digitalWrite(ledPin,LOW);
  }
  else{
    digitalWrite(ledPin,HIGH);
  }
  
  delay(2000);
}



Thursday, June 23, 2016

KY-028 NTC Temperature Sensor Module


The KY-028 is a thermal sensor module that utilizes an NTC thermistor to detect the temperature of the surrounding environment. NTC or Negative Temperature Coefficient means the resistance of the thermistor decreases with increasing temperature. The passive components that include the LM393 IC create a voltage divider for the thermistor.

The module in this example has analog (A0) and digital (D0) pin connections. Only the analog pin is used here. When the temperature increases, the output voltage that appears on the analog input of the Arduino will drop. The opposite applies when the temperature decreases. The temperature detection threshold can be adjusted through the onboard potentiometer.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
int sensorPin=A0;
int val;

void setup() {
  Serial.begin (9600);
  pinMode(sensorPin,INPUT);
}

void loop() {
  val=analogRead(sensorPin);
  Serial.println(val);
  delay(2000);
}


Thursday, June 16, 2016

ADXL345 3 Axis Accelerometer


The ADXL345 is a 3-axis acceleration module. Playing with Arduino, Wire.h library is included in the skecth to communicate with the module. In this example, the ADXL345 is configured in I2C mode. Pin A4 of the Arduino (Uno) is connected to the SDA (data) while pin A5 is wired to SCL (clock). CS pin is tied high to enable this mode. As no other devices are connected to the I2C bus, external pull-up resistors are not used in this circuit.


Here, the AUTO_SLEEP (D4) and Measure (D3) bits of the 0x2D register are activated by inserting two lines of code "Wire.write(16)" and "Wire.write(8)" (dec 8 = binary 1000 and dec 16 = binary 10000). Register 0x32 to Register 0x37 hold the output data for each axis (X, Y, Z). Put it simply, two registers are used to store the data for each axis.

#include <Wire.h>

#define accel_module (0x53)

void setup(){
  Wire.begin();
  Serial.begin(9600);

  Wire.beginTransmission(accel_module);
  Wire.write(0x2D);
  Wire.write(0);
  Wire.endTransmission();

  Wire.beginTransmission(accel_module);
  Wire.write(0x2D);
  Wire.write(16);
  Wire.endTransmission();

  Wire.beginTransmission(accel_module);
  Wire.write(0x2D);
  Wire.write(8);
  Wire.endTransmission();
}

void loop(){
  int x1reg=0x32;
  int x2reg=0x33;
  int y1reg=0x34;
  int y2reg=0x35;
  int z1reg=0x36;
  int z2reg=0x37;

  int x1pos, x2pos, y1pos, y2pos, z1pos, z2pos;
  
  byte values[6];
  char output[512];

  Wire.beginTransmission(accel_module);
  Wire.write(x1reg); //Move the register pointer back to 0x32
  Wire.endTransmission();

  Wire.beginTransmission(accel_module);
  Wire.requestFrom(accel_module,1);
  values[0]=Wire.read();
  x1pos=(int)values[0];
  sprintf(output,"%d ",x1pos);
  Serial.print(output);
  Wire.endTransmission();


  Wire.beginTransmission(accel_module);
  Wire.write(x2reg);
  Wire.endTransmission();

  Wire.beginTransmission(accel_module);
  Wire.requestFrom(accel_module,1);
  values[1]=Wire.read();
  x2pos=(int)values[1];
  sprintf(output,"%d ",x2pos);
  Serial.print(output);
  Wire.endTransmission();


  Wire.beginTransmission(accel_module);
  Wire.write(y1reg);
  Wire.endTransmission();

  Wire.beginTransmission(accel_module);
  Wire.requestFrom(accel_module,1);
  values[2]=Wire.read();
  y1pos=(int)values[2];
  sprintf(output,"%d ",y1pos);
  Serial.print(output);
  Wire.endTransmission();


  Wire.beginTransmission(accel_module);
  Wire.write(y2reg);
  Wire.endTransmission();

  Wire.beginTransmission(accel_module);
  Wire.requestFrom(accel_module,1);
  values[3]=Wire.read();
  y2pos=(int)values[3];
  sprintf(output,"%d ",y2pos);
  Serial.print(output);
  Wire.endTransmission();


  Wire.beginTransmission(accel_module);
  Wire.write(z1reg);
  Wire.endTransmission();

  Wire.beginTransmission(accel_module);
  Wire.requestFrom(accel_module,1);
  values[4]=Wire.read();
  z1pos=(int)values[4];
  sprintf(output,"%d ",z1pos);
  Serial.print(output);
  Wire.endTransmission();

  Wire.beginTransmission(accel_module);
  Wire.write(z2reg);
  Wire.endTransmission();

  Wire.beginTransmission(accel_module);
  Wire.requestFrom(accel_module,1);
  values[5]=Wire.read();
  z2pos=(int)values[5];
  sprintf(output,"%d ",z2pos);
  Serial.print(output);
  Wire.endTransmission();

  Serial.write(10);

  delay(2000);
}


Wednesday, June 15, 2016

KY-026 IR Based Flame Detector


The 3-pin module detects the infrared in the flame in the range 760 to 1100nm. Aiming a TV remote control at the sensor will also work. Digital pin DO produces high or low electric level signal output. There is no analog output on the module used here. Sensitivity is adjustable via the onboard blue potentiometer. This module also comes equipped with a power supply indicator lamp and a comparator output indicator lamp. When the a certain threshold is reached, the comparator lamp lights up.

In the circuit below, the Arduino pin 12 that acts as digital input is connected to the digital pin DO on the sensor. When flame is detected, the onboard green LED on Arduino will illuminate. Keep in mind that the output from the board used here is HIGH when no flame or infrared emission is detected.


int ledPin=13;
int sensorPin=12;
int val;

void setup() {
  pinMode(ledPin,OUTPUT);
  pinMode(sensorPin,INPUT);
}

void loop() {
  val=digitalRead(sensorPin);
  if(val==HIGH){
    digitalWrite(ledPin,LOW);
  }
  else{
    digitalWrite(ledPin,HIGH);
  }
  //delay(500);
}

Tuesday, June 14, 2016

BMP180 Barometric Pressure Sensor


This sensor module can be used to calculate temperature, pressure, and altitude. There are five pin connections on this module that include VCC, GND, SCL, SDA, and 3.3. In the circuit below, the 3.3 pin is left unconnected. The I2C pins, SDA (Serial Data) and SCL (Serial Clock), connect to pin A4 and pin A5 of Arduino. The module's VCC pin is connected to the Arduino's 5V supply pin. BMP180 modules from other manufacturers may require different connections. Boards with four or six pins are available in the market.

This example uses the SFE_BMP180 library from SparkFun that can be downloaded here. One of the two examples from the library (SFE_BMP180_example) is then executed. The output can be seen on the serial monitor.


Monday, June 13, 2016

SW-18010P Vibration Sensor Module


This module uses SW-18010P spring type vibration switch to detect vibration of the surrounding environment. It does not require a large amount of vibration to generate triggering effect. A green LED light on the module will turn on when the module is shaken or external force is applied to the sensor. Sensitivity is adjustable via the blue digital potentiometer.

In the circuit below, the module's digital pin D0 connects to the the Arduino's digital pin 12. Put it simply, pin 12 is used to detect the high and low level. The Arduino's built-in LED light will be activated when vibration is detected. Keep in mind that when there is no vibration, the output from the sensor is HIGH. The opposite applies when the sensor detects vibration.


int ledPin=13;
int sensorPin=12;
int sensorValue=0;
 
void setup ()
{
  pinMode(ledPin,OUTPUT) ;
  digitalWrite(ledPin,LOW);
  pinMode(sensorPin,INPUT) ;
}
 
void loop ()
{
  sensorValue=digitalRead(sensorPin);
  if(sensorValue==HIGH)
  {
    digitalWrite(ledPin,LOW);
  }
  else
  {
    digitalWrite(ledPin,HIGH);
  }  
}

Sunday, June 12, 2016

KY-038 Sound Detection Module


Designed for sound detection, the KY-038 is equipped with an electret microphone. The connections of the module is straightforward. It only has four pins that include + , G, A0 (Analog), and D0 (Digital). There are two red LEDs on the module, one for power and the other will light up when sound reaches a certain value.

In the circuit below, only the analog pin connects to the Arduino. The KY-038 seems to have low sensitivity. The potentiometer on the module is utilized to adjust the sensitivity of the sensor. The default sensor value (when everything is quiet) is 500. This makes it more responsive to the incoming signals. When signal comes above 550 or below 500, the value will be displayed on the serial monitor. The second red LED on the module will also illuminate.


int sensorPin = A0;
int sensorValue = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  sensorValue = analogRead(sensorPin);    
  if(sensorValue>550){
    Serial.println(sensorValue);
  }
  if(sensorValue<500){
    Serial.println(sensorValue);
  }
  //delay(100);
}