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.
• 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
VCC -- VCC
GND -- GND
Signal -- Analog 0
#define pin A0
void setup ()
pinMode (pin, INPUT);
void loop ()
uint16_t value = analogRead (pin);
uint16_t range = get_gp2d12 (value);
Serial.println (" mm");
uint16_t get_gp2d12 (uint16_t value)
if (value < 10) value = 10;
return ((67870.0 / (value - 3.0)) - 40.0);
GP2Y0A21YK0F GP2Y0A21 Infrared Proximity Sensor IR Analog Distance Sensor VE713 P
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.
I found this schematic online for the module
The following schematic shows how to connect the module to an Arduino, I have only shown one device (lightbulb) connected to one relay
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;
digitalWrite(RelayControl1,HIGH);// NO1 and COM1 Connected (LED on)
digitalWrite(RelayControl1,LOW);// NO1 and COM1 disconnected (LED off)
1PC/LOT 5V 4-Channel Relay Module Shield for Arduino ARM PIC AVR DSP Electronic 5V 4 Channel Relay Newest
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.
//set all as inputs
//set all high
//Read the value of the buttons and print it on the serial port.
PS2 JOYSTICK SHIELD V2.0 for Arduino
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.
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
Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
val=analogRead(0); //connect sensor to Analog 0
Serial.println(val);//print the value to serial
LX1972 Analog Light Sensor DIY Maker Illumination Sensor Module