User Tools

Site Tools


projektas_nr.6

Čia yra sena dokumento versija!


Projektas Nr. 6. Šviesa – Fotorezistoriai

Ką darysime Potenciometras yra puikus įvesties įrankis žmogaus valdomuose bandymuose. Tačiau ką naudosime aplinkos valdomame bandyme? Vietoje pasukimu valdomos varžos (potenciometro) naudosime šviesa valdomą varžą (fotorezistorių). Arduino tiesiogiai nejaučia varžos, tačiau jaučia įtampą, taigi reiks nustatyti įtampos daliklį http://ardx.org/VODI. Tiksli įtampa jutiklio kontakte yra apskaičiuojama, bet mūsų projektui (šviesos kiekio matavimui) galime pažaisti su reikšmėmis ir pasižiūrėti, kas mums labiausiai tiks. Žemos įtampos pasireikš, kai sensorius gerai apšviestas, o aukštos įtampos susidarys esant mažesniam apšvietimui.

Grandinės dalys

  • CIRC-09 Maketo plokštės šablonas x1
  • 2 kištukų kontaktas
  • Fotorezistorius x1
  • Laidai x3
  • 10k rezistorius (Rudas-Juodas-Oranžinis) x1
  • 560 rezistorius (Žalias-Mėlynas-Rudas)
  • Žalias šviesos diodas x1

Principinė schema

Grandinės šablonas

Surinkta grandinė

Šaltiniai .:Atsisiųsti:. Maketo plokštės šablono - http://ardx.org/BBLS09

.:Žiūrėti:. Surinkimo vaizdo medžiaga - http://ardx.org/VIDE09

Programos kodas (nereikia visko spausdinti) Atsisiųsti programos kodą: http://ardx.org/CODE09 (nukopijuokite tekstą ir įklijuokite tuščiame Arduino IDE lange)

/* * 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 between

                                         //0 and 255

analogWrite(ledPin, lightLevel); write the value } Neveikia? (trys dalykai kuriuos galime padaryti) Šviesos diodas nešviečia Jis nereguoja į šviesos kiekio pakitimus Vis dar neveikia? This is a mistake we continue to make time and time again, if only they could make an LED that worked both ways. Pull it up and give it a twist. Given that the spacing of the wires on the photo-resistor is not standard, it is easy to misplace it. Double check its in the right place. You may be in a room which is either too bright or dark. Try turning the lights on or off to see if this helps. Or if you have a flashlight near by give that a try. Patobulinkime? Reverse the response: Perhaps you would like the opposite response. Don't worry we can easily reverse this response just change: analogWrite(ledPin, lightLevel); —→ analogWrite(ledPin, 255 - lightLevel); Upload and watch the response change: Night light: Rather than controlling the brightness of the LED in response to light, lets instead turn it on or off based on a threshold value. Change the loop() code with. void loop(){ int threshold = 300; if(analogRead(lightPin) > threshold){ digitalWrite(ledPin, HIGH); }else{ digitalWrite(ledPin, LOW); } } Šviesa kontroliuoja servo variklį: Lets use our newly found light sensing skills to control a servo (and at the same time engage in a little bit of Arduino code hacking). Wire up a servo connected to pin 9 (like in CIRC-04). Then open the Knob example program (the same one we used in CIRC-08) File > Examples > Library-Servo > Knob. Upload the code to your board and watch as it works unmodified. Using the full range of your servo: You'll notice that the servo will only operate over a limited portion of its range. This is because with the voltage dividing circuit we use the voltage on analog pin 0 will not range from 0 to 5 volts but instead between two lesser values (these values will change based on your setup). To fix this play with the val = map(val, 0, 1023, 0, 179); line. For hints on what to do visit http://arduino.cc/en/Reference/Map . Kitas projektas. Matuosime temperatūrą davikliu TMP36 Atgal į projektus

projektas_nr.6.1445797243.txt.gz · Keista: 2015/10/25 20:20 vartotojo 193.219.47.27