free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems
Hi everyone, I need help with what I think should be a very simple C code:
I have 2 input signals and 1 output signal InputSignal1(IS1) = 1 determines my OutputSignal(OS) to be 1 InputSigna 2(IS2) = 0 determines my OS to be 0 Thats about it. The 2 signals are from 2 water levels and the output signal should command for a water valve to open to fill up my water tank if the water level is below a certain limit and to close when it gets to my upper limit.
I was thinking to use only PortA for both inputs and outputs, something like: PA0, PA1 inputs, PA2 output, but I'm not sure if it's correct and exactly how to do it. If u guys could help me it would be so great. Thanks
So, if I understand you correctly, IS1 is a lower level sensor, which means the water level has reached a low level, and the container needs to be filled up again, and IS2 is an upper level sensor, which means the water level has reached a maximum level, and the water needs to be turned off.
If this is the case, you are correct: The software is fairly simple:
You need a flag to indicate that the lower level sensor has been reached. This flag will be used to turn on the water valve. As the water rises, the lower level sensor will no longer be active, but that's okay, because the flag will still be set, so the valve will remain open. As soon as the upper sensor is reached, it will disable the flag. The output will reflect the flag status always: flag on means output valve is on, flag off -> output off...
So what will the software look like? Give it a try and let's have a look at what you have attempted. There are other things to consider, like sensor jitter, but that will come after your first attempt at the software...
Now, consider what might happen if there is noise on the input line from the sensors...
There is a technique called "digital filtering" that can keep you from reacting to a false positive.
Reading the input over and over again, and only setting the flag if the input stays constant for a few successive reads can reduce the possibility of reacting to a false positive.
If you have a filter built into your electronics, then the digital filtering probably isn't necessary. I always provide a method within my code just in case I want to implement it later on, or if during debugging, I find I have a noisy system.
You can play around with it by changing the debounce value. If you are tight on code space, then I would probably leave it out.
Regarding the connection, as long as the voltage levels and current levels are right, you only need to connect the sensors. My guess is, though, that driving the solenoid from the processor isn't such a good idea. Calculate the current draw from the solenoid coil, and you'll probably come up with the same conclusion. Besides, there's things like back EMF when you open the solenoid ( coil field collapses ) that can damage a micro very quickly. I always isolate loads like this with a driver of some kind.
Good luck,
-Dave "Basic research is what I am doing when I don't know what I am doing"
Yeah, and what is the voltage level for your microcontroller? And what is the current sinking capability of your port pin? Check the data sheet for these values, and you'll probably find that your micro is out-matched by the solenoid coil load by a significant amount...
My suggestion is go with a transistor to turn the solenoid on and off, or maybe an opto-isolator / driver...
-Dave "Basic research is what I am doing when I don't know what I am doing"
Yea, my microcontroller is supplied at 5V and I indeed have a tranzistor that comands the relay .
So in conclusion I only need to connect the 3 pins? I don't know why but I thought that ground is supposed to be common for all the circuit, that's why I wanted to connect the microcontroler ground with the sensor cirucit ground.
when i press new thread it shows the page with subject and the box for my description.but when i got to type anything it stops. went into settings and the same thing happened
thought it could be my settings so tried it on another computer but it done the same!!i am a member but do i have to do something else before i can us the forum?! it doesnt have sample code in .c code
8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems