# Water level sensor

This is a discussion on Water level sensor within the C Programming forums, part of the General Programming Boards category; I just amended the code and was able to see changes. Now the 7 segment can display 10 when the ...

1. I just amended the code and was able to see changes. Now the 7 segment can display 10 when the water level reaches 10cm, 20 when the water level reaches 20cm and 30 when the water level reaches 30 cm . Now the problem is that when the water level reaches 10cm it shows 10 , when the water level reach 20cm its show 10 than 20 continously in the 7 segment. When it reaches 30cm the 7 segment shows 10 then 20 then 30 continously. How to solve this pro?

Originally Posted by tabstop
So look at your code on the sensor. So far as I can tell you send 15 time units of 'A', then 15 time units of 'W', then 15 time units of 'E' -- since the distinction is based on count, which as far as I can tell is just your timer. Perhaps you should be checking your ADC10MEM instead? (Or at least checking for something other than 80.)
Your code doesn't make much sense..
You have the sensor hooked up to the ADC so I'm guessing the sensor sends an analogue value for the water level.. But you aren't using that value anywhere, you are just looping over a timer interrupt that goes 1..45
What sensor are you using?

Edit: and wtf happened to the default font size?

3. Can u help me on what are the changes that i have to make in order to have the correct reading accordingly. What should be the right ADC value for this? Thanks
Code:
```
#include "msp430x22x4.h"
#include "mrfi.h"
int count=0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
BSP_Init();
MRFI_Init();//initalize 6 pin wire connection between cc2500 & msp430
TACCTL0 = CCIE;
TACCR0 = 37500;
TACTL = TASSEL_2 + MC_1 + ID_3;
P1DIR |= 0x03; // P1DIR = P1DIR | 0x03 Set P1.0, P1.1 to output direction
P1OUT &= ~0x03;
__bis_SR_register(GIE);
for (;;)
{
if(count>=0&&count<=15)
{
TACCR0 =37500; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
{
P1OUT |= 0x01;
P1OUT &= ~0x02;
mrfiPacket_t packet;
packet.frame[9]=' ';
packet.frame[0]=8+20;
packet.frame[9]='A';
MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
}
{
P1OUT |= 0x02;
P1OUT &= ~0x01;
mrfiPacket_t packet;
packet.frame[9]=' ';
packet.frame[0]=8+20;
packet.frame[9]='X';
MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
}
ADC10CTL0 &= ~ENC; // Clear ENC to stop conversion
}
else if(count>=16&&count<=30)
{
TACCR0 = 37500; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
{
P1OUT |= 0x01;
P1OUT &= ~0x02;
mrfiPacket_t packet;
packet.frame[9]=' ';
packet.frame[0]=8+20;
packet.frame[9]='W';
MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
}
{
P1OUT |= 0x02;
P1OUT &= ~0x01;
mrfiPacket_t packet;
packet.frame[9]=' ';
packet.frame[0]=8+20;
packet.frame[9]='Y';
MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
}
ADC10CTL0 &= ~ENC; // Clear ENC to stop conversion
}
else if(count>=31&&count<=45)
{
TACCR0 = 37500; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
{
P1OUT |= 0x01;
P1OUT &= ~0x02;
mrfiPacket_t packet;
packet.frame[9]=' ';
packet.frame[0]=8+20;
packet.frame[9]='E';
MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
}
{
P1OUT |= 0x02;
P1OUT &= ~0x01;
mrfiPacket_t packet;
packet.frame[9]=' ';
packet.frame[0]=8+20;
packet.frame[9]='Z';
MRFI_Transmit(&packet,MRFI_TX_TYPE_FORCED);
}
ADC10CTL0 &= ~ENC; // Clear ENC to stop conversion
}
}
}
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
if (count == 45)
{
count = 1;
}
else
{
count++;
}
}
void MRFI_RxCompleteISR()
{
}```

4. The main problem is the logic, not specific values. I think you can work it out though, just read the code and modify small things to see how they effect the whole system. If we give you all the answers you won't learn anything - the best way to learn is by trying things and seeing what happens.

5. Analog-to-Digital Conversion for 2 Sensors

I worked on the rcvr code just to see; If, I could understand it; no desire to work on the xmtr.
Edit: But, posted link that helps to understand the xmtr code; decided it was generic enough that it might not be based off of it.

Tim S.

6. Now i want to send SMS Using AT Commands for the EMERGENCY level of water level. I have tried Hyperterminal to send and recieve SMS. It works well. I can send and receive SMS in Hyperterminal. But Now I am not sure how to apply that in my C code on water level sensor project? The AT Code that i used for hyperterminal was

at
ok
at+cmgf=1
ok
at+csca="+65--------"
ok
at+cmgs="+65--------"
>HELLO
Press Ctrl and Z

Now how to Send SMS from my project?

7. Originally Posted by Aneesha
Now i want to send SMS Using AT Commands for the EMERGENCY level of water level. I have tried Hyperterminal to send and recieve SMS. It works well. I can send and receive SMS in Hyperterminal. But Now I am not sure how to apply that in my C code on water level sensor project? The AT Code that i used for hyperterminal was

at
ok
at+cmgf=1
ok
at+csca="+65--------"
ok
at+cmgs="+65--------"
>HELLO
Press Ctrl and Z

Now how to Send SMS from my project?
Those are modem commands... open the modem's comport as a file and send them with standard C file read and write commands...

8. Sry, how am i suppose to do that? Can u pls elaborate ? I do not understand by the phrase "open the modem's comport as a file and send them with standard C file read and write commands... ".

9. You can open ports just like you open files in C ... The syntax is a little different for each operating system, but the concept is the same... it's all just streams of data.

It's been a while but I believe it's like this, for Windows...
Code:
`comport = fopen("COM1:", "w+");`

10. comport = fopen("COM1:", "w+"); This command i need to add in the beginning or the part that the EMERGENCY level occurs? AND i still don't understand which C code am i suppose to type under the Emergency level where the water reaches 30cm.

11. I thought this is for embedded? Why are we talking Windows?

Read the datasheet on how to configure and use the UART.

12. My question is how to send SMS in C code in my project water level sensor? What is the code can be used?

13. Yes, you have to write the code. Read the datasheet on UART.

14. what is that to do with my problem?

15. Your problem is you don't know how to write to the serial port. The datasheet tells you how.

Or do you expect people to write the code for you?

Page 4 of 7 First 1234567 Last