Categories

Arduino and GP2Y0A21YK Distance Sensor

the GP2Y0A21 is an infrared proximity sensor made by Sharp. Part # GP2Y0A21YK has an analog output that varies from 3.1V at 10cm to 0.4V at 80cm. The sensor has a Japanese Solderless Terminal (JST) Connector.

FEATURES

• Digital Output
• LED Pulse Cycle Duration: 32 ms
• Range: 10 to 80 cm
• Typical response time: 39 ms
• Typical start up delay: 44 ms
• Average Current Consumption: 30 mA
• Detection Area Diameter @ 80 cm: 12 cm

 

Schematic

Code

/*  
VCC -- VCC  
GND -- GND  
Signal -- Analog 0 
 */
 
#define pin A0
 
void setup () 
{
  Serial.begin (9600);
  pinMode (pin, INPUT);
}
 
void loop () 
{
  uint16_t value = analogRead (pin);
  uint16_t range = get_gp2d12 (value);
  Serial.println (value);
  Serial.print (range);
  Serial.println (" mm");
  Serial.println ();
  delay (1000);
}
 
uint16_t get_gp2d12 (uint16_t value) 
{
  if (value < 10) value = 10;
  return ((67870.0 / (value - 3.0)) - 40.0);
}

 

Link
GP2Y0A21YK0F GP2Y0A21 Infrared Proximity Sensor IR Analog Distance Sensor VE713 P

Share

5 Volt 4 Channel Arduino Relay Module example

In this example we will take a look at another relay module, this time this one is called the 5 Volt 4 Channel Arduino Relay Module , here is a picture of the module

This relay module provides four relays that are rated for 7A at either 28VDC or 10A at 125VAC. Each relay has  a Normally Open (NO) and a Normally Closed (NC) contact. This module could be used in various automation projects such as switching lights and motors.

You can see that each relay is controlled by a corresponding input pin called In1 to IN4, there are also LEDs that show if the input is low or high. Another benefit is that each relay is optically isolated using an LTC-817.

 

Module Schematic

I found this schematic online for the module

 

Schematic

The following schematic shows how to connect the module to an Arduino, I have only shown one device (lightbulb) connected to one relay

 

Code

Here is some test code

int RelayControl1 = 4;    // Digital Arduino Pin used to control the motor
int RelayControl2 = 5;  
int RelayControl3 = 6;  
int RelayControl4 = 7;  
 
 
void setup()  
{   
  Serial.begin(9600);
  pinMode(RelayControl1, OUTPUT);
  pinMode(RelayControl2, OUTPUT);
  pinMode(RelayControl3, OUTPUT);
  pinMode(RelayControl4, OUTPUT);
}
 
 
void loop()  
{
 
  digitalWrite(RelayControl1,HIGH);// NO1 and COM1 Connected (LED on)  
  delay(1000);
  digitalWrite(RelayControl1,LOW);// NO1 and COM1 disconnected (LED off)  
  delay(1000);
  digitalWrite(RelayControl2,HIGH);
  delay(1000);
  digitalWrite(RelayControl2,LOW);
  delay(1000);
  digitalWrite(RelayControl3,HIGH);
  delay(1000);
  digitalWrite(RelayControl3,LOW); 
  delay(1000);     
  digitalWrite(RelayControl4,HIGH);  
  delay(1000);
  digitalWrite(RelayControl4,LOW); 
  delay(1000);
}

 

Links
1PC/LOT 5V 4-Channel Relay Module Shield for Arduino ARM PIC AVR DSP Electronic 5V 4 Channel Relay Newest

Share

PS2 JOYSTICK SHIELD V2.0 code example

In this code example we will take a look at the PS2 JOYSTICK SHIELD V2.0.

The X-axis of the joystick is connected to pin A0 of Arduino, the Y-axis to pin A1, power supply to 5V and ground to GND.

There are four buttons on the PS2 JOYSTICK SHIELD . D3 should be connected to digital pin 3; D4 to digital pin4; D5 to digital pin 5; D6 to digital pin 6. The other small button is reset button.
Generally, PS2 rocker can be used for controlling small vehicles. It is mainly comprised of two 10K potentiometers and a button switch. The five ports are VCC, X, Button, Y and GND.

 

Code

char button0=3;
char button1=4; 
char button2=5; 
char button3=6;
char joybutton=2;
 
void setup(void)
{
  //set all as inputs
  pinMode(joybutton, INPUT); 
  pinMode(button0, INPUT);      
  pinMode(button1, INPUT);     
  pinMode(button2, INPUT);
  pinMode(button3, INPUT);
 
  //set all high
  digitalWrite(joybutton, HIGH);
  digitalWrite(button0, HIGH);  
  digitalWrite(button1, HIGH);  
  digitalWrite(button2, HIGH);
  digitalWrite(button3, HIGH);
 
  Serial.begin(9600); 
}
 
void loop(void)
{
  Serial.print(analogRead(0));
  Serial.print(",");
  Serial.print(analogRead(1));
  Serial.print(",");
 
  //Read the value of the buttons and print it on the serial port.
  Serial.print(digitalRead(button0)); 
  Serial.print(digitalRead(joybutton));    
  Serial.print(digitalRead(button0)); 
  Serial.print(digitalRead(button1));  
  Serial.print(digitalRead(button2));  
  Serial.println(digitalRead(button3)); 
 
  delay(1000);
}

 

Links
PS2 JOYSTICK SHIELD V2.0 for Arduino

Share

Arduino and LX1972 light sensor example

The LX1972 is a low cost silicon light sensor with spectral response that closely emulates the human eye. Patented circuitry produces peak spectral response at 520nm, with IR response less than ±5%, of the peak response, above 900nm.

The photo sensor is a PIN diode array with a linear, accurate, and very repeatable current transfer function.

High gain current mirrors on the chip multiply the PIN diode photo-current to a sensitivity level that can be voltage scaled with a standard value external resistor. Output current from this simple to use two-pin device can be used directly or converted to a voltage by placing it in series with a single resistor at either of its two pins.

Dynamic range is determined by the resistors (typically in the range of 10K to 100K) and power supply values. Typically the LX1972 needs only 1.8V of headroom to operate at 1000 Lux illumination.

Internal temperature compensation allows dark current to be kept below 200nA over the full specification temperature range (-40 to +85°), providing high accuracy at low light levels. Usable ambient light conditions range is from 1 to more than 5000 Lux.The LX1972 is optimized for controlling back lighting systems in low cost consumer products such as LCD TV, portable computers, and digital cameras.

lx1972-module

FEATURES:
1. Near Human Eye Spectral Response
2. Very Low IR Sensitivity
3. Highly Accurate & Repeatable Output Current vs. Light
4. Scalable Output Voltage
5. Temperature Stable
6. Integrated High Gain Photo Current Amplifiers
7. No Optical Filters Needed

 

Code

void setup()
{
  Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
}
 
void loop()
{
      int val;
      val=analogRead(0);      //connect sensor to Analog 0
      Serial.println(val);//print the value to serial        
      delay(100);
}

Links

 

LX1972 Analog Light Sensor DIY Maker Illumination Sensor Module

Share