lunes, 15 de abril de 2013

Cheapest Smart Car Robot: parts, examples of use and documentation

[caption id="attachment_1552" align="aligncenter" width="600"]Ultrasonic Smart Car Kit Ultrasonic Smart Car Kit[/caption]

[caption id="attachment_1746" align="alignleft" width="150"]Funduino Arduino DuemilaNove clon Funduino Arduino DuemilaNove clon[/caption]

It's really cheap but it does not include any documentation; but don't panic, all you will need can be found on Internet. And now, the main electronic components: the microcontroller, the dual motor driver, the ultrasonic sensor and the servo:

The microcontroller brain is a Funduino (Arduino Duemilanove clone), and as far I've used it (and as other buyer said is fully, at least for software, compatible). Here we will not have any problem because there are a lot of documentation about Arduino and Duemilanove.

A simple hello world example (here the file)

[sourcecode language="c"]

// Blinking LED

int ledPin = 13;                 // LED connected to digital pin 13

void setup()
{
Serial.begin(57600);
printf ("Setup/n/l");
Serial.println("Hello world!");
pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop()
{
printf ("2009");
Serial.println("2009");
digitalWrite(ledPin, HIGH);   // sets the LED on
delay(1000);                  // waits for a second
digitalWrite(ledPin, LOW);    // sets the LED off
delay(1000);                  // waits for a second
}

[/sourcecode]

[caption id="attachment_1748" align="alignleft" width="150"]Dual_H-Bridge_Motor_Driver Dual_H-Bridge_Motor_Driver[/caption]

But to control the two motors this kit use an Dual H-Bridge motor driver (L298). Here (read the Drive Two DC Motors section) you can find a lot of useful documentation and examples,  and  here you can find also more information, specially about electronics.

Here the file with the example

[sourcecode language="c"]
int ENA=5;//connected to Arduino's port 5(output pwm)
int IN1=2;//connected to Arduino's port 2
int IN2=3;//connected to Arduino's port 3
int ENB=6;//connected to Arduino's port 6(output pwm)
int IN3=4;//connected to Arduino's port 4
int IN4=7;//connected to Arduino's port 7
void setup()
{
Serial.begin(57600);
Serial.println("Two motors");
pinMode(ENA,OUTPUT);//output
pinMode(ENB,OUTPUT);
pinMode(IN1,OUTPUT);
pinMode(IN2,OUTPUT);
pinMode(IN3,OUTPUT);
pinMode(IN4,OUTPUT);
digitalWrite(ENA,LOW);
digitalWrite(ENB,LOW);//stop driving
digitalWrite(IN1,LOW);
digitalWrite(IN2,HIGH);//setting motorA's directon
digitalWrite(IN3,HIGH);
digitalWrite(IN4,LOW);//setting motorB's directon
}
void loop()
{
analogWrite(ENA,255);//start driving motorA
analogWrite(ENB,255);//start driving motorB
delay(3000);
analogWrite (IN1,0);//stop driving motorA
analogWrite (IN2,0);//stop driving motorB

analogWrite (IN3,0);//stop driving motorA
analogWrite (IN4,0);//stop driving motorB

delay (3000);

int ledPin = 13;
while (1)
{
digitalWrite(ledPin, HIGH);   // sets the LED on
delay(1000);                  // waits for a second
digitalWrite(ledPin, LOW);    // sets the LED off
delay(000);
}
<pre>[/sourcecode]

[caption id="attachment_1753" align="alignleft" width="150"]Ultrasonic sensor hc-sr04 Ultrasonic sensor hc-sr04[/caption]

The HC-SR04 ultrasonic distance sensor, example of use (here the file):

[sourcecode language="c"]

#define trigPin 9
#define echoPin 11

void setup() {
Serial.begin (115200);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}

void loop() {
int duration, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance > 400 || distance < 0){
Serial.println("Out of range");
}
else {
Serial.print(distance);
Serial.println(" cm");
}
delay(500);
}

[/sourcecode]


[caption id="attachment_1755" align="alignleft" width="150"]TowerPro micro servo SG90 TowerPro micro servo SG90[/caption]

And the Tower PRO SG-90 micro servo (and here the file with the example):

[sourcecode language="c"]
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// a maximum of eight servo objects can be created

int pos = 0;    // variable to store the servo position

void setup()
{
myservo.attach(3);  // attaches the servo on pin 3 to the servo object
}

void loop()
{
for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
{                                  // in steps of 1 degree
myservo.write(pos);              // tell servo to go to position in variable 'pos'
delay(15);                       // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
{
myservo.write(pos);              // tell servo to go to position in variable 'pos'
delay(15);                       // waits 15ms for the servo to reach the position
}
}
[/sourcecode]

Soon I will add an LCD display with 6 buttons

No hay comentarios:

Publicar un comentario