Pages: [1]   Go Down
Author Topic: RGB LED issues HELP  (Read 4267 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey I have my system all setup and it half works, except my RGB LEDs are not working correctly. they are all wired in correctly, but the LEDs ONLY light up when wired in wrong? i.e when the ground is collected to one of the RGB cathodes. It should be RG(Grnd)B.

Anyone see a fault in my coding or know what this problem may be? Apologies if my code looks like a complete hack job, its because it is!







#include <dht11.h>

//
//   FILE:  dht11_test1.pde
// PURPOSE: DHT11 library test sketch for Arduino
//

//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
   return 1.8 * celsius + 32;
}

// fast integer version with rounding
//int Celcius2Fahrenheit(int celcius)
//{
//  return (celsius * 18 + 5)/10 + 32;
//}


//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
   return celsius + 273.15;
}

// dewPoint function NOAA
// reference: http://wahiduddin.net/calc/density_algorithms.htm
double dewPoint(double celsius, double humidity)
{
   double RATIO = 373.15 / (273.15 + celsius);  // RATIO was originally named A0, possibly confusing in Arduino context
   double SUM = -7.90298 * (RATIO - 1);
   SUM += 5.02808 * log10(RATIO);
   SUM += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ;
   SUM += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
   SUM += log10(1013.246);
   double VP = pow(10, SUM - 3) * humidity;
   double T = log(VP/0.61078);   // temp var
   return (241.88 * T) / (17.558 - T);
}

// delta max = 0.6544 wrt dewPoint()
// 5x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
   double a = 17.271;
   double b = 237.7;
   double temp = (a * celsius) / (b + celsius) + log(humidity/100);
   double Td = (b * temp) / (a - temp);
   return Td;
}

int redpin = 11;
int greenpin = 10;
int bluepin = 9;

int redpin2 = 3;
int greenpin2 = 5;
int bluepin2 = 6;

int temperature;

#include <dht11.h>

dht11 DHT11;

#define DHT11PIN A0

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();
  pinMode(redpin, OUTPUT);
  pinMode(greenpin, OUTPUT);
  pinMode(bluepin, OUTPUT);
 
  pinMode(redpin2, OUTPUT);
  pinMode(greenpin2, OUTPUT);
  pinMode(bluepin2, OUTPUT);
}

void loop()
{
 
  temperature = (float)DHT11.temperature, 2;
 
  if(temperature>=19){
    analogWrite(redpin, 255);
    analogWrite(greenpin, 255);
    analogWrite(bluepin, 255);
        analogWrite(redpin2, 255);
    analogWrite(greenpin2, 255);
     analogWrite(bluepin2, 255);
       
  }
  if(temperature>=20){
    analogWrite(redpin, 255);
    analogWrite(greenpin, 255);
    analogWrite(bluepin, 255);
        analogWrite(redpin2, 255);
    analogWrite(greenpin2, 255);
     analogWrite(bluepin2, 255);
  }
 
  if(temperature>=21){
    analogWrite(redpin, 255);
    analogWrite(greenpin, 255);
    analogWrite(bluepin, 225);
        analogWrite(redpin2, 255);
    analogWrite(greenpin2, 255);
     analogWrite(bluepin2, 255);
  } 
     if(temperature>=22){
    analogWrite(redpin, 255);
    analogWrite(greenpin, 255);
    analogWrite(bluepin, 255);
        analogWrite(redpin2, 255);
    analogWrite(greenpin2, 255);
     analogWrite(bluepin2, 255);
}
  if(temperature>=23){
    analogWrite(redpin, 255);
    analogWrite(greenpin, 255);
    analogWrite(bluepin, 255);
        analogWrite(redpin2, 255);
    analogWrite(greenpin2, 255);
     analogWrite(bluepin2, 255);
}
 
  if(temperature>=24){
    analogWrite(redpin, 112.5);
    analogWrite(greenpin, 255);
    analogWrite(bluepin, 112.5);
        analogWrite(redpin2, 112.5);
    analogWrite(greenpin2, 255);
     analogWrite(bluepin2, 112.5);
}
 
if(temperature>=25){
    analogWrite(redpin, 0);
    analogWrite(greenpin, 255);
    analogWrite(bluepin, 255);
        analogWrite(redpin2, 0);
    analogWrite(greenpin2, 255);
     analogWrite(bluepin2, 255);
  } 
 
 
  Serial.println("\n");

  int chk = DHT11.read(DHT11PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case DHTLIB_OK:
      Serial.println("OK");
      break;
    case DHTLIB_ERROR_CHECKSUM:
      Serial.println("Checksum error");
      break;
    case DHTLIB_ERROR_TIMEOUT:
      Serial.println("Time out error");
      break;
    default:
      Serial.println("Unknown error");
      break;
  }

  Serial.print("Temperature (oC): ");
  Serial.println((float)DHT11.temperature, 2);
 

  delay(500);
}
Logged

Colorado
Offline Offline
Edison Member
*
Karma: 47
Posts: 1562
Reviving dead brain cells with Arduinos.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey I have my system all setup and it half works, except my RGB LEDs are not working correctly. they are all wired in correctly, but the LEDs ONLY light up when wired in wrong? i.e when the ground is collected to one of the RGB cathodes.
Quote

How do you know they are wired in correctly?
How do you expect us to know that they are wired in correctly?

It should be RG(Grnd)B.

That statement right there tells me that you yourself don't know if that is the correct pin layout or not.  If you don't, who does?  Datasheet?  Picture?  Wiring diagram?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That wasn't really helpful Kirash. What do you want me to show? I study design so wouldnt know where to begin drawing you a circuit diagram.
Logged

Offline Offline
Edison Member
*
Karma: 56
Posts: 2185
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There are Common Anode RGBs and Common Cathode RGBs.
Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12465
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I recognize my example code, good to see it used  smiley-wink

Quote
temperature = (float)DHT11.temperature, 2;

This is valid C but it does not do what you expect.

- temperature is an int so a cast to float is ignored by the compiler.
- the ,2 seems to be copied from the print function. There it is used to print 2 decimals when the first param is float.
- the DHT11 only give integer values so 2 decimals or casting to float makes no sense.

Furthermore you read the temperature variable before the sensor is read.

You should write a function to display the colour and put the temp checking in a switch,

I modified the sketch to reflect this, (code not tested BTW)
Code:
int redpin = 11;
int greenpin = 10;
int bluepin = 9;

int redpin2 = 3;
int greenpin2 = 5;
int bluepin2 = 6;

int temperature;

#include <dht11.h>

dht11 DHT11;

#define DHT11PIN A0

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();
  pinMode(redpin, OUTPUT);
  pinMode(greenpin, OUTPUT);
  pinMode(bluepin, OUTPUT);
 
  pinMode(redpin2, OUTPUT);
  pinMode(greenpin2, OUTPUT);
  pinMode(bluepin2, OUTPUT);
}

void loop()
{
  int chk = DHT11.read(DHT11PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case DHTLIB_OK:
      Serial.println("OK");
      break;
    case DHTLIB_ERROR_CHECKSUM:
      Serial.println("Checksum error");
      break;
    case DHTLIB_ERROR_TIMEOUT:
      Serial.println("Time out error");
      break;
    default:
      Serial.println("Unknown error");
      break;
  }

  Serial.print("Temperature (oC): ");
  Serial.println( (float)DHT11.temperature, 2);
 
  temperature = DHT11.temperature;
 
  switch(temperature)
  {
  case(19): showRGB(255, 255, 255, 255, 255, 255); break;  //<<<<<<<<<<<<<<< ADJUST NUMBERS IN THESE FUNCTION CALLS TO YOUR SPECIFICATION
  case(20): showRGB(200, 200, 255, 200, 200, 255); break;
  case(21): showRGB(255, 150, 150, 255, 150, 150); break;
  case(22): showRGB(100, 255, 100, 100, 255, 100); break;
  case(23): showRGB(255, 50, 50, 255, 50, 50); break;
  case(24): showRGB(0, 255, 255, 0, 255, 255); break;
  case(25): showRGB(255, 0, 255, 255, 0, 255); break;
  default: showRGB(0, 0, 0, 0, 0, 0); break;
  }
  delay(2000); // there should be 2 seconds between reads ==> see sensor specifications.
}

void showRGB(int R1, int G1, int B1, int R2, int G2, int B2)
{
  analogWrite(redpin, R1);
  analogWrite(greenpin, G1);
  analogWrite(bluepin, B1);
  analogWrite(redpin2, R2);
  analogWrite(greenpin2, G2);
  analogWrite(bluepin2, B2);
}

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: