Atlas Scientific env RGB sensor

Hello,
I am a new comer to this forum. I am now trying to code the Atlas Scientific evn RGB sensor on Arduino Uno. The problem is when i print the data on the Serial motonitor, all the data are 0. I am so confused and i really need some help.

Here is my code up to now

(CODE TAGS PLEASE)

#include <SoftwareSerial.h> 

int RX = 2;
int TX = 3;
SoftwareSerial mySerial(RX,TX);




String first = ""; 
String second = "";
String third = "";
String forth = "";
String fifth = "";
String sixth = "";
String seventh = "";
String eighth = "";

String excess = "";
String input_string = ""; 
boolean input_stringcomplete = false; 
boolean sensor_stringcomplete = false; 
int commacount = 0;
byte  byteRead;

void setup(){ 
  
Serial.begin(38400); 
mySerial.begin(38400);
mySerial.print('C');

excess.reserve(100);
input_string.reserve(20); 
first.reserve(20);
second.reserve(20);
third.reserve(20);
forth.reserve(20);
fifth.reserve(20);
sixth.reserve(20);
seventh.reserve(20);
eighth.reserve(20);
}

void serialEvent() { 
char inchar = (char)Serial.read(); 
input_string += inchar; 
if(inchar == 13) {input_stringcomplete = true;} 
if (inchar == 44)
{
 commacount++;
} 
if (commacount == 0)
{
 if (inchar == 44)
 {
   excess += inchar;
 }
 else
 {
   first += inchar;
 }
}

else if (commacount == 1)
{
 if (inchar == 44)
 {
   excess += inchar;
 }
 else
 {
   second += inchar;
 }
}
else if (commacount == 2)
{
 if (inchar == 44)
 {
   excess += inchar;
 }
 else
 {
   third += inchar;
 }
}
else if (commacount == 3)
{
 if (inchar == 44)
 {
   excess += inchar;
 }
 else
 {
   forth += inchar;
 }
}
else if (commacount == 4)
{
 if (inchar == 44)
 {
   excess += inchar;
 }
 else
 {
   fifth += inchar;
 }
}
else if (commacount == 5)
{
 if (inchar == 44)
 {
   excess += inchar;
 }
 else
 {
   sixth += inchar;
 }
}
else if (commacount == 6)
{
 if (inchar == 44)
 {
   excess += inchar;
 }
 else
 {
   seventh += inchar;
 }
}
else if (commacount == 7)
{
 if (inchar == 44)
 {
   excess += inchar;
 }
 else
 {
   eighth += inchar;
 }
}
if(inchar == 13) {sensor_stringcomplete = true;} 
}

void loop(){ 
 

if (input_stringcomplete){ 
Serial.print(input_string); 
input_string = ""; 
input_stringcomplete = false; 
}

if (sensor_stringcomplete)
{
  int firstint = first.toInt();

  int secondint = second.toInt();

  int thirdint = third.toInt();

  int forthint = forth.toInt();

  int fifthint = fifth.toInt();

  int sixthint = sixth.toInt();

  int seventhint = seventh.toInt();

  int eighthint = eighth.toInt();
 
  Serial.println(firstint);
  Serial.println(secondint); 
  Serial.println(thirdint); 
  Serial.println(forthint); 
  Serial.println(fifthint);
  Serial.println(sixthint);
  Serial.println(seventhint);
  Serial.println(eighthint);
  
  first = "";
  second= "";
  third= "";
  forth= "";
  fifth= "";
  sixth= "";
  seventh= "";
  eighth= "";
  
  excess="";
  commacount=0;
  
  sensor_stringcomplete = false; 
}
}

Sounds like your strings are not getting filled properly. Try printing the strings as well as the integers:

  Serial.print(F("Strings: \""));
  Serial.print(first);
  Serial.print(F("\", \""));
  Serial.print(second); 
  Serial.print(F("\", \""));
  Serial.print(third); 
  Serial.print(F("\", \""));
  Serial.print(forth); 
  Serial.print(F("\", \""));
  Serial.print(fifth);
  Serial.print(F("\", \""));
  Serial.print(sixth);
  Serial.print(F("\", \""));
  Serial.print(seventh);
  Serial.print(F("\", \""));
  Serial.print(eighth);
  Serial.println(F("\""));

  Serual.print(F("Integers: "));
  Serial.print(firstint);
  Serial.print(F(", "));
  Serial.print(secondint); 
  Serial.print(F(", "));
  Serial.print(thirdint);
  Serial.print(F(", ")); 
  Serial.print(forthint); 
  Serial.print(F(", "));
  Serial.print(fifthint);
  Serial.print(F(", "));
  Serial.print(sixthint);
  Serial.print(F(", "));
  Serial.print(seventhint);
  Serial.print(F(", "));
  Serial.println(eighthint);

If the strings don't look right there must be a mistake in your code.

Thank you very much for your consideration. I tried your code but it seem like the same problem.

Here what i get in the Serial Mornitor:

Strings: "
", "", "", "", "", "", "", ""
Integers: 0, 0, 0, 0, 0, 0, 0, 0

I'm not sure is it because of the code or the wiring or the sensor? Do you know how to check whether the sensor is good or not?

Oh i disconnect the sensor with the power supply (the 5V pin) and it works really well. I' so confused now :slight_smile:

How do you mean "works really well"?
Is it giving you the figures you were expecting.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

Can you please post a picture of your project.

Tom...... :slight_smile:

This is how i actually plug the sensor in the Arduino Borad and the data i get. It can read RGB quite sensitively. However, i still can not make it read the lx ( say i only get first 3 values for Red Green Blue, the other is 0)

By the way, when i upload the code, i have to connect the green wire to pin 2 and white wire to pin 3, but after uploading, i have to reconnect the 2 wires to pin 0(RX) and pin 1(TX) so that it can show the data.

Here is how i wired up ( i do not have to plug the red wire in)

Here is the wiring