Saturday, April 21, 2012

Push Button ON/OFF

21st April, 2012

Ever wondered how can you keep your circuit ON using a push button rather than a toggling switch?

just like in many instruments/ mobile phones etc

the following schematic shows you how,


The idea is that you use the push button to run the circuit normally, and then, very fast (in the beginning of your code if the cct contain a microcontroller) send a signal to close a switch (could be a relay or whatever)

Example on ATmega328

#include <avr/io.h>  
#include <util/delay.h>  
#include <USART.h>  
#define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT))  
#define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT)) 

int main(void)  
{  
    init_usart();  
    SETBIT(DDRB,0);  //Output pin (ON/OFF)
    CLEARBIT(DDRB,1); //Input to change time
    SETBIT(PORTB,1);  //Enable Pull-Up resistor

    for (;;)  
    {  
        for (uint16_t i=30; i>0; i--)  //repeat 15 times going down, used as delay
        {  
            printf("i=%d\n",i);  //just to see whats the current delay value
            _delay_ms(100);  //give me time to release button
            while ((PINB & 0x02)==0x02)  //loop when I don't press button
            {  
                SETBIT(PORTB,0);   //ON
                _delay_ms(i);      //i value as delay
                CLEARBIT(PORTB,0); //OFF 
                _delay_ms(i);
            }  
        }  
    }  
    return 0;  
} 


Remember that when a person pushes a button and releases it, he usually takes quite long (in ms), which is an enough time for the MCU to run, turn the switch ON and keep itself alive :)








26th April, 2012

So I've tried to go with only MOSFETs instead of the bulky relay, I tried this earlier:




which did not succeed as I said, so today I tried this:





which was not successful as welll :S


What am I doing wrong?!!






Thursday, February 16, 2012

Pajero Mod 1.0

Monday evening, when got in my car going back home, I suddenly got the itch to modify the car a lil.

It is annoying that there is no USB port at least for charging:



So I decided to add USB port for charging, and while I'm at it, but some blue LEDs :)

I first removed the passenger drawer


and got access to all the wire-mess inside, yay!





Air Bag!!







anyway, I started with the LED for door,
the LED is super bright and is rated for 80mA, the supply is 12v
R = V/I = 12/0.08 = 150 ohm

I soldered 150 ohm directly to the LED and tried to make the assembly in similar form-factor as the original bulb, the result:


amazing, now to my USB charger, the circuit is like:





and I added hot glue to make sure no short circuit happens

Then fixed the LED to place:



awesome!
and the USB:



now I can charge my phone :)

Friday, February 3, 2012

Battery in Salt Solution

For some reason or another, I got this silly idea of dropping a battery in a water saturated with salt :)

I thought, the salt will act as a conductor with resistance ~ 0 and Imagined all the sparking (really?! spark inside water! just imagine! :P)

I started with the Test Aperture :D

1- Resistance test leads



I cute two ~ 3 inch of steel wire and stripped out 5mm of insulation from both ends and soldered one end to binding post



which I fixed to a glass bottle's cover









And here I got some interesting results

the probes were about 7cm apart from each other (the bottle diameter is about 9cm)


resistance with tap water ~ 70K ohm
resistance with salt water ~ 14K ohm

what a finding!!!!!

This means with the battery inside the water, it won't effectively be a short-circuit, no sparking!!!!


it was kinda depressing, but I continued, I added temperature sensor (LM335) to MCU (ATmega168) to serial port on PC and then I logged the data


Once in water, I saw small bubbles forming on the negative pin and then going out, this continued and continued and continued without spark!!!, after sometime I got bored and stopped the data recording.


you can find the recorded raw data here : Temperature Readings

I graphed it on excel and I found this:



the x-axis numbers are just the index numbers, they dont mean anything, but it is actually for about 16 mins of continues data recording, I assume the ADC clock is maximum which is half the MCU clock which was 16MHz so the ADC is 8MHz

the y-axis is the decimal value of the ADC, so you can go:

V = 5*(y/1023)

V is the actual voltage read by the ADC
5 is the ADC reference voltage
y is the number from the file (the decimal value)
1023 is the ADC counts, for 10-bit ADC (2^10)

then to get the actual temperature, you use the formula from the data sheet of LM335 which is

V = 10mV / K

so

T (K) = V * 0.01

and you get the temperature in Kelvin, however, you might need to do initial calibration with a know temperature and then you subtract/add the calibration value to all other measured values.

Since I don't have this equipment, I used the raw decimal value to see the trend


here, I put the bottle outside and went to sleep, the next day:




















what a mess!

of course, everything including the poor LM335 inside will all go to be disposed  off the universe!

Shall I count it as a fail?!
why the resistance was large?!!
How can I decrease it?!!






Sunday, January 1, 2012

How Fast Relays Are?

From the time I learned about relays, I wondered if they can be used to make an H-Bridge for motors, I asked my professor and he said that you can't because they are slow.

I never knew how slow, till today, so I wrote a small code on my AVR ATmega168 microcontroller

basically, the code send an ON -> delay(x) -> OFF -> delay(x)

where x is a value (in ms) changing every time a button is pressed going down from 15 ms to 1ms

1:  #include <avr/io.h>  
2:  #include <util/delay.h>  
3:  #include <USART.h>  
4:  #define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT))  
5:  #define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT))  
6:  int main(void)  
7:  {  
8:       init_uart();  
9:        SETBIT(DDRB,0);  //Output pin (ON/OFF)
10:       CLEARBIT(DDRB,1); //Input to change time
11:       SETBIT(PORTB,1);  //Enable Pull-Up resistor
12:       for (;;)  
13:       {  
14:            for (uint16_t i=15; i>0; i--)  //repeat 15 times going down, used as delay
15:            {  
16:                 printf("i=%d\n",i);  //just to see whats the current delay value
17:                 _delay_ms(100);  //give me time to release button
18:                 while ((PINB & 0x02)==0x02)  //loop when I don't press button
19:                 {  
20:                      SETBIT(PORTB,0);   //ON
21:                      _delay_ms(i);      //i value as delay
22:                      CLEARBIT(PORTB,0); //OFF 
23:                      _delay_ms(i);
24:                 }  
25:            }  
26:       }  
27:       return 0;  
28:  } 

And then connected the relay, driving it with a NPN



I found that min time is 2ms, at 1ms, no switching will occur ( i was getting highly rippled 5v)



and here is an awesome sound of 1~15ms switching, at 0:16 the time is 1ms



~2ms (500Hz) is the min time (max freq) u can switch a typical relay




Saturday, December 3, 2011

Masafi Water-Air C-Engine Rocket

Playing with air pressure rockets is really awesome, I used to take on of these Masafi bottles, but water hose in (tight fit), pump water -> after sometime, the air pressure inside will be high enough that you can't hold it anymore, then point up and release and BOOOOM

That what happen with one bottle, so what about a whole rocket??

so, I set to make a rocket, which currently is a big fail because I did not have a proper air sealing material,,,

concept of one bottle, first pressurize then release (click to enlarg)


When I connected two, the leak happened as shown

The concept of the Multi-Masafi Water-Air Rocket (cross section showing 2 of the six C-Engine Cylinder :P) and yea, C for Circular, and "strobe" should be "straw"


The pictures above does not show the actual bottle size, below it does (okay, to some extent, excuse my hand skills on MS Paint)

It also shows the expected aerodynamic behavior (the rocket is going up)

  

well, if it failed/drifted etc am gonna add a cone/rocket case to remove the effect of the straws / bottle shape





I collected bottles


drilled the holes



assembled with duct tape and glue gun:








The problem is that glue gun does not withstand air pressure and fails, I'll continue this when I have what I need, till that time, this rocket which looks like one of Yuri's buildings (Red Alert) will stay on the wall


Garage Door

Recently, we moved to another home, unfortunately (or fortunately) the garage door does not work, we open it manually currently, we requested the house owner to fix it but they said that they tried many times but failed, so what does this mean for an EE lover?

An awesomeness of course, a new toy to play with, a new game to reverse engineering :)

I tried the manual button, the motor does work but the door does not move, I tried assisting it by giving it a push but no hope, so apparently, the gears are broken/loose etc a mechanical problem in short.

not only that, but also, we do not have the remote controller, so apparently I'll have to hack it to put my own wireless connection, later..

now lets start playing:


The box:


Now I need to remove the bottom to reach the mechanical problem and fix it, I had to use a lot of force to open these two blots on bottom:


notice how the spanner got bended in the image below



What about this dried-sanded grease:






overview of the inside, 
top right is the motor with three wires (I don't have experience with motors, so your help is apperciated here, the motor has three wires two of them are connected the big cylinder you can see on the top left [I guess a cap??!] and there is a third wire)
What is this motor? which type? what are the three wires?
Is it a capacitor really? why it is there?

top left a capacitor (I guess)
below it is the transformer
and on bottom the PCB
Wireless chip on right side of PCB
Connection Header on top of PCB


The circuit 





started labeling some wires


I then used WD-40 and sprayed on the screws to remove the PCB (Along with the transformer which is soldered to the PCB)



Now I need to remove wires, so I took note of all connections and labeled wires



Before that, I decided to test it, found that the motor is actually rotating as well as the output shaft
so, I reconnected it up again, but again it does not work!!!

conclusion: the mechanical assembly is having a problem which I cannot fix

repairing attempt Failed!