Selasa, 24 April 2018

DIY 2WD Obstacle Avoider Smart Car Robot

DIY 2WD Obstacle Avoider Smart Car Robot


Bahan-bahan
Arduino Uno R3 + USB Cable
Motor Control Shield
HC-SR04 dan Bracket
Motor DC + Gearbox & Roda
2x 14500 3.7V Li-Ion Battery dan 2xAA Battery Box
2WD Smart Car Chassis dan Spacer
Male to Male Jumper Cable
Male to Female Jumper Cable

Library dan Panduan Motor Control Shield

Pin Out

ARDUINO / MOTOR CONTROL SHIELD

A4
ECHO HC-SR04
A5
TRIGGER HC-SR04
M3
MOTOR / RODA KIRI
M4
MOTOR / RODA KANAN
EXT_PWR
BATTERY (Jumper PWR_JMP)

Sketch
#include <AFMotor.h> // import AdaFruit Motor Shield Library
#define trigPin A5 // define the pins of Ultrasonic HC-SR04 pins
#define echoPin A4
AF_DCMotor motor3(3, MOTOR34_64KHZ); // set up motors
AF_DCMotor motor4(4, MOTOR34_8KHZ);

void setup()
{
  Serial.begin(9600); // begin serial communitication 
  Serial.println("Motor test!");
  pinMode(trigPin, OUTPUT); // set the trig pin to output (Send sound waves)
  pinMode(echoPin, INPUT);  // set the echo pin to input (recieve sound waves)
  motor3.setSpeed(200); //set the speed of the motors, between 0-255
  motor4.setSpeed (200); 
}

void loop()
{
  long duration, distance; // start the scan
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(30); // delays are required for a succesfull sensor operation
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(38); // this delay is required as well!
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2)/29.1; // convert the distance to centimeters
  if (distance < 25) /*if there's an obstacle 25 centimers, ahead, do the following: */
  {  
    Serial.println ("Close Obstacle detected!" );
    Serial.println ("Obstacle Details:");
    Serial.print ("Distance From Robot is " );
    Serial.print ( distance);
    Serial.print ( " CM!"); // print out the distance in centimeters.
    Serial.println (" The obstacle is declared a threat due to close distance. ");
    Serial.println (" Turning !");
    motor3.run(FORWARD); // Turn as long as there's an obstacle ahead.
    motor4.run (BACKWARD);
  }
  else
  {
    Serial.println ("No obstacle detected, going forward");
    delay (10);
    motor3.run(FORWARD); //if there's no obstacle ahead, Go Forward!
    motor4.run(FORWARD); 
  } 
}


Galeri


Rabu, 02 November 2016

KY-031 Knock Impact Sensor Module


KY-031 Knock Impact Sensor Module

KY-031 Knock Sensor PinOuts
KY-031 Knock Sensor Module Schematic
KY-031 Connection to the Arduino
Arduino Sketch
int knockPin = 10; // Use Pin 10 as our Input
int knockLED = 13;
int knockVal = HIGH; // This is where we record our shock measurement
boolean bAlarm = false;unsigned long lastKnockTime; // Record the time that we measured a shock

int knockAlarmTime = 500; // Number of milli seconds to keep the knock alarm high

void setup ()
{
  
Serial.begin(9600); 
  
pinMode (knockPin, INPUT); // input from the KY-031
    pinMode (knockLED, OUTPUT);
}

void loop ()
{
  knockVal = 
digitalRead (knockPin); // read KY-031 Value

  
if (knockVal == LOW) // If we see a knock
  {

    lastKnockTime = 
millis(); // record the time of the shock
    // The following is so you don't scroll on the output screen
    if (!bAlarm)
    {
      
Serial.println("KNOCK, KNOCK");
      digitalWrite (knockLED, HIGH);
      bAlarm = 
true;
    }
  }
  
else
  {
    
if( (millis()-lastKnockTime) > knockAlarmTime  &&  bAlarm)
    {
      
Serial.println("no knocks");
      digitalWrite (knockLED, LOW);
      bAlarm = 
false;
    }
  }
}


Sumber
Keyes KY-031 Arduino Knock Impact Sensor: Manual and Tutorial

Where to Buy
KY-031 Percussion Knock Impact Sensor Module

KY-031 Percussion Knock Impact Sensor Module

Sabtu, 22 Oktober 2016

HC-SR501 PIR (Passive InfraRed) Motion Sensor Module

HC-SR501 PinOuts and Controls
Pin or ControlFunction
Time Delay AdjustSets how long the output remains high after detecting motion.... Anywhere from 5 seconds to 5 minutes.
Sensitivity AdjustSets the detection range.... from 3 meters to 7 meters
Trigger Selection JumperSet for single or repeatable triggers.
Ground pinGround input
Output PinLow when no motion is detected.. High when motion is detected. High is 3.3V
Power Pin5 to 20 VDC Supply input

Device Area of Detection

Time Delay Adjustment

HC-SR501 Connection to Arduino

Arduino Sketch
int ledPin = 13;  // LED on Pin 13 of Arduino
int pirPin = 7; // Input for HC-SR501
int pirValue; // Place to store read PIR Value
void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(pirPin, INPUT);

  digitalWrite(ledPin, LOW);
}
void loop()
{
  pirValue = digitalRead(pirPin);
  digitalWrite(ledPin, pirValue);
}

Sumber
Arduino HC-SR501 Motion Sensor Tutorial

Where to buy
HC-SR501 PIR Motion Sensor Module

HC-SR501 PIR Motion Sensor Module

Senin, 17 Oktober 2016

KY-040 Rotary Encoder Module

KY-040 Rotary Encoder
KY-040 Rotary Encoder PinOut
Keyes Rotary Encoder Schematic
KY-040 Evaluation Circuit
KY-04 Connection to the Arduino
Arduino Sketch
int pinA = 3;  // Connected to CLK on KY-040
int pinB = 4;  // Connected to DT on KY-040
int encoderPosCount = 0;
int pinALast; 
int aVal;
boolean bCW;
void setup()
{
 
pinMode (pinA,INPUT);
  
pinMode (pinB,INPUT);
  
/* Read Pin A
  Whatever state it's in will reflect the last position   
  */
  pinALast = digitalRead(pinA);
  
Serial.begin (9600);
}

void loop()
{
  aVal = 
digitalRead(pinA);
  
if (aVal != pinALast)
  {
    // Means the knob is rotating
    // if the knob is rotating, we need to determine direction
    // We do that by reading pin B.
    if (digitalRead(pinB) != aVal)
    { 
      // Means pin A Changed first - We're Rotating Clockwise
      encoderPosCount ++;
      bCW = 
true;
    }
    else
    {
      // Otherwise B changed first and we're moving CCW
      bCW = false;
      encoderPosCount--;
    }
    
Serial.print ("Rotated: ");
    
if (bCW)
    {
      
Serial.println ("clockwise");
    }
    else
    {
      
Serial.println("counterclockwise");
    }
    
Serial.print("Encoder Position: ");
    
Serial.println(encoderPosCount);
  }
  pinALast = aVal;
}

Sumber
Keyes KY-040 Arduino Rotary Encoder User Manual

Where to buy
KY-040 Rotary Encoder Module


Mukaddimah

BismillaahirRahmaanirRahiim

alHamdulillaah blog ini bisa dibuat. Insha ALLAH kedepannya blog ini akan diisi dengan tutorial dan cara pengetesan komponen, serta beberapa contoh aplikasi atau proyek. Mudah-mudahan blog ini bisa bermanfaat, Aamiiin...