NodeMCU-ColorSensor-ThingSpeak
Color Sensor
Sensor Connection-
LHS pins are of the NodeMCU, and RHS pins are of the color sensor
NodeMCU pins—->color sensor pins
- D4—>S0
- D5—>S1
- D6—>S2
- D7—>S3
- GND—>OE
- D8—>OUT
- 3.3V—>VCC
- GND—>GND
Arduino code for sensor-
| 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 | const int s0 = D4; const int s1 = D5; const int s2 = D6; const int s3 = D7; const int out = D8; int red = 0; int green = 0; int blue = 0; void setup() { Serial.begin(9600); pinMode(s0, OUTPUT); pinMode(s1, OUTPUT); pinMode(s2, OUTPUT); pinMode(s3, OUTPUT); pinMode(out, INPUT); digitalWrite(s0, HIGH); digitalWrite(s1, HIGH); } void loop() { color(); Serial.print(“R Intensity:”); Serial.print(red, DEC); Serial.print(” G Intensity: “); Serial.print(green, DEC); Serial.print(” B Intensity : “); Serial.print(blue, DEC); if (red < blue && red < green && red < 20) { Serial.println(” – (Red Color)”); } else if (blue < red && blue < green) { Serial.println(” – (Blue Color)”); } else if (green < red && green < blue) { Serial.println(” – (Green Color)”); } else { Serial.println(); } delay(1000); } void color() { digitalWrite(s2, LOW); digitalWrite(s3, LOW); red = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH); digitalWrite(s3, HIGH); blue = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH); digitalWrite(s2, HIGH); green = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH); } |