Laporan Praktikum Sistem Embedded Modul ARDX CIRC-09 – Foto resistor

Apa yang kita lakukan?

Mendapatkan inputan dari potensiometer bisa berguna untuk eksperimen yang dikendalikan manusia, tapi gimana kalau kita mau eksperimen yang dikendalikan lingkungan? Kita menggunakan prinsip yang hampir sama, tapi dibandingkan menggunakan potensiometer, kita pakai photo resistor (light dependent resistor / sensor cahaya). Arduino gak bisa merasakan resistansi langsung (dia merasakan voltage), jadi kita membuat voltage divider. 

Rangkaian : 

Code (bisa didapatkan di http://ardx.org/CODE09)

/*
 * A simple programme that will change the intensity of
 * an LED based  * on the amount of light incident on 
 * the photo resistor.
 * 
 */

//PhotoResistor Pin
int lightPin = 0; //the analog pin the photoresistor is 
                  //connected to
                  //the photoresistor is not calibrated to any units so
                  //this is simply a raw sensor value (relative light)
//LED Pin
int ledPin = 9;   //the pin the LED is connected to
                  //we are controlling brightness so 
                  //we use one of the PWM (pulse width
                  // modulation pins)
void setup()
{
  pinMode(ledPin, OUTPUT); //sets the led pin to output
}
 /*
 * loop() - this function will start after setup 
 * finishes and then repeat
 */
void loop()
{
 int lightLevel = analogRead(lightPin); //Read the
                                        // lightlevel
 lightLevel = map(lightLevel, 0, 900, 0, 255); 
         //adjust the value 0 to 900 to
         //span 0 to 255



 lightLevel = constrain(lightLevel, 0, 255);//make sure the 
                                           //value is betwween 
                                           //0 and 255
 analogWrite(ledPin, lightLevel);  //write the value
}

Coding ini menghasilkan LED yang akan mati kalau sensor mendeteksi cahaya.


Gak jalan? 

  1. LED tetap gak nyala
    Inilah kesalahan yang terus kita bikin yang terus terusan ngabisin waktu. Coba aja mereka bisa bikin LED yang bisa ditukar PIN nya.
    Coba putar LED nya, baru coba lagi.
  2. Sensornya gak merespon perubahan cahaya
    Karena tempat merakitnya memang sempit, mungkin aja salah rakit. Coba rakit ulang.
  3. Masih gak jalan juga?
    Mungkin kamu berada di ruangan yang terlalu terang, atau terlalu gelap. Coba matiin lampu. Atau kalau ada senter (di lab sini adanya laser), coba pakai.

Lebih lanjut : http://ardx.org/CIRC09

Tugas kampus : Ketika lasernya kena sensor, LEDnya hidup. Kalau lasernya dimatikan, lampunya mati. Tampilkan keluaran sensor pada Serial Monitor.

int lightPin=0;
void setup()
{
 Serial.begin(9600);
 pinMode(ledPin, OUTPUT); //sets the led pin to output
}
 
void loop()
{
 int lightLevel = analogRead(lightPin); 
 
 Serial.print(lightLevel);
 Serial.print("\n");
 lightLevel = map(lightLevel, 0, 300, 255, 0); 




 lightLevel = constrain(lightLevel, 0, 255);//make sure the 
 //value is betwween 
 //0 and 255
 analogWrite(ledPin, lightLevel); //write the value
}

Hasil : 

https://www.instagram.com/p/BVD1Erbh5Ig/?taken-by=rinaldojonathan

Tugas 2 :

  1. Buat buzzer yang membunyikan lagu “Ibu Kita Kartini” (ARDX CIRC06)
  2. Buzzer baru hidup setelah sensor mendeteksi adanya cahaya.
 
int speakerPin = 9;
int ledPin = 9;
int lightPin=0;


int length = 52; // the number of notes
char notes[] = "cdefgecaCbagfagfecdfedcfefagagecedefgefefagagecedfbdc"; // a space represents a rest
int beats[] = { 3,1,2,2,3,1,4,3,1,2,2,8,3,1,2,2,4,4,3,1,2,2,8, 3,1,2,2,1,1,1,1,2,2,2,2,2,2,8,3,1,2,2,1,1,1,1,2,2,2,2,2,2,8 };
int tempo = 300;

void playTone(int tone, int duration) {
 for (long i = 0; i < duration * 1000L; i += tone * 2) {
 digitalWrite(speakerPin, HIGH);
 delayMicroseconds(tone);
 digitalWrite(speakerPin, LOW);
 delayMicroseconds(tone);
 }
}

void playNote(char note, int duration) {
 char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
 int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
 
 // play the tone corresponding to the note name
 for (int i = 0; i < 8; i++) { if (names[i] == note) { playTone(tones[i], duration); } } } void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); //sets the led pin to output pinMode(speakerPin, OUTPUT); } void loop() { int lightLevel = analogRead(lightPin); lightLevel = map(lightLevel, 0, 900, 0, 255); //adjust the value 0 to 900 to //span 0 to 255 lightLevel = map(lightLevel, 0, 300, 255, 0); if ( lightLevel >200)
 {
 for (int i = 0; i < length; i++) {
 if (notes[i] == ' ') {
 delay(beats[i] * tempo); // rest
 } else {
 playNote(notes[i], beats[i] * tempo);
 }
 
 // pause between notes
 delay(tempo / 2); 
 }
 }
}

https://www.instagram.com/p/BVD4b-eBnVg/?taken-by=rinaldojonathan

Kesimpulan : Sekarang kami bisa menggunakan sensor cahaya dengan Arduino. Tapi untuk menghidupkan lagu dengan cahaya, saya belum tahu apa kegunaannya :hammers

Share Button

By Rinaldo Jonathan

Admin of this site. Artis papan PCB. #zoneRinaldo #Controllerism Studio Demon, Stage Angel, Sleepy Developer, Smoke free. Kalkud SHS 2012, PCR G15.

Leave a Reply

Verified by ExactMetrics