Categories

Arduino tip sampling analog data

Sampling sata is particularly useful for analog sensors such as an LDR or a thermistor

You can change the amount of samples to take and the interval which is in millioseconds

int sampleData(int analogPin, int samples = 10, int sampleInterval = 100) 
{ 
int sampleData[samples];
int val = 0;
for (int i = 0; i<samples; i++) 
{
sampleData[i] = analogRead(analogPin);
val = val + sampleData[i];
delay(sampleInterval);
}
val = (val / samples);
return map(val, 550, 1023, 100, 0);
}
Share

3 channel tracking sensor example

This Tracking Sensor for Arduino can detect the white lines in black and black lines in white. This particular module has 3 sensors

Using infrared light detection, anti-interference ability
Built-in LED indicator lights
Sensor CTRT5000, high sensitivity, stable performance
Operating voltage 5V, output low black line, white line output high

 

Connection

Module Pin Arduino pin
 Vcc  5v
 L  Arduino Pin 4
 C  Arduino Pin 5
 R  Arduino Pin 6
 Gnd  Gnd

 

Code

// connect the sensors to digital pins
#define LEFT_SENSORPIN 4
#define CENTER_SENSORPIN 5
#define RIGHT_SENSORPIN 6
 
void setup()
{
  Serial.begin(9600);
  pinMode(LEFT_SENSORPIN,INPUT);
  pinMode(CENTER_SENSORPIN,INPUT);
  pinMode(RIGHT_SENSORPIN,INPUT);
}
 
void loop()
{
  // read input from sensors
  byte leftSensor=digitalRead(LEFT_SENSORPIN);
  byte centerSensor=digitalRead(CENTER_SENSORPIN);
  byte rightSensor=digitalRead(RIGHT_SENSORPIN);
 
  Serial.print(" Left : ");
  Serial.print(leftSensor);
  Serial.print(" Centre : ");
  Serial.print(centerSensor);
  Serial.print(" Right : ");
  Serial.print(rightSensor);
  Serial.println();
  delay(1000);
}

 

Links

5V 3 Channel Infrared Line Track Tracking Tracker Sensor Module For Arduino

Share

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