Page 1 of 2

Power controller

PostPosted: July 6th, 2014, 12:07 pm
by dsolodov
Got hardware and software working :D for a power controller based upon ATtiny85. The controller features:
  • hardware debounce for the push button;
  • support for alternating polarity dual color LEDs;
  • an optocoupler based interface to an external 5-30VDC trigger to integrate to a receiver based or similar trigger;
  • low side power switch to turn on/off an external device such as a relay.
    The MOSFET switch supports up to 15A and was tested with 2A load.;
  • an analog port to interface with an analog temperature sensor or other sensor;
  • timer based turn-off;
    The thinking is to turn off the audio device after ~3 hours to preserve the caps in case the owner has left and forgot to turn off.
  • interrupt driven code with ATTiny in power down mode most of the time.
    The board's power consumptions measures 0.35mA with LED off and 6mA with LED on
  • the PCB is 60x45mm;
  • a separate switching PSU with matching board size for stacking and ~68% PSU efficiency.

The code compiles to ~1600 bytes, so plenty of space for extra code is available in both Attiny45/85 and ATmega328.

Schematic v.0.02ss.jpg

Pctrl v0.06.JPG

Edit 8/21/14: Removed pictures of the prototype and added 3D preview.
Edit 1/13/15: Updated boards' dimentions.

Re: Power controller

PostPosted: July 6th, 2014, 3:06 pm
by cobretti
Well, I would probably never find a use for it, at least for now. But, if you have a free pin on the micro available, would it be possible to wire a few DIP switches through resistor network to select different times? Just a thought. 8-)

Power controller

PostPosted: January 13th, 2015, 7:06 pm
by dsolodov
A DIP switch is a nice idea for higher volume. A DIP switch could be read directly as high-low and use I/O pins on the MCU. A DIP switch would need at least 2 pins, so ATtinyX4 would be required. The current board uses all pins except the pin 1 on ATtinyX5.

ATtinyX5 pins assignments on the controler are:
8 - VCC
7 - Analog temperature sensor
6 - Optocoupler for 12V input trigger
5 - Momentary button
4 - Gnd
3 - Control of MOSFET based switch for the external circuit up to 15A
2 - Control indicator LEDs (High/On and Low/Off states)
1 - Reset

Two options:
A. Update the constant in the code and update the MCU with the updated firmware.
B. The code uses MCU pin 7 through JP3 to read the voltage from the the precision LMT87 ( temperature sensor. The code switches to the off state, if the sensor reports the voltage corresponding to temperature above 55C, which is defined through a constant. The 55C temperature threshold corresponds to 1888mV or lower on the JP3 as per the datasheet for LMT87. So at long as the supplied voltage is below the threshold, the controller will switch to the off (low) state.

On the physical side, the SMD version of LMT87 is small. I unintentionally flooded the pins and then used he solder wick to remove extra solder on the sensor mounting boards. Through hole TO-92 version of the sensor is available as well.

The PSU for the board is switching RAC01-05SC for 68% efficiency. The board has its own fuse as Amb recommends ( . The holder is for Littelfuse TR5/TE5 fuses. These are neat. The fuse values go down to 0.05A! (

I calibrated my ATTiny85 chips using Fluke 287 and the available code ( The controller's code reads PSU voltage before taking a measurement from the sensor. Prior to calibration the temperature reading was >2.5C off. After calibration the reading is within 0.1C against the reading by Fluke 62. :)

Re: Power controller

PostPosted: January 14th, 2015, 1:36 pm
by cobretti
Looks good.

Re: Power controller

PostPosted: January 17th, 2015, 6:36 am
by cobretti
I would like to know more about LMT87 temp. protection. Does it have any Hysteresis? Does it auto reset or is it manual resettable from OFF back to ON state? Can I see the code please? I am guessing you programmed MCU in Arduino...?

Re: Power controller

PostPosted: January 17th, 2015, 2:08 pm
by dsolodov
The code is written with focus on a state machine for control of power to a relay for mains power. Pressing the push button or external 12V trigger going 'high' is an event that will turn on the relay. Pressing the push button, external 12V trigger going 'low', reading of a temperature above a threshold, and timeout are events that will turn off the relay.

Power Controller Diagrams.jpg

cobretti wrote:I would like to know more about LMT87 temp. protection. Does it have any Hysteresis?

The overall state machine at a high level is described above. If temperature is above a threshold value, the logic will turn off the device. The assumption, which is not always valid, is the initial temperature is below threshold. Ups.

cobretti wrote:Does it auto reset or is it manual resettable from OFF back to ON state?

Currently once the state is OFF (low) only pressing the button or optical trigger going high will result in ON( high) state. You got me thinking. Maybe after auto shutdown for any reason, only the button (i.e. user action) should be capable to trigger ON.

The code uses the temperature threshold to turn off only. The thinking was to have the feature as a protection from overheating assuming turning off the relay will result in lower temperatures.

cobretti wrote:Can I see the code please? I am guessing you programmed MCU in Arduino...?

Arduino IDE is used.

Code: Select all


AppData appData;
// Calibrated for the specific MCU
const float Vbandgap = 1.1 * 1000 * 5150.0 / 5209.0;
     uint8_t nextState = LOW
               ,triggerUpdate = 0;
     AppData::LastAction la = AppData::UNKNOWN_ACTION;
     AppData::LastAction storedLastAction = appData.getLastAction();
     if((storedLastAction == AppData::BUTTON_TURN_ON || storedLastAction == AppData::OPTO_TURN_ON)){
        float tempC = 0.0;
        if( appData.getTemperatureSensorPresenceFlag() == HIGH
            && appData.isTimeoutReached4TemperatureReading( TEMPERATURE_READING_INTERVAL)){
           VccReader vccReader(Vbandgap);
           long mVolts = vccReader.readVccMillivolts();
           LMT87 lmt87( sensorPort, mVolts); 
           tempC = lmt87.readTemperatureC();
           appData.setTemperatureReadTimestamp( appData.getWDTCounter());
        if( tempC >= MAX_TEMPERATURE_THRESHOLD){
           // Turn off the device
            nextState = LOW;
            triggerUpdate = 1;
            la = AppData::TEMPERATURE_TURN_OFF;
        else if( appData.isTimeoutReached( MAX_INACTIVITY_DURATION)){
           // Turn off the device
           nextState = LOW;
           la = AppData::WDT_TURN_OFF;
  if( triggerUpdate == 1){ 
     appData.setPowerStatus( nextState);
     appData.setLEDStatus( nextState);
     appData.setLastAction( la);
     digitalWrite( powerPort, nextState);
#ifdef USE_LED 
     digitalWrite( ledPort, nextState);

Re: Power controller

PostPosted: January 18th, 2015, 2:14 am
by Shaman
Nice! 8-)

Are there any I/O pins left to add an IR trigger?

Re: Power controller

PostPosted: January 18th, 2015, 12:58 pm
by cobretti
Could be added on pin6 after the opto-coupler through the diode or something like that my guess..... 8-)

Re: Power controller

PostPosted: January 23rd, 2015, 4:51 pm
by dsolodov
In the 'as is' configuration, there are not easily available free pins that can be used without quite a bit of effort.

IR may be used instead of the temperature sensor on the analog input header JP3 as it goes directly to the MCU. Software to handle an IR sensor is required as well.

LCDDuino supports IR control including learning and can be operated without the LCD, if I recall correctly.

Re: Power controller

PostPosted: February 11th, 2018, 11:42 am
by theenggprojects

If you are working on Arduino then you should have a look at Introduction to Atmega328. I have written this article and have tried my best to share all the details. I hope you guys will enojy it.