4. Si funksionon?
Punon duke derguar nje ultra tingull edhe qendron ne pritje per te
degjuar kete tingull pasi perplaset me objektin edhe kthehet mbas tek
sensori.
Kohezgjatja e pulsit eshte e barabarte me kohen qe I eshte dasht
ultratingullit qe te udhetoj nga sensori tek objekti edhe prap mbas tek
sensori.
Duke perdorut shpejtesin e zerit,
ky uultratingull mund
te konvertohet ne distance.
5. Eksperimenti #1
Cfare do te na duhet?
Platforma Arduino.
Ultrasonic sensor.
Kabulla.
Breadboard.
7. Edhe nje cik programim!
/* Qarku:
* VCC e sensorit eshte lidhur tek +5V
* GND e sensorit eshte lidhur tek ground
* TRIG e sensorit eshte lidhur tek dalja dixhitale 2
* ECHO e sensorit eshte lidhur te dalja dixhitale 4
const int trigPin = 8;
const int echoPin = 7;
void setup() {
// Vendosim nje komunikim serial:
Serial.begin(9600);}
8. Cik me shume programim!
void loop(){
// Do deklarojme variablat per te matur distancen,
// rezultatet e distance do te jen ne kohezgjatje, inches, centimetra: long
duration, inches, cm;
// Trigeri I sensorit do te vendoset High qe ait e gjeneroj nje ultratingull.
// I japim si fillim nje pulse te shkurter LOW qe te zigurohemi qe trigeri te
nxier High:
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
9. Ja edhe pak!
// Lexo sinjalin nga sensori
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
// konvertojme kohen ne distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
}
10. Mbaruam!!!!!
long microsecondsToInches(long microseconds){
// Sipas datasheet te Paralax na duhen 73,746 miktosekonta per
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds){
// Shpejtesia e zerit eshte 340m/s ose 29 mikrosekonta per
return microseconds / 29 / 2;
}
16. IR Sensor
Sensoret IR jane mikrocipe te vegjel!
Kan nje qelize qe eshte e ndjeshme ndaj drites Infra te
kuqe!
Ndodhen ne nje pjes te madhe te paisjeve
elektroshtepiake si psh:
TV, DVD, Stereo etj.
17. Photo resistors
Photo resistor ose ndryshe e njofur si resistenca te
varura nga drita(Light Dependent Resistor”LDR”)
Jane resistenca te ndryshueshme ne varesi se sa drite u
ekspozohet
18. IR Sensor vs Photo resistor
Detektojne ngjyrat
edhe driten e
dukshme nga syri I
njeriut.
Mund te detektojne te
tera frekuencat.
Sillen si resistenca.
Jane te filtruar
apostafat per te mare
driten infra te kuqe.
Kane demodulator qe
kerkon driten IR ne
moduluar ne
frekuencen 38kHz.
Jane dixhital, nxierin 0
ose 1.
20. Si thoni per pak programim?
//Si fillim do deklarojm se ku do lidhet sensori me
Arduinon..
// Kjo do na e bej me t thjesht qe te ndjekim kodin me
poshte.
int sensorPin = A0;
int ledPin = 9;
// Gjithashtu do vendosim disa variable globale per
nivelin e drites.
int max = 100;
21. void setup() {
// Do deklarojme pin-in e Led-it edhe LDR qe te jet
OUTPUT.
pinMode(LED, OUTPUT);
pinMode(LDR, OUTPUT);
base = analogRead(LDR);
Serial.begin(9600);
}
22. void loop() {
Int v = analogRead(LDR);
Serial.prinln(v);
If ( v > threshold){
digitalWrite(LED, LOW);}
else{
digitalWrite(LED, HIGH);
}}
24. Pasi mbaruam qarkun!
Do hedhim librarin qe kemi shkarkuar nga
https://github.com/shirriff/Arduino-IRremote
tek Arduino->Libraries
Duhet te sigurohemi qe emri I folderit qe kemi shkarkuar te mos ket “ -
, . ! “ te jet vetem shkronja
Do shkojme tek File->Examples->Irremote
->IRrecvDemo
Pasi ngarkuam kodin ne arduino do hapim Serial Monitor qe te
shikojme se ca vlerash na vijne nga pulti.
Vlerat vijn ne form hexadecimale.
Do shtypim butonat qe na
interesojne edhe do shenojme
kodin e tyre !
26. #include <IRremote.h>
int before;
int out=9; //connect your LED to pin 9
int RECV_PIN = 11; //data out of IR receiver connects to pin 11
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup(){
irrecv.enableIRIn(); // start the receiver
before=0; //LED is turned off
bright=255; //brightness value is at maximum (255)
pinMode(out,OUTPUT);
}
27. void loop() {
if (irrecv.decode(&results)) {
if (results.value==0x20DF8D72){ //Code to turn the LED ON/OFF
if(before==0){ // if the LED was turned off, then we turn it on
digitalWrite(out,HIGH);
before=1; //LED is now turned on
}
else{
digitalWrite(out,LOW); //if the LED was turned on, then we turn it off
before=0;
}}
irrecv.resume();
}}