sâmbătă, 12 mai 2012

Ultrasound Measurement Device - part.1


Work in progress...

The objective of this work is to design and manufacture a machine to measure distances using an ultrasonic sensor. Because sound speed variation with temperature, will be implemented and a temperature sensor, which will increase measurement accuracy.

The schematics:
The PCB:



The components:
IC1 – ATMEGA8,
IC2 – LM7805,
D1 – 1N4004,
C6,C7 – 47uF,
C2,C3 – 22pF,
C1,C4,C5,C8,C9,C12 – 100nF,
R1,R4 – 10K,
R2 – 330R,
R3 – 220R,
R7 – 1K,
Trimmer 10K,
Q1 – 16MHz,
L1,L2 – Led,

 Code i used for testing:

///----------------------------------------///
///         by gabimincu 10.05.2012        ///
///  masurarea distantelor cu ultrasunete  ///
///           gabimincu@gmail.com          ///
///        www.robot-fun.blogspot.com      ///
///----------------------------------------///

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int pingPin = 7;               // pin trig senzor
const int inPin = 9;                 // pin echo senzor
int t=0;
int i;
float tempc = 0,temp;                     //variabile temperatura
int d;                        
float durata,cm;                     //variabile distanta

void setup()
{
  Serial.begin(9600);
  lcd.begin(16, 2);
  pinMode(8,INPUT);
}

void loop()
{  
  afisare();






Do you want the rest of the code?

}





Next step: construction of box

duminică, 15 aprilie 2012

Almost ready...





Built with PIC 18F2550 from Microchip.

Future improvement: implementation of a steering control so you just turn to the desired angle.
For now this is my mobile robot:



This is the Pinguino with 18F2550 from Microchip:


This is DC motor controller which I have used.

..and the unipolar stepper controller:


And the code that I use it now:

#include
#include

const int pingPin = 7;
const int SafeDist = 40;
unsigned long duration;
long int cm,st,dr;
int motorPin1=14;
int motorPin2=16;
int motorPin3=13;
int motorPin4=15;
int motorDelay=3;/// viteza stepper
int i;

void setup()
{
///pini motoare dc
pinMode (0,OUTPUT);
pinMode (1,OUTPUT);
pinMode (2,OUTPUT);
pinMode (3,OUTPUT);
///pini stepper bipolar
pinMode(13, OUTPUT);
pinMode(14, OUTPUT);
pinMode(15, OUTPUT);
pinMode(16, OUTPUT);
}

void SonarScan()
{
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH,10000);
}

void inainte()
{
digitalWrite(0, HIGH);
digitalWrite(1, LOW);
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
delay(200);
digitalWrite (0,LOW);
digitalWrite (1,LOW);
digitalWrite (2,LOW);
digitalWrite (3,LOW);
}
void ho()
{
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
}
void inapoi()
{
digitalWrite (0,LOW);
digitalWrite (1,HIGH);
digitalWrite (2,LOW);
digitalWrite (3,HIGH);
delay(1000);
digitalWrite (0,LOW);
digitalWrite (1,LOW);
digitalWrite (2,LOW);
digitalWrite (3,LOW);
}
void dreapta()
{
digitalWrite (0,HIGH);
digitalWrite (1,LOW);
digitalWrite (2,LOW);
digitalWrite (3,HIGH);
delay(666);
digitalWrite (0,LOW);
digitalWrite (1,LOW);
digitalWrite (2,LOW);
digitalWrite (3,LOW);
}
void stanga()
{
digitalWrite (0,LOW);
digitalWrite (1,HIGH);
digitalWrite (2,HIGH);
digitalWrite (3,LOW);
delay(666);
digitalWrite (0,LOW);
digitalWrite (1,LOW);
digitalWrite (2,LOW);
digitalWrite (3,LOW);
}
///baleere stanga
void bast()
{
for(i=1;i<130;i++)
{
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(motorDelay);

digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(motorDelay);

digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(motorDelay);

digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(motorDelay);
}
}
///baleere dreapta
void badr()
{
for(i=1;i<130;i++)
{
digitalWrite(motorPin4, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin1, LOW);
delay(motorDelay);

digitalWrite(motorPin4, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin1, HIGH);
delay(motorDelay);

digitalWrite(motorPin4, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin1, HIGH);
delay(motorDelay);

digitalWrite(motorPin4, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin1, LOW);
delay(motorDelay);
}
}
void loop()
{
SonarScan();
if (duration < 2000)
{
ho();
duration=0;
delay(300);
badr();
SonarScan();
dr=duration;
bast();
bast();
SonarScan();
badr();
st= duration;
if (dr< 2000 && st <2000)
{
inapoi();
stanga();
delay(55);
stanga();
}
else if (dr > st)
{
dreapta();
}
else stanga();
}
else inainte();
}