Go Down

Topic: Ir transmitter to send hex signals at certain times (Read 104 times) previous topic - next topic

Rodg98133

Hey all, new to the forum and arduino in general.

I have come a cross arduino as a solution for what I want to achieve. I have had a play with a board I have and done a few basic sketches to have a play.

Basically what I want to achieve...

I have a fish tank with a light that has 4 different channels of leds, each channel has 10 different degrees of brightness. The light is controlled by an ir remote.

I want to create a unit that will automatically brighten the leds gradually over say half and hour in the morning and then dim them gradually in the evening.

I have made an ir receiver and have the hex codes that are transmitted when each button is pressed now I want to know how to transmit a certain hex at a certain time.

Hardware I already have is a general 'starter kit'

I have also ordered some ir led, some 430ohms resistors and a real time clock.

Anything else I will need and any ideas on how to create a code that will do what I want it to do?

Thanks in advance

DrDiettrich

You have to track two events:
- what to do next
- when to do it
For the "what" a state machine may be a good solution. Then determine the interval after which the next step shall be taken, and wait for that time - see BlinkWithoutDelay.

For the IR part you need the IRremote library, I think that you found it already.

Blackfin

You can try using a pseudocode framework like this as a rough starting point:

Code: [Select]

#include <RTC library>
#include <IR library>

//brightness statemachine state names
#define WAIT_SUNRISE    0
#define SUNRISE         1
#define WAIT_SUNSET     2
#define SUNSET          3

#define SUNRISE_HRS     6       //06:45:00 is sunrise example
#define SUNRISE_MINS    45
//
#define SUNSET_HRS      20      //20:45:00 is sunset example (RTC is reporting in 24hrs mode)
#define SUNSET_MINS     45

#define MAX_BRIGHTNESS  9       //0-9 is 10 steps

const unsigned long BrightnessTable[] =
{
    10 IR codes for increasing brightness from off (index 0) to max (index 9)
}

//read the time into something like this
typedef struct
{
    byte    hours;
    byte    minutes;
    byte    seconds
   
}struct_timenow;

struct_timenow timenow;

void setup()
{
    stateLED = setInitialStateFromRTC();
   
    other setups as needed
   
}

byte setInitialStateFromRTC( void )
{
    readRTC( &timenow );
    retval = one of WAIT_SUNRISE or WAIT_SUNSET value based on RTC time
    assign initial brightness to match retval
    return retval
   
}

void loop()
{
    //just run the statemachine
    //could also use alarms/wakeup from RTC to trigger sunrise/sunset code if you want to save energy
    DoLEDStateMachine();
}

void DoLEDStateMachine( void )
{
    static uint8_t
        lastseconds = 255; //initial value will be different from every second value so 1st time through will work
       
    readRTC( &timenow );

    //run statemachine each time a second changes
    if( timenow.seconds != lastseconds )
    {
        lastseconds = timenow.seconds;
        switch( stateLED )
        {
            case    WAIT_SUNRISE:
                if( timenow.hours == SUNRISE_HRS && timenow.minutes == SUNRISE_MINS && timenow.seconds == 0 )
                {
                    //when time to start sunrise, initialize brightness to zero                   
                    brightness = 0;
                    //10 steps in 30mins is 3 minutes (180 seconds) per step
                    steps = 180;
                    //next state is sunrise
                    stateLED = SUNRISE;   
                   
                }//if
               
            break;

            case    SUNRISE:
                //if max brightness has been reached, move to state waiting for sunset time
                if( brightness == MAX_BRIGHTNESS )
                    stateLED = WAIT_SUNSET;
                else
                {
                    //when 180 steps/seconds are done...
                    steps--;
                    if( steps == 0 )
                    {
                        //...increase brightness index
                        brightness++;
                        //and send new value
                        sendIRBrightness( BrightnessTable[brightness] );
                        //reset seconds counter for next brightness increase step
                        steps = 180;
                       
                    }//if
                   
                }//else
               
            break;

            case    WAIT_SUNSET:
                //waiting for RTC to indicate sunset
                if( timenow.hours == SUNSET_HRS && timenow.minutes == SUNSET_MINS && timenow.seconds == 0  )
                {
                    //going from max brightness down to min...
                    brightness = MAX_BRIGHTNESS;
                    //in same 3-min intervals
                    steps = 180;
                    //move to sunset
                    stateLED = SUNSET;   
                   
                }//if
               
            break;

            case    SUNSET:
                //if sun has set, move to wait for sunrise time
                if( brightness == 0 )
                    stateLED = WAIT_SUNRISE;
                else
                {
                    //decrease steps count...
                    steps--;
                    //...if zero...
                    if( steps == 0 )
                    {
                        //decrease brightness index and send it...
                        brightness--;
                        sendIRBrightness( BrightnessTable[brightness] );
                        //...and setup for next adjustment in 3 minutes
                        steps = 180;
                       
                    }//if
                   
                }//else
               
            break;
           
        }//switch
       
    }//if
   
}//DoLEDStateMachine

Go Up