Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

float switch... interfacing with a atmega32 board..

Status
Not open for further replies.

poo

New Member
hi all..
has any1 done the project related to the above mentioned topic ??.. i want to measure the diesel level in tank.. n the mesage has to displayed on lcd of the board... i hav the wriiten the program too.. but the board is not recognising the output of float switch ..... :(... check the attached file...

please help me out... happy morning :)
thank u
 

Attachments

  • user manual111.pdf
    547 KB · Views: 395
So what is the float control you are using?
There is a million and one float controls on the market, making your question a one in a million to answer.

Pete.
 
If it is a float switch, it is capable of quantizing the fuel level to one bit! If it is a fuel sender (like in a car), then you can read an analog voltage with an AD, however, the resistance vs float arm position is highly non-linear, and you will have to calibrate the sensor by adding a gallon/liter at a time to the tank while recording resistance/voltage.
 
hi saborn ..
sorry fa tat..i ll attach t float switch pic...please chk it... i m doin a project on..

REMOTE MONITORING OF GENERATOR USING GSM MODEM IMPLEMENTED IN BTS
Introduction:
Often in the base transceiver station (BTS) there is a power failure and a generator is to be turned on to keep the BTS in working condition. Here in our project we monitor the diesel level in the BTS and send the information to the GSM modem. The information is through SMS. Information includes the BTS name and the diesel level. We further would create a virtual personal area network using four GSM modems which will monitor their respective BTS and will send the message to the controller server. Hence an immediate refill of diesel can be called and avoid failure of the system. This will avoid the failure of BTS and will provide caution before the system fails. An effective wireless network can thus be established.
Objectives:
 Design a circuit for measuring the diesel level using float switch.
 Interface the float switch to ATMEGA32 based development board.
 Code the ATMEGA32 to decode the voltage level sent by the switch.
 Further coding for generating appropriate message for transmission.
 Interfacing ATMEGA32 to the GSM modem.
 GSM modem will push the message to the server.
Applications:
 The system can be efficiently made use in BTS.
 The system can be used for remote monitoring of generator diesel level or even for that matter for water tank also.
This project can be extended for interactive monitoring that is receiving message from sever and processing it and taking the appropriate action.

now t problem is with float switch part... i m not able to read the current value at atmega32 port ... if i m done wit this... ma project works well... please help me...and i hav added the file of GSM modem too...
 

Attachments

  • BIGPND~1.DOC
    17 KB · Views: 299
  • 01_VFS.pdf
    1.4 MB · Views: 832
hi mike..
its a float switch... oh oki.. this switch has 3 output wires... for 3 levels in a tank...and for example if the diesel comes to mid level.. t reed switch comes in contact and the current flows thru tat wire.. and in turn it is connected to the atmega board... but i m not able to read tat value at the port...

please check.. the..previous post of mine.. i hav attached the related files of float switch... please help me...
 
First im not fluent with the atmega, so unable to help with any programming there, and as you have not given any schematic of your circuit setup i can only make a guess to the problem.

What i suspect is, you do not have a pullup or pulldown resistor on your inputs to the micro and have the inputs floating till a reed switch is activated.

If you have negative going to the float sensor which is switched via the float reed switches to the micro than you will need pullup resistors on the micro inputs, (5K-10K should be fine) or pulldown resistors if you are switching positive with the float switches.

Pete.
 
hi saborn..

programming is not a problem sir. rite now i hav built a circuit to generate current.. i have not yet used float switch.
and the micro has internal pull up resistors. the current output i hav given it to the port A. but i am not able to read the value :(
My friends told me to use a buffer.. Will that be of help ?


sir, can u giv me ur mail id
 
I can not see what difference a buffer will make to a switch.

If you have internal pullups than you need to have negative running to the switch.

As i said i dont know the atmega, but you might need to add a lower resistance pullup external resistor as i would expect the internals to be rather high resistance.

It would help if you quoted some values for things rather than just say it has internal pullups.

Are you sure you dont have a program error, and have you tried stripped all the program down to just reading 1 input with a switch on it to see if you have a bug else where in your program.

Do you have a delay in the program after it reads a switch response to allow for switch bounce, as you could be reading a on / off all in a single action.

All we know is you have a problem but no information to work with, and my crystal ball is Chinese made and it dont work worth crap.

Pete.
 
I don't get it. You have a float switch but even though you linked to them you don't mention which version in the link you have? One single point switch? Four switches? Which one?

Even with a float switch if it only contains a single switch they come in SPST and SPDT so again, which switch?

Best case with a single switch you can tell if the tank is at some point and that is as good as it gets. If for example you have a 400 liter tank that is linear and the switch is 1/4 up from the bottom we can assume when the switch changes states the tank will have about 100 liters remaining. That is as good as it gets.

So the uC input will see a 1 or a 0 (high or a low). If the switch closes at 1/4 tank your code should pick up the transition from high to low on a pin designated as a DI pin. You do not need a switch to check your code. Place a logic low on the DI pin and the code should respond. That would be the code you don't want to post. If you think you have a uC problem there is a section of these forums dedicated to micro controllers.

Without seeing the code, a schematic and knowing the exact switch that is as good as it gets.

Additionally forum members do not generally give out their email addresses.

Ron
 
saborn

ya sir we have given enough delay for the switch to read...thats not a problem now the problem lies in the taking the voltage and interpreting it as one or zero.....
 
Last edited:
hello ron...float switch has three wires to indicate each level of fuel low,mid or high every time fuel reaches a particular level particular wire gives out 5v and some 0.5amps current so we built the circuit to reduce the current since our micro controller can take only max of 20ma so...in our current reduction circuit just ttl logic 7408 and in series with a 560 ohms resistor that gave us some 8ma output current so we were happy to connect it to board but when we connect it the atmega32 board is driving the voltage i dont know why??????????what can be the best solution please reply...as quickly as possible
 
hello ron...float switch has three wires to indicate each level of fuel low,mid or high every time fuel reaches a particular level particular wire gives out 5v and some 0.5amps current so we built the circuit to reduce the current since our micro controller can take only max of 20ma so...in our current reduction circuit just ttl logic 7408 and in series with a 560 ohms resistor that gave us some 8ma output current so we were happy to connect it to board but when we connect it the atmega32 board is driving the voltage i dont know why??????????what can be the best solution please reply...as quickly as possible

OK, now we are getting somewhere. This also makes sense. Well, almost sense. When the pins of the uC are programmed as a DO (Digital Out) they can sink or source a limited amount of current and I believe that is where you came up with the 20 mA.

You mentioned that the switches have 3 wires? If you have levels of low, mid and high the switch should have 4 wires total? The 5 volts is coming from somewhere? If I apply 5 volts to the switch common then I can understand the 5 volts but there would be a 4th wire as the 5 volts is coming from somewhere?

You mention the uC has internal pull up correct? That tells me if you configure the pins for DI (Digital In) the pins will float at between 3.3 and 5 volts depending on the uC. Placing a low on any of those pins will produce results. But ..... Let me maks a drawing to explain this. Back soon.

OK attached is a very rough sketch of a uC using digital inputs driven by switches. The resistors drawn in the uC are the internal pull up resistors. The uC is programmed so the Digital In/Out pins D0, D1 and D2 are Inputs. I just used simple switches that are NO (Normally Open but when the tank is full they are all closed. The switches in my example likely could have been drawn better. Since when the tank is full all switches are closed as the tank level decreases the switches will sequentially open top to bottom.

Switch 3 will open and D0 will go high and the code for that D0 pin would look something like:

if pin D0 = 1 then
do something the tank has 1/3 less than full

if pin D1 = 1 then
do something else the tank is down 2/3

Something along those lines is where I think you should be going. This is based on your mention about the internal pull up resistors. The DIO pins should be programmed as DI.

The attached was done in haste so I hope you get the idea.

Ron
 

Attachments

  • u Controller.gif
    u Controller.gif
    10 KB · Views: 188
Last edited:
yes sir exactly you got it ..we have four wires one for common and three for indication....yeah this is the way it is connected to uc but our uc is not responding instead it driving voltage from the switch connection...
 
As i had said earlier for best results the switches need to have negative wired to them not 5v+ as you have said you have, the reason is you have "pullup" resistors and not pulldown as you would require for 5v+ to the switches.

As Ron said the micro only sees 1's and 0's and with 5v+ to the switches than it will only ever see 1's and never 0's so you will not get a change in state on the input.

Secondly having a ground supply to the switches if far safer than having 5v+ supply when you concider it is a fuel tank.

I dont see what you are requiring limiting resistors for as its just a simple pull low with the switches and pulled high with the pullups circuit, so the most current that will be drawn is via the pullups.

Pete.
 
thank you sir for the suggestion i will try that simultaneously i am uploading the program please check it and let me know if there are any errors..


#include <avr/io.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>



#define LED_PIN1_DDR DDC6
#define LED_PIN1 PC6
#define LED_PIN2_DDR DDC7
#define LED_PIN2 PC7
#define LED_PORT PORTC
#define LED_DDR DDRC
#define LOW(uint) (uint&0xFF)
#define HIGH(uint) ((uint>>8)&0xFF)

#define LCD_DATA_PORT PORTD
#define LCD_DATA_DDR DDRD
#define LCD_D7 PD7
#define LCD_D6 PD6
#define LCD_D5 PD5
#define LCD_D4 PD4
#define LCD_CONTROL_PORT PORTB
#define LCD_CONTROL_DDR DDRB
#define LCD_RS_PIN PB0
#define LCD_RW_PIN PB1
#define LCD_EN_PIN PB2
//important
#define SET_FUNCTION 0x28 // 8bits, 2lines
#define DISPLAY_ON 0x0C
#define DISPLAY_CLR 0x01
#define ENTRY_MODE 0x06 // Entry = increase
#define RETURN_HOME 0x02
#define CURSOR_BACK 0x10
#define SET_DDRAM 0x80
#define WRITE_DATA 1 //
#define WRITE_COMMAND 0 //
#define LCD_EN 0x80
#define LCD_LINE_TWO 0x40



extern void lcd_init(void);
extern void lcd_gotoxy(unsigned char x,unsigned char y);
extern void lcd_putc(unsigned char c);
extern void lcd_print( unsigned char * ptr );
extern void lcd_print_p( PGM_P ptr );

//typedef enum _BOOL { false = 0, true } bool;
typedef unsigned char BYTE; // 8-bit
typedef unsigned int WORD; // 16-bit
typedef unsigned long DWORD; // 32-bit

typedef union _BYTE_BITS
{
BYTE byte;
struct
{
unsigned char bit0:1;
unsigned char bit1:1;
unsigned char bit2:1;
unsigned char bit3:1;
unsigned char bit4:1;
unsigned char bit5:1;
unsigned char bit6:1;
unsigned char bit7:1;
} bits;
} BYTE_BITS;

typedef union _WORD_BYTES
{
WORD word;
BYTE bytes[2];
struct
{
BYTE low;
BYTE high;
} byte;
struct
{
unsigned char bit0:1;
unsigned char bit1:1;
unsigned char bit2:1;
unsigned char bit3:1;
unsigned char bit4:1;
unsigned char bit5:1;
unsigned char bit6:1;
unsigned char bit7:1;
unsigned char bit8:1;
unsigned char bit9:1;
unsigned char bit10:1;
unsigned char bit11:1;
unsigned char bit12:1;
unsigned char bit13:1;
unsigned char bit14:1;
unsigned char bit15:1;
} bits;
} WORD_BYTES;

typedef union _DWORD_BYTE
{
DWORD dword;
WORD words[2];
BYTE bytes[4];
struct
{
WORD low;
WORD high;
} word;
struct
{
BYTE LB;
BYTE HB;
BYTE UB;
BYTE MB;
} byte;
struct
{
unsigned char bit0:1;
unsigned char bit1:1;
unsigned char bit2:1;
unsigned char bit3:1;
unsigned char bit4:1;
unsigned char bit5:1;
unsigned char bit6:1;
unsigned char bit7:1;
unsigned char bit8:1;
unsigned char bit9:1;
unsigned char bit10:1;
unsigned char bit11:1;
unsigned char bit12:1;
unsigned char bit13:1;
unsigned char bit14:1;
unsigned char bit15:1;
unsigned char bit16:1;
unsigned char bit17:1;
unsigned char bit18:1;
unsigned char bit19:1;
unsigned char bit20:1;
unsigned char bit21:1;
unsigned char bit22:1;
unsigned char bit23:1;
unsigned char bit24:1;
unsigned char bit25:1;
unsigned char bit26:1;
unsigned char bit27:1;
unsigned char bit28:1;
unsigned char bit29:1;
unsigned char bit30:1;
unsigned char bit31:1;
} bits;
} DWORD_BYTES;

// mac address structure
typedef struct _MAC_ADDR
{
BYTE byte[6];
}MAC_ADDR;

// ethernet header structure
typedef struct _ETH_HEADER
{
MAC_ADDR dest_mac;
MAC_ADDR src_mac;
WORD_BYTES type;
}ETH_HEADER;

// IP address structure
typedef struct _IP_ADDR
{
BYTE byte[4];
}IP_ADDR;

// IP header structure
typedef struct _IP_HEADER
{
BYTE version_hlen;
BYTE type_of_service;
WORD_BYTES total_length;
WORD_BYTES indentificaton;
WORD_BYTES flagment;
BYTE time_to_live;
BYTE protocol;
WORD_BYTES checksum;
IP_ADDR src_ip;
IP_ADDR dest_ip;

}IP_HEADER;

// ARP packet structure
typedef struct _ARP_PACKET
{
WORD_BYTES hardware_type;
WORD_BYTES protocol_type;
BYTE hardware_length;
BYTE protocol_length;
WORD_BYTES opcode;
MAC_ADDR src_mac;
IP_ADDR src_ip;
MAC_ADDR dest_mac;
IP_ADDR dest_ip;
} ARP_PACKET;

// ICMP packet structure
#define ICMP_MAX_DATA 32
typedef struct _ICMP_PACKET
{
BYTE type;
BYTE code;
WORD_BYTES checksum;
WORD_BYTES identifier;
WORD_BYTES sequence_number;
BYTE data[ICMP_MAX_DATA];
} ICMP_PACKET;

// TCP Header
typedef struct _TCP_HEADER
{
WORD_BYTES src_port;
WORD_BYTES dest_port;
DWORD_BYTES sequence_number;
DWORD_BYTES seqack_number;

union
{
struct
{
unsigned char reserved:4;
unsigned char value:4;
}nibble;
unsigned char byte;
}data_offset;

union
{
struct
{
unsigned char FIN:1;
unsigned char SYN:1;
unsigned char RST:1;
unsigned char PSH:1;
unsigned char ACK:1;
unsigned char URG:1;
unsigned char reserved:2;
} bits;
unsigned char byte;
} flags;
WORD_BYTES window;
WORD_BYTES checksum;
WORD_BYTES urgent_pointer;
} TCP_HEADER;

typedef struct _TCP_OPTION
{
BYTE kind;
BYTE length;
WORD_BYTES max_seg_size;
} TCP_OPTION;

typedef struct _UDP_HEADER
{
WORD src_port;
WORD dst_port;
WORD length;
WORD checksum;
} UDP_HEADER;

union flag1
{
BYTE byte;
struct
{
unsigned char key_is_executed:1;
unsigned char update_display:1;
unsigned char lcd_busy:1;
unsigned char key_press:1;
unsigned char send_temp:1;
unsigned char syn_is_sent:1;
unsigned char syn_is_received:1;
unsigned char send_temp_timeout:1;
}bits;
}flag1;

union flag2
{
BYTE byte;
struct
{
unsigned char key_hold:1;
unsigned char unuse:7;
}bits;
}flag2;


void lcd_send_nibble(unsigned char data)
{
data &= 0xF0;
LCD_DATA_PORT &= 0x0F;
LCD_DATA_PORT |= data;
_delay_us(1); // 1us
LCD_CONTROL_PORT |= _BV(LCD_EN_PIN);
_delay_us(2);
LCD_CONTROL_PORT &= ~_BV(LCD_EN_PIN);
}

void lcd_send_byte( char data_or_cmd, char data )
{
LCD_CONTROL_PORT &= ~_BV(LCD_RS_PIN);
if(data_or_cmd)
LCD_CONTROL_PORT |= _BV(LCD_RS_PIN);
else
LCD_CONTROL_PORT &= ~_BV(LCD_RS_PIN);
_delay_us(50); // 1us
LCD_CONTROL_PORT &= ~_BV(LCD_EN_PIN);
lcd_send_nibble(data & 0xF0);
lcd_send_nibble(data << 4);
}

void lcd_init(void)
{
char i;
LCD_DATA_DDR |= (_BV(LCD_D7) | _BV(LCD_D6) | _BV(LCD_D5) | _BV(LCD_D4));
LCD_CONTROL_DDR |= (_BV(LCD_RS_PIN) | _BV(LCD_RW_PIN) | _BV(LCD_EN_PIN));

LCD_DATA_PORT &= ~(_BV(LCD_D7) | _BV(LCD_D6) | _BV(LCD_D5) | _BV(LCD_D4));
LCD_CONTROL_PORT &= ~(_BV(LCD_RS_PIN) | _BV(LCD_RS_PIN) | _BV(LCD_RS_PIN));

_delay_ms(15); // 15 ms
for(i=1;i<=3;++i)
{
lcd_send_nibble(0x30);
_delay_ms(5); // 5 ms
}
lcd_send_nibble(0x20);
lcd_send_byte(WRITE_COMMAND, SET_FUNCTION);
lcd_send_byte(WRITE_COMMAND, DISPLAY_ON);
lcd_send_byte(WRITE_COMMAND, DISPLAY_CLR);
lcd_send_byte(WRITE_COMMAND, ENTRY_MODE);
}

void lcd_gotoxy( unsigned char x, unsigned char y)
{
char address=0;

if(y!=1)
address = LCD_LINE_TWO;
address += x-1;
lcd_send_byte(WRITE_COMMAND, SET_DDRAM|address);
}

void lcd_putc( unsigned char c)
{
if(c == '\f')
{
lcd_send_byte(WRITE_COMMAND, DISPLAY_CLR);
_delay_ms(2); // 2ms
}
else if(c == '\n')
lcd_gotoxy(1, 2);
else if(c == '\b')
lcd_send_byte(WRITE_COMMAND, CURSOR_BACK);
else
lcd_send_byte(WRITE_DATA, c);
}

void lcd_print( BYTE *ptr)
{

while( *ptr )
{
lcd_putc(*ptr++);
}
}

void lcd_print_p( PGM_P ptr )
{
unsigned char c;

while( (c = pgm_read_byte ( ptr++ )) )
{
lcd_putc(c);
}
}
delay()
{
while ( (TIFR & _BV ( TOV1 )) == 0 );
TIFR |= _BV(TOV1);
TCNT1 = 1536;
}







int main (void)
{
unsigned char float_switch_read;
char msg[4];
int i;
TCCR1B = 0x01;
lcd_init ();
DDRC|=0xf8;
PORTC|=0x07;
PINC &=0x07;
switch(PINC)
{
case(0x04):
delay();
msg[0]='h';
msg[1]='i';
msg[2]='g';
msg[3]='h';
break;
case(0x02):
delay();
msg[0]='h';
msg[1]='a';
msg[2]='l';
msg[3]='f';
break;
case(0x01):
delay();
msg[0]='l';
msg[1]='o';
msg[2]='w';
msg[3]=' ';
break;
default:
msg[0]='e';
msg[1]='r';
msg[2]='o';
msg[3]='r';
break;

}
for(i=0;i<=3;i++)
{
while ( (TIFR & _BV ( TOV1 )) == 0 );
TIFR |= _BV(TOV1);
TCNT1 = 1536;
lcd_putc(msg);
}








return 0;
}
 
Rather than posting your entire code and expect someone to filter through lines of code, why dont you just go back to basics and try to read a single switch in code and get that part sorted out first.

What i would normally do is use a basic code to read the switch and light a led, once you have that part working then its easy to add it to the main program.

The whole thing with programming is to do each step at a time and get it to work then advance to the next stage, then it becomes easy to string it all together.

Pete.
 
Glad it worked for you.

Ron
 
The best way to look at your problem you had is 2 high's dont make a low.

Ie: high on the pullup resistors and a high on the signal in, can only ever give you a high on the input pin, it is never pulled low so the micro will only ever see a high input.

Using ground through the float switches will pull each input pin low as the switch is activated.

Good to see you have the circuit working but if you had followed my advice from around the first post you would have solved the problem days ago.

We live and learn so good luck with your project.

Pete. (not sir???)
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top