Sunday, March 26, 2017

Wiring diagram


Line following example

// These constants won't change.  They're used to give names
// to the pins used:
const int analogInPinL = A0;  // Analog input pin that the IR sensor is attached to
const int analogInPinR = A1;  // Analog input pin that the IR sensor is attached to

const int maxSpeed = 250;     // fastest the robot will go (on one wheel)

int leftBalance = 50;

int motorLeftSpeed = 150;
int motorRightSpeed = 150;

int sensorValueL = 0;        // value read from the pot
int outputValueL = 0;        // value output to the PWM (analog out)
int sensorValueR = 0;        // value read from the pot
int outputValueR = 0;        // value output to the PWM (analog out)

int combinedSensor = 0;     // value of both sensors

// connect motor controller pins to Arduino digital pins
// motor one
int motorSpeedA = 10;
int motorDirectionAin1 = 9;
int motorDirectionAin2 = 8;
// motor two
int motorSpeedB = 5;
int motorDirectionBin3 = 7;
int motorDirectionBin4 = 6;

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);

 // set all the motor control pins to outputs
  pinMode(motorSpeedA, OUTPUT);
  pinMode(motorSpeedB, OUTPUT);
  pinMode(motorDirectionAin1, OUTPUT);
  pinMode(motorDirectionAin2, OUTPUT);
  pinMode(motorDirectionBin3, OUTPUT);
  pinMode(motorDirectionBin4, OUTPUT);
}

void loop() {

  delay(2);
  sensorValueL = analogRead(analogInPinL);
  sensorValueR = analogRead(analogInPinR);

  combinedSensor = sensorValueL + sensorValueR;

 Serial.print("total sensor = ");
 Serial.println(combinedSensor);

  if (combinedSensor < 2000)

  {
    // turn on motors
    digitalWrite(motorDirectionAin1, HIGH);
    digitalWrite(motorDirectionAin2, LOW); 
    digitalWrite(motorDirectionBin3, HIGH);
    digitalWrite(motorDirectionBin4, LOW);   
Serial.println("motor on");
      motorLeftSpeed = 150;
      motorRightSpeed = 150;

    analogWrite(motorSpeedA, motorLeftSpeed);
    analogWrite(motorSpeedB, motorRightSpeed);
  }

    digitalWrite(motorDirectionAin1, HIGH);
    digitalWrite(motorDirectionAin2, LOW); 
    digitalWrite(motorDirectionBin3, HIGH);
    digitalWrite(motorDirectionBin4, LOW);   

 
  while (combinedSensor < 1500)

  {
    if (combinedSensor < 250)
    {
      motorLeftSpeed = 150;
      motorRightSpeed = 150;
    digitalWrite(motorDirectionAin1, HIGH);
    digitalWrite(motorDirectionAin2, LOW); 
    digitalWrite(motorDirectionBin3, HIGH);
    digitalWrite(motorDirectionBin4, LOW);   

    }

    if ((sensorValueL > 100) && (motorRightSpeed < 250))
    {
      motorLeftSpeed = motorLeftSpeed - 15;
      motorRightSpeed = motorRightSpeed + 10;
    digitalWrite(motorDirectionAin1, LOW);
    digitalWrite(motorDirectionAin2, HIGH); 
    digitalWrite(motorDirectionBin3, HIGH);
    digitalWrite(motorDirectionBin4, LOW);   


    }   

    if ((sensorValueR > 100) && (motorLeftSpeed < 250))
    {
      motorLeftSpeed = motorLeftSpeed + 10;
      motorRightSpeed = motorRightSpeed - 15;
    digitalWrite(motorDirectionAin1, HIGH);
    digitalWrite(motorDirectionAin2, LOW); 
    digitalWrite(motorDirectionBin3, LOW);
    digitalWrite(motorDirectionBin4, HIGH);   

    }   

    analogWrite(motorSpeedA, motorLeftSpeed);
    analogWrite(motorSpeedB, motorRightSpeed);
    delay(5);

    // read the analog in value:
    sensorValueL = analogRead(analogInPinL);
    sensorValueR = analogRead(analogInPinR);

    combinedSensor = sensorValueL + sensorValueR;

  }

    // now turn off motors
    digitalWrite(motorDirectionAin1, LOW);
    digitalWrite(motorDirectionAin2, LOW); 
    digitalWrite(motorDirectionBin3, LOW);
    digitalWrite(motorDirectionBin4, LOW); 
 

}

Motor test

// connect motor controller pins to Arduino digital pins
// motor one
int motorSpeedA = 10;
int motorDirectionAin1 = 9;
int motorDirectionAin2 = 8;
// motor two
int motorSpeedB = 5;
int motorDirectionBin3 = 7;
int motorDirectionBin4 = 6;

void setup() {
 // set all the motor control pins to outputs
  pinMode(motorSpeedA, OUTPUT);
  pinMode(motorSpeedB, OUTPUT);
  pinMode(motorDirectionAin1, OUTPUT);
  pinMode(motorDirectionAin2, OUTPUT);
  pinMode(motorDirectionBin3, OUTPUT);
  pinMode(motorDirectionBin4, OUTPUT);
}



void loop() {

    digitalWrite(motorDirectionAin1, HIGH);
    digitalWrite(motorDirectionAin2, LOW); 
    digitalWrite(motorDirectionBin3, HIGH);
    digitalWrite(motorDirectionBin4, LOW);   

    analogWrite(motorSpeedA, 250);
    analogWrite(motorSpeedB, 250);

    delay(1000);
   
    // now turn off motors
    digitalWrite(motorDirectionAin1, LOW);
    digitalWrite(motorDirectionAin2, LOW); 
    digitalWrite(motorDirectionBin3, LOW);
    digitalWrite(motorDirectionBin4, LOW); 
 
}

Materials

  1. Robot chassis 
    1. 2 wheels
    2. 2 motors
    3. 1 bag of wires
    4. 1 Connection board
    5. 1 On and Off switch
    6. 1 Bag of screws
    7. 1 battery holder
  2. 1 Robot Chassis
  3. 5 AA batteries
  4. 1 L298N Motor control board
  5. 2 infrared sensors
  6. 1 Arduino board with USB cable
  7. 1 power plug
  8. Assorted wires

Roby the Robot


Introduction
I am a 5th grader and won a grant from Disney (www.ysa.org/grants/youth-grants/disney/) to do a service project about robotics. My project is about encouraging young kids in the 4th grade to get excited about science, technology, engineering, and math (STEM) by building a robot. I am planning to teach a class of kids about basic computer programing and how to construct a small robot. This is a free experience and we will provide all the materials, instructions, and volunteers to help everyone.

Project Background
I’m doing this project to help kids understand the importance of robotics. This project is needed so all kids can have a better understanding of how robotics work. My project is also needed, because when kids start to get to my age they tend to drift away from S.T.E.M (science, technology, engineering, and math). However, once you dive in and start learning about robotics and how to do them you find it might be one of your most favorite things in the world.

This is special to me because I love robotics and I want other people to see how much fun robotics is. I think that even a kid who has never tried robotics will instantly fall in love with robotics.

What You Will Learn
Participants will learn how to build, wire, and program a small line follower robot. Roby is constructed of a small chassis with 2 motors controlling the main wheels and a swivel caster. Roby is controlled by a computer board running a program participants will write. The program uses 2 infrared sensors to detect the line on the ground. When one of the sensors detects the line the robot turns in that direction so the line stays under the center of the robot. The robot will keep following the line unless both sensors touch the black.