Show Posts
Pages: [1] 2 3 ... 21
1  Using Arduino / Programming Questions / Re: AC dimmer code issus on: September 21, 2014, 12:34:39 pm
Yes I get what you are saying but on the other hand It does work when I'm not using a pot
2  Using Arduino / Programming Questions / Re: AC dimmer code issus on: September 21, 2014, 10:26:52 am
Thanks for your reply I've tired that and it's still acting erratically any other ideas to over come this?
I
Thanks Joe
3  Using Arduino / Programming Questions / AC dimmer code issus on: September 21, 2014, 08:19:13 am
Hi there

I've found this code on the internet which dims AC output down which works fine. ( This is the code below)

Code:
int AC_LOAD = 5;    // Output to Opto Triac pin
int dimming = 128;  // Dimming level (0-128)  0 = ON, 128 = OFF
/* Due to timing problems, the use of ‘0’ can sometimes make the circuit
flicker. It is safer to use a value slightly higher than ‘0’
*/
void setup()
{
  pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
  attachInterrupt(0, zero_crosss_int, RISING); 
// Chooses '0' as interrupt for the zero-crossing
}
// the interrupt function must take no parameters and return nothing
void zero_crosss_int() 
// function to be fired at the zero crossing to dim the light
{
  // Firing angle calculation : 1 full 50Hz wave =1/50=20ms 
  // Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle) For 60Hz => 8.33ms

  // 10ms=10000us
  // (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65
  int dimtime = (75*dimming);    // For 60Hz =>65     
  delayMicroseconds(dimtime);    // Off cycle
  digitalWrite(AC_LOAD, HIGH);   // triac firing
  delayMicroseconds(10);         // triac On propogation delay
                                 //(for 60Hz use 8.33)
  digitalWrite(AC_LOAD, LOW);    // triac Off
}
void loop()  {
 for (int i=5; i <= 128; i++)
{
 dimming=i;
 delay(10);
 }
 }


What I'm trying to do is to control the AC output using a pot, I have tried doing this on the code below but the bulb seems to flash erratically what have I done wrong ?

Code:
int POT_pin = A3;             // Pot for testing the dimming
int AC_LOAD = 5;    // Output to Opto Triac pin
int dimming = 128;  // Dimming level (0-128)  0 = ON, 128 = OFF
int val =0;
/* Due to timing problems, the use of ‘0’ can sometimes make the circuit
flicker. It is safer to use a value slightly higher than ‘0’
*/
void setup()
{
  pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
  attachInterrupt(0, zero_crosss_int, RISING); 
// Chooses '0' as interrupt for the zero-crossing
}
// the interrupt function must take no parameters and return nothing
void zero_crosss_int() 
// function to be fired at the zero crossing to dim the light
{
  // Firing angle calculation : 1 full 50Hz wave =1/50=20ms 
  // Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle) For 60Hz => 8.33ms

  // 10ms=10000us
  // (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65
  int dimtime = (75*dimming);    // For 60Hz =>65     
  delayMicroseconds(dimtime);    // Off cycle
  digitalWrite(AC_LOAD, HIGH);   // triac firing
  delayMicroseconds(10);         // triac On propogation delay
                                 //(for 60Hz use 8.33)
  digitalWrite(AC_LOAD, LOW);    // triac Off
}
void loop()  {

        val = analogRead(POT_pin) ;        // pont input
        dimming = map(val, 0, 1023, 0, 128);
 }


thanks Joe
4  Using Arduino / Programming Questions / Re: watchdog timer with a ATtiny 84 on: September 21, 2014, 08:10:43 am
The only reason I ask I have this code on one of my ATtiny84 and it still freezes from time to time?
5  Using Arduino / Programming Questions / watchdog timer with a ATtiny 84 on: September 08, 2014, 12:37:04 pm
hi there will this watchdog  time code work on my ATtiny84?

Code:

#include <avr/io.h>
#include <avr/wdt.h>

void setup()
{
MCUSR=0;
wdt_enable (WDTO_8S);
}

void loop () {

// do some stuff here

wdt_reset();
}
6  Using Arduino / Programming Questions / Re: digitalRead question on: August 13, 2014, 03:54:53 pm
yes sorry it is  ||
any other ideas?   
7  Using Arduino / Programming Questions / digitalRead question on: August 13, 2014, 03:31:26 pm
hi there I have this code what works fine

Code:
if ((FalSafeValue < 359 && (failFlag == false)) {

but I would like to add  a diditalRead in this.I have had a go in the code below but now that piece of the code doesn't seem to work at all now.

Code:
if ((FalSafeValue < 359) ll !digitalRead(tempFalSafe) && (failFlag == false)) {

what have I done  wrong?
8  Using Arduino / General Electronics / Re: battery mAh tester on: August 03, 2014, 03:55:55 am
Make i am testing with is ultra max np7-12, 12volt, 7Ah, gel sell lead acid
I have to of them linked in series to give me a 24v output
9  Using Arduino / General Electronics / Re: battery mAh tester on: August 03, 2014, 03:06:15 am
Yes I did mean 7am
So the general concessive is to switch off the wains to it check the voltage and then put it under a load and see how far the voltage drops?

On the other hand you can buy a battery testers which can test the Am within about 20s or so, so how do these things work?
Or are they not particularly accurate? But hope not as some of them are over £200
10  Using Arduino / General Electronics / battery mAh tester on: July 31, 2014, 03:55:00 pm
hi there, I have a project  which uses two 7 mAh batteries for mains failure. These are being constantly charged. What I would like to do is some sort of battery test on them on a push of a button. I thought the best way to test them is a mAh test? But I have seen others that have done this but they take a fully charged battery and discharge it all the way down but I don't have the time to do that or take the risk of having a flat battery at the end of it. Is there another way I can do this?

any help will be appreciated
thanks Joe
11  Using Arduino / General Electronics / voltage regulators on: July 27, 2014, 09:12:46 am
hi there I am using a TA7805F voltage regulators what works but gets very hot jue to high input voltage (28v), could any one recommend anything beater for the job?

thanks Joe
12  Using Arduino / Programming Questions / analong delay? on: July 27, 2014, 09:04:08 am
hi there
I have this bit of code below what woks fine, but what I would like it to do is when the stamen is true for a set period of time before executing the code, say for 4s?

Code:
int FalSafeValue = analogRead(FalSafeInput);
if (FalSafeValue < 100) {
FalSAFE():
}

any help with be appreciated
thanks Joe
13  Using Arduino / General Electronics / Re: attiny84 freezing on: June 13, 2014, 12:37:02 pm
hi there thanks for all your feedback
yes I would agree it is the 3 phase what is playing me up, still having issues so I am all out of ideas?

I have look into the watchdog timer but just seem to reset like every 10s so I don't no if I have dun something wrong?

Code:
//         ***  INPUT'S  ***
const int HeatIn1   =  7;    // input from PC 1
const int HeatIn2   =  8;    // input from PC 2
const int overload1 =  9;    // overload cut out 1
const int overload2 = 10;    // overload cut out 2
const int reverse   =  6;   // reverse swich for heat's

//          *** OUTPUT'S  ***
const int valve     =  11;    // valve in pooler room       // not being used
const int LED       =  5;    // lock out led
const int pump      =  4;    //  pump in pooler room
const int heater1   =  3;    // heater 1 output forwch
const int heater1R  =  2;    // heater 1 output revus
const int heater2   =  1;    // heater 2 output forwch
const int heater2R  =  0;    // heater 2 output revus


#include <avr/wdt.h>

unsigned long resetTime = 0;
#define TIMEOUTPERIOD 10000             // You can make this time as long as you want,
                                       // it's not limited to 8 seconds like the normal
                                       // watchdog
#define doggieTickle() resetTime = millis();  // This macro will reset the timer
void(* resetFunc) (void) = 0; //declare reset function @ address 0

void watchdogSetup()
{
cli();  // disable all interrupts
wdt_reset(); // reset the WDT timer
MCUSR &= ~(1<<WDRF);  // because the data sheet said to
/*
WDTCSR configuration:
WDIE = 1 :Interrupt Enable
WDE = 1  :Reset Enable - I won't be using this on the 2560
WDP3 = 0 :For 1000ms Time-out
WDP2 = 1 :bit pattern is
WDP1 = 1 :0110  change this for a different
WDP0 = 0 :timeout period.
*/
// Enter Watchdog Configuration mode:
WDTCSR = (1<<WDCE) | (1<<WDE);
// Set Watchdog settings: interrupte enable, 0110 for timer
WDTCSR = (1<<WDIE) | (0<<WDP3) | (1<<WDP2) | (1<<WDP1) | (0<<WDP0);
sei();
}


ISR(WDT_vect) // Watchdog timer interrupt.
{
  if(millis() - resetTime > TIMEOUTPERIOD){
  doggieTickle();                                          // take these lines out
  resetFunc();     // This will call location zero and cause a reboot.
  }
}


void setup()
{
  watchdogSetup();
  //        ***  OUTPUT'S  ***
  pinMode(valve   ,    OUTPUT);
  pinMode(LED     ,    OUTPUT);
  pinMode(pump    ,    OUTPUT);
  pinMode(heater1 ,    OUTPUT);
  pinMode(heater1R,    OUTPUT);
  pinMode(heater2 ,    OUTPUT);
  pinMode(heater2R,    OUTPUT);


  //        ***  INPUT'S  ***
  pinMode(HeatIn1,     INPUT);
  pinMode(HeatIn2,     INPUT);
  pinMode(reverse,     INPUT);
  pinMode(overload1,   INPUT);
  pinMode(overload2,   INPUT);

}

int firstTime = true;

enum LoopOneStates {
  Heating, NotHeating, ReverseMode, ReverseModeOn,  ReverseModeOff, WaitingToHeat};

enum LoopTwoStates {
  EitherHot, OpenValve, StartPump, NeitherHot,  CloseValveStopPump};

void loop() {
    if (firstTime){
    firstTime = false;
  }
  if(millis() - resetTime > 2000){
    doggieTickle();  // if you uncomment this line, it will keep resetting the timer.
  }
 
 
  unsigned long currentTime = millis();
 
  //  LoopOne for Heater 1
if (digitalRead(overload1)) {
  static enum LoopOneStates state1 = Heating;
  static unsigned long state1EntryTime = 0;
  switch (state1) {
  case Heating:
    digitalWrite(heater1, HIGH);
    if (!digitalRead(HeatIn1))
      state1 = NotHeating;
    break;

  case NotHeating:
    digitalWrite(heater1, LOW);
    if (digitalRead(reverse)) {
      state1 = ReverseMode;
      state1EntryTime = currentTime;
    }
    if (digitalRead(HeatIn1))
      state1 = Heating;
    break;

  case ReverseMode:
    if (currentTime - state1EntryTime > 30000) {
      digitalWrite(heater1R, HIGH);
      state1 = ReverseModeOn;
      state1EntryTime = currentTime;
    }
    break;

  case ReverseModeOn:
    if (currentTime - state1EntryTime > 10000) {
      digitalWrite(heater1R, LOW);
      state1 = ReverseModeOff;
      state1EntryTime = currentTime;
    }
    break;

  case ReverseModeOff:
    if (currentTime - state1EntryTime > 30000) {
      state1 = WaitingToHeat;
    }
    break;

  case WaitingToHeat:
    if (digitalRead(HeatIn1)) {
      state1 = Heating;
    }
    break;
  }
}
else {
  digitalWrite(heater1,  LOW);
  digitalWrite(heater1R, LOW);
}


  //  LoopOne for Heater 2
  if (digitalRead(overload2)) {
  static enum LoopOneStates state2 = Heating;
  static unsigned long state2EntryTime = 0;
  switch (state2) {
  case Heating:
    digitalWrite(heater2, HIGH);
    if (!digitalRead(HeatIn2))
      state2 = NotHeating;
    break;

  case NotHeating:
    digitalWrite(heater2, LOW);
    if (digitalRead(reverse)) {
      state2 = ReverseMode;
      state2EntryTime = currentTime;
    }
    if (digitalRead(HeatIn2))
      state2 = Heating;
    break;

  case ReverseMode:
    if (currentTime - state2EntryTime > 30000) {
      digitalWrite(heater2R, HIGH);
      state2 = ReverseModeOn;
      state2EntryTime = currentTime;
    }
    break;

  case ReverseModeOn:
    if (currentTime - state2EntryTime > 10000) {
      digitalWrite(heater2R, LOW);
      state2 = ReverseModeOff;
      state2EntryTime = currentTime;
    }
    break;

  case ReverseModeOff:
    if (currentTime - state2EntryTime > 30000) {
      state2 = WaitingToHeat;
    }
    break;

  case WaitingToHeat:
    if (digitalRead(HeatIn2)) {
      state2 = Heating;
    }
    break;

  }
  }
else {
  digitalWrite(heater2,  LOW);
  digitalWrite(heater2R, LOW);
}

  //                                                        **loop two**
  //  LoopOne for Heater 1
  static enum LoopTwoStates state3 = EitherHot;
  static unsigned long state3EntryTime = 0;
  switch (state3) {
  case EitherHot:
    if (digitalRead(HeatIn1) || digitalRead(HeatIn2)) {
      state3 = OpenValve;
      state3EntryTime = currentTime;
    }
    break;

  case OpenValve:
    digitalWrite(valve, HIGH);
    // Fifteen seconds later, starty the pump
    if (currentTime - state3EntryTime > 5000) {
      state3 = StartPump;
      state3EntryTime = currentTime;
    }
    break;

  case StartPump:
    digitalWrite(pump, HIGH);
    state3 = NeitherHot;
    state3EntryTime = currentTime;
    break;

  case NeitherHot:
    // Wait for a full 30 minutes with neither heat indicators on
    if (digitalRead(HeatIn1) || digitalRead(HeatIn2)) {
      // Reset the timer if either heater is on
      state3EntryTime = currentTime;
    }
    if (currentTime - state3EntryTime > 1000UL*60UL*30UL) {
      state3 = CloseValveStopPump;
    }
    break;

  case CloseValveStopPump:
    digitalWrite(valve,       LOW);
    digitalWrite(pump,        LOW);
    state3 = EitherHot;
    break;
  }
  //     Lock out LED
  if (!digitalRead(overload1) || !digitalRead(overload2)) {
     digitalWrite(LED,     HIGH);
  }
     else {
     digitalWrite(LED,     LOW);   
  }
}

14  Using Arduino / Programming Questions / digital read on stat up questions on: June 05, 2014, 03:44:56 pm
Hi there
What I am trying to do is when the arduino starts up I want it to look at a state of a digital pin and choose to do one piece of code or another depending on the state of the input pin being high or low. So in other words in set up to choose to do one loop or another.
But I don't want it to continuously look at the input pin just on start up.

I hope that makes sense, any help would be appreciated.

thanks Joe
15  Using Arduino / General Electronics / Re: regulating 45v to 35v on: April 03, 2014, 02:55:04 pm
 literally 45 to 35V

the 45v is being used for something else so going to pick of that. need to drop it down for a battery charging circuit
Pages: [1] 2 3 ... 21