I am having issues with the arduino yun, showing any data in the serial monitor. The sensor lights up when i plug it in but that is about it and the code seems to compile but nothing is coming through. I am using the adafruit color sensor. i have the sda and slc connected to pin 4 and 5. the servo is connected to pin 3. the rest is just on Vin and GND.
#include "Servo.h"
#include "Wire.h"
#include "Adafruit_TCS34725.h"
const int redPos = 160;
const int orangePos = 130;
const int yellowPos = 100;
const int greenPos = 70;
const int bluePos = 30;
const int nonePos = 0; // Kein Objekt erkannt
Servo myservo;
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_1X);
void setup() {
Serial.begin(9600);
Serial.println("Makerblog.at - MuMs Color Sensor");
if (tcs.begin()) {
Serial.println("Sensor gefunden");
} else {
Serial.println("TCS34725 nicht gefunden ... Ablauf gestoppt!");
while (1);
}
// Der Servo hängt am PWM-Pin 3
myservo.attach(3);
// Servo in Grundstellung fahren
myservo.write(0);
delay(1000);
}
void loop() {
uint16_t clearcol, red, green, blue;
float average, r, g, b;
delay(100); // Farbmessung dauert c. 50ms
tcs.getRawData(&red, &green, &blue, &clearcol);
average = (red+green+blue)/3;
r = red/average;
g = green/average;
b = blue/average;
// Clear-Wert und r,g,b seriell ausgeben zur Kontrolle
// r,g und b sollten sich ca. zwischen 0,5 und 1,5
// bewegen. Sieht der Sensor rot, dann sollte r deutlich über 1.0
// liegen, g und b zwischen 0.5 und 1.0 usw.
Serial.print("\tClear:"); Serial.print(clearcol);
Serial.print("\tRed:"); Serial.print(r);
Serial.print("\tGreen:"); Serial.print(g);
Serial.print("\tBlue:"); Serial.print(b);
if ((r > 1.4) && (g < 0.9) && (b < 0.9)) {
Serial.print("\tROT");
myservo.write(redPos);
}
else if ((r < 0.95) && (g > 1.4) && (b < 0.9)) {
Serial.print("\tGRUEN");
myservo.write(greenPos);
}
else if ((r < 0.8) && (g < 1.2) && (b > 1.2)) {
Serial.print("\tBLAU");
myservo.write(bluePos);
}
else if ((r > 1.15) && (g > 1.15) && (b < 0.7)) {
Serial.print("\tGELB");
myservo.write(yellowPos);
}
else if ((r > 1.4) && (g < 1.0) && (b < 0.7)) {
Serial.print("\tORANGE");
myservo.write(orangePos);
}
else {
Serial.print("\tNICHT ERKANNT");
myservo.write(nonePos);
}
Serial.println("");
delay(100);