Saturday, 10 May 2014

THE ULTRA SONIC SENSOR

 
THIS IS ONE COOL WAY TO TRY OUT SOMETHING WE'VE ALL BEEN DOING SINCE GRADE ONE...
SO THE BIG QUESTION IS "WHAT IS AN ULTRA-SONIC SENSOR...WHAT DOES IT DO?" 

WELL AMONGST OTHER THINGS, IT CAN BE USED TO MEASURE DISTANCE BETWEEN OBJECTS.IT WORKS BY SENDING A SIGNAL FROM ONE OF THE OUTPUTS, THE TRANSMITTER (SEEN HERE ON THE LEFT, MARKED 'T'), THIS SIGNAL, DEPENDING ON ITS STRENGTH, HITS A SOLID OBJECT AND IS REFLECTED BACK, RECEIVED BY THE OTHER OUTPUT (RECEIVER-'R'), AND THE DISTANCE IS CALCULATED
  
 MATERIALS NEEDED
  • ARDUINO BOARD AND CABLE
  • BREAD BOARD
  • 220 OHM RESISTOR FOR THE LED
  • ULTRA-SONIC SENSOR
  • JUMPER WIRE 
  • LED
 THIS IS THE ULTRA SONIC SENSOR (the pins from left to right are VCC, TRIG, ECHO and GND)


 
NOTE: CONNECT YOUR CIRCUIT AS FOLLOWS
  • VCC TO ARDUINO 5V
  • GND TO ARDUINO GND
  • ECHO TO ARDUINO PIN 7
  • TRIG TO ARDUINO PIN 8
  • LED TO ARDUINO PIN 9


 AND THE CODE (QUITE LENGTHY, OOOPS):



int echopin =7;
int trigpin =8;
int led = 9;
int maxdistance = 200;
int mindistance = 0;
long duration, distance;
void setup(){
  Serial.begin(9600);
  pinMode(trigpin,OUTPUT);
  pinMode(echopin,INPUT);
  pinMode(led,OUTPUT);
}
void loop(){
  digitalWrite(trigpin,LOW);
  delayMicroseconds(2);
  digitalWrite(trigpin,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigpin,LOW);
  duration = pulseIn(echopin,HIGH);
  distance = duration/58.2;
if (distance >= maxdistance||distance <= mindistance){
    Serial.println("OUT OF RANGE");
    digitalWrite(led,HIGH);
  }
  else{
    Serial.println(distance);
    digitalWrite(led,LOW);
  }
  delay(50);
}



 SO WHAT DO YOU THINK?

THINK+CREATE+REPEAT

No comments :

Post a Comment