Il progetto consiste nel far seguire ad una breadboard la luce nelle tre dimensioni.
Materiali
- Arduino Uno (1x)
- HS-422 Deluxe Standard Servo (o simile) (2x)
- Staffa Lunga a U (2x)
- Barre metalliche (4x)
- Breadboard 400 punti (2x)
- Fotoresistenze (4x)
- Resistenze 220 ohm (4x)
- Led RGB (1x)
Realizzazione
Chiedo scusa per la qualità della foto ma il progetto è stato realizzato molto tempo fa ed è l’unica ritrovata; spero tuttavia la struttura risulti chiara.
- Piegare due barre metalliche in modo da far avvolgere loro i due servomotori. Praticare due fori per unirle alle altre due barre.
- Montare la staffa ad U sul servo inferiore
- Montare la seconda staffa ad U ruotata di 90 gradi sulla prima.
- Montare il secondo serv0 sulla seconda staffa.
- Cablare la breadboard con le fotoresistenze (le fotoresistenze devono trovarsi ai quattro angoli)
- Montare la breadboard con le fotoresistenze sulla barra metallica del servo superiore
- Cablare il led RGB
Nel progetto ultimato la breadboard superiore è stata spostata sotto e sostituita da un piccolo pannello fotovoltaico. Ai quattro angoli del pannello sono state fissate le fotoresistenze, prolungate mediante saldatura e ricollegate alla breadboard.
Codice
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | #include <Servo.h> #include <Adafruit_NeoPixel.h> #include <avr/power.h> #define PIN 11 Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_RGB + NEO_KHZ800); const int soglia = 10; //modifica parametro per modificare sensibilità luminosa const int sogliaLED = 500; //inserisci valore media delle fotoresistenze int velocita_servo = 25; //più si alza il valore più rallentano i servo Servo myservoD; int up_averageD; int down_averageD; Servo myservoU; int up_averageU; int down_averageU; int A0_val; int A1_val; int A2_val; int A3_val; int valD = 90; int valU = 90; int diffDpos; int diffDneg; int diffUpos; int diffUneg; int media; int ledR=11; int ledG=10; int ledB=9; int luce=0; int valR; int valG; int valB; void setup () { pinMode (A0, INPUT ); pinMode (A1, INPUT ); pinMode (A2, INPUT ); pinMode (A3, INPUT ); pinMode (ledR, OUTPUT ); pinMode (ledG, OUTPUT ); pinMode (ledB, OUTPUT ); myservoD.attach(13); myservoD.write(valD); myservoU.attach(12); myservoU.write(valU); Serial.begin(9600); delay (3000); A0_val = analogRead (A0); //reading data from sensors A1_val = analogRead (A1); A2_val = analogRead (A2); A3_val = analogRead (A4); media = (A0_val + A1_val + A2_val + A3_val) / 4; Serial.println( "Media: " + String (media)); Serial.println( "A0: " + String (A0_val)); Serial.println( "A1: " + String (A1_val)); Serial.println( "A2: " + String (A2_val)); Serial.println( "A3: " + String (A3_val)); } void loop () { A0_val = analogRead (A0); //reading data from sensors A1_val = analogRead (A1); A2_val = analogRead (A2); A3_val = analogRead (A3); down_averageD = (A0_val + A1_val)/2; //the sum of the two lower sensors /2 up_averageD = (A2_val + A3_val)/2; //the sum of the two upper sensors /2 diffDpos = abs (up_averageD-down_averageD); //checking the difference between the two averages diffDneg = abs (down_averageD-up_averageD); if ((up_averageD > down_averageD) && (diffDpos > soglia)) { if (valD < 180) //if different from max val { valD--; myservoD.write(valD); } } if ((down_averageD > up_averageD) && (diffDneg > soglia)) { if (valD > 0) //if different from min val { valD++; myservoD.write(valD); } } delay (velocita_servo); down_averageU = (A0_val + A3_val)/2; //the sum of the two lower sensors /2 up_averageU = (A1_val + A2_val)/2; //the sum of the two upper sensors /2 diffUpos = abs (up_averageU-down_averageU); //checking the difference between the two averages diffUneg = abs (down_averageU-up_averageU); if ((up_averageU > down_averageU) && (diffUpos > soglia)) { if (valU < 180) //if different from max val { valU++; myservoU.write(valU); } } if ((down_averageU > up_averageU) && (diffUneg > soglia)) { if (valU > 0) //if different from min val { valU--; myservoU.write(valU); } } delay (velocita_servo); media = (A0_val + A1_val + A2_val + A3_val) / 4; if (media < (sogliaLED - 100)) { strip.setPixelColor(0, 255, 0, 0); //RED strip.show(); } if (media >= (sogliaLED - 100) && media <= (sogliaLED + 100)) { strip.setPixelColor(0, 255, 75, 0); //ORANGE strip.show(); } if (media > (sogliaLED + 100)) { strip.setPixelColor(0, 0, 255, 0); //GREEN strip.show(); } } |