22 August, 2016

Save energy with a timed plug: Do it yourself with Arduino

I used this to build a wireless plug socket countdown
I had a Wireless programmable plug Contros of Broadlink with the wifi card damaged:

and I realized that I could come in handy a plug to be activated for a certain time simply by pressing the button, with increments of the same time with each pulse (similar to working electronic microwave, that with each press of the button quick heated adds 30 seconds to the time). A picture is worth a thousand words (explained in spanish, sorry):

We could use this plug in many cases; I for example have a Philips coffee with fairly inaccessible button to be switched on and off whenever used so it is not always consuming to keep warm. In this case , we are activating the morning with a simple push of the button and we would have prepared for an hour. Another example is the plugs mata-mosquitos (liquid or pills) often forget fired, polluting the environment with poison without because if you look, all die half an hour and two hours, and it is no longer necessary unless we leave an open window. In this case we avoid poison in our body that ultimately may affect our nervous system (or may not, and the maximum exposure for which these devices are regulated are healthy, but healthy is to avoid it ), in addition to saving in the consumable.
A plug so (I do not know if they will be available for sale) is very simple to build with Arduino, and is more useful than one connection in some cases. The problem is that if we do it as compact as possible, we use a plate as small as possible ( more than the Nano ) . And in this case more than contros recycled box is not wide precisely:

In these compact and simple necessities it is where comes into play Attiny Digispark plates,small but powerful .

Until I have not noticed that the number of analog input pin does not correspond to the plate (for digital yes), I have gone mad wondering what is failing, because it proved an Arduino Uno and working properly but not to put the same code in the ATtiny85. the sooner you you you read and memoricéis differences , before you can take advantage of their qualities in a plate just 20x20mm:
  1. The Digispark works with an  Atmel ATtiny85 MCU - has some differences from the ATmega328 and some libraries do not work properly, but will improve over time.
  2. The Digispark only 6 KB of memory available for our code (8 KB if we remove the virtual USB bootloader and we programmed directly with an Arduino UNO ).
  3. Pin 3 and Pin 4 (P3 and P4) are used for communications and USB programming ;if only it interferes if we use the USB connection and can be used while not use the USB connection on the final design, but keep in mind that if the program acts dramatically on the voltage thereof, will be best to disconnect once we uploaded the program by USB.
  4. Pin 3 (P3) is connected to a pull-up resistor 1.5 KQ required when P3 and P4 are used for USB communication (programming included). Your design will have to take thatinto account and you'd have to supercharge the pin to put it in LOW.
  5. The Digispark does not have a serial port hardware or a converter to USB. A library of example (DigiUSB) as well as some sample code and a monitor program series, but communication with the computer will not always plug and play, especially when there are other libraries in use is provided.
  6. On power does nothing until 4 seconds later , as it is the waiting time that is scheduled for programming USB (this I think can be eliminated by programming directly , but I have not tried), so must be taken into account if we need quick start the program.
  7. While digital connections correspond to the pins (digitalRead (0) where 0 = Pin0), the correspondence of the analog pins change :
analogRead (1); // Read P2
analogRead (2); // Read P4
analogRead (3); // Read P3
analogRead (0); // Read P5

To program the Digispark

We need to install version 1.6.6 or above and follow the instructions of your page . It took me make it work on Windows 10, but do not despair because either restarting or reinstalling drivers and rebooting, is arranged. The procedure is different from the Arduino programming ; the Digispark not have to have it connected, but first we give to dump program from the IDE, and we indicated that we connect (when connected by USB is 4 seconds waiting for a connection for programming), Windows notifies you of the connection and disconnection USB and finally the IDE will warn us in the status window that has been programmed correctly.

We will need the following material

  • A programmer or plug apparatus Bypass to activate or deactivate the connected;I used a Broadlink contros spoiled.
  • A transformer 85 / 240V AC to 5V DC at least 300mA to feed the Digispark and relay.
  • A Digispark (or Arduino Nano if you have space).
  • A relay of at least 10A and activate it with digital 5V (powered).
  • Soldering iron, tin, scissors, tape, thin wires; the usual.
tried using a source of 9V with a voltage regulator L7805 but too heated and had no place to put sink; better to play an optimal source regulated 5V and efficient.

On the other hand I tried to take advantage of the relay that had the contros 16V, but overload the Arduino pin to activate it , due to its high consumption (had no separate power pins); you will see some photos of the preliminary designs with any of these changes, but always talk about the final design.

To take advantage contros must find out how the circuit of blue and white button and LED functions.

I am only interested regulate the intensity of the blue LED and LOW put on one of the digital pins with the switch; at the end I cut the track that linked the LED and the switch to + 5V as to put a pin LOW have to connect to GND (ground, earth). The good practice in a device that will be connected a long time is to define the input pins with pull-up resistor ( pinMode (botonPIN, INPUT); digitalWrite (botonPIN, HIGH);)  to avoid possible short circuits caused by error or fluctuations . for indefinite status pin that can give us problems This would be the scheme Fritzing ; the relay is not well indicated as I have not found one like it , but I think it means:

You can  download it here , and  here the Digispark  to include in your own projects

Connect everything according to the scheme (the regulator in the picture below is only necessary if the source is more than 5V DC):

I welded and reinforced tracks the connection to the relay , welding it directly instead of using the screws included; this is the pole that connects or disconnects to close the circuit with the device we connect. The other pole is connected directly and have only taken the power transformer:

Put everything in place is complicated , which have 3D printer fabricaros able to measure a box; we need to ensure isolate all right for there is no short. In the following images, the previous version where the relay contros advantage:

I later switched by a relay fed to avoid problems of wear Atmel chip:

The code for the plug would be as follows:

 /* ==================================================================  
  Sketch control relé temporizado por horas; cada vez que se pulsa el botón añade una tiempo predefinido de funcionamiento.  
  Autor: David Losada.  
  Version: 0.1  
  Fecha: 13 de julio de 2016  
   ==================================================================  */  
 //#include  //He utilizado primero un MEGA 2560 con pantalla LCD Keypad Shield para probar el código antes de pasarlo  
 // select the pins used on the LCD panel  
 //LiquidCrystal lcd(8, 9, 4, 5, 6, 7);+  
 //Definición pines digitales para activar relés  
 //PINES USADOS; no uso el 3 ni el 5 porque ambos me daban problemas mientras tenía el USB conectado  
 long timeBoton=3600; //Tiempo en segundos que añade por cada pulsación al temporizador  
 int botonPIN=0; //3 Pin de botón configuración  
 int relePIN=2; //4 Pin activación relé  
 int luzPIN=4; //Pin de luz indicadora  
 int ledPIN=1; //Led del aTTiny85 ver. B está en 1  
 //Variables programa  
 long timeLED=0; //Para encender el LED cada segundo  
 long tiempoRele=0; //Tiempo total al que configuramos para activarlo  
 long tPrevRele=0; //Momento en que ha empezado a funcionar el rele  
 boolean boton=false; //Botón ha sido pulsado  
 boolean luzON=false; //Si la luz azul está encendida  
 void setup()  {   
  //Definir pines  
 pinMode(botonPIN, INPUT);  
 pinMode(relePIN, OUTPUT);  
 digitalWrite(botonPIN,HIGH); //Evitamos fluctuaciones activando con LOW  
 //lcd.begin(16,2); //pantalla de 16 caracteres y 2 filas  
 void loop()   
 //Comprobamos si se pulsa el botón  
  if (digitalRead(botonPIN)==LOW && boton==false) {  
   luzON=false; //apagamos momentáneamente la luz como indicador de pulsación  
 //Si el botón se suelta añadimos hora al tiempo  
  if (digitalRead(botonPIN)==HIGH && boton==true) {  
   tiempoRele=tiempoRele+(timeBoton * 1000);  
 //Se acaba de activar el tiempo; marcamos inicio  
 if (tPrevRele==0 && tiempoRele>0) {  
 //Cuando pasan 50 días millis se resetea  
 if (tPrevRele>millis()) {  
 //Mientras no haya pasado el tiempo establecido, activar Relé  
 if (tiempoRele>0 && (millis()-tPrevRele)millis()) { //Cuando pasen 50 dias resetear  
  if ((millis()-timeLED)>1000) {  
    analogWrite(ledPIN,100); //enciende LED indicando funcioanmiento  
   if ((millis()-timeLED)>500) {  
    analogWrite(ledPIN,0); //apaga led  
  delay(100); //Más de este tiempo no es recomendable o el botón no responderá bien  

This is just one example of the world of possibilities opened up by these economic and small plates Digispark programmable. Happy projects!

More information and links:

No comments :

Post a Comment