PDA

View Full Version : Automatic Toilet Flusher



Techbuilder
- 30th January 2008, 13:03
Hi everyone maybe you can help me out

My room mates never flush the toilet and no matter how much I yell at them
they still do not flush the toilet.

I want to build an automatic toilet flusher so all they have todo is pass there hand by it or just have a timer when it detected someone.

Here's what I have an idea of what I need

1 servo

1 Pic micro controller 16F627A

1 Ir receiver

1 Ir led

and I already know the resistors and caps I need.

Should I go with a different approach for programing or do you think that this sounds like a pretty solid toilet flusher?

Acetronics2
- 30th January 2008, 13:29
Hi,

2nd Idea :

" My room mates never flush the toilet and no matter how much I yell at them
they still do not flush the toilet."

Is it really their duty to do that ...


Now, talking electronics ...

the "industrial" toilets flushers work like that ... and some I know ( mainly highway and hospital toilets ) use the 16F628 chip !!!

the only difference is commercial ones use an electro-valve.


Interesting point ...

Think to what happens if mains failure lasts a bit ...

Alain

Pic_User
- 30th January 2008, 13:29
Hi everyone maybe you can help me out

My room mates never flush the toilet and no matter how much I yell at them
they still do not flush the toilet.

I want to build an automatic toilet flusher so all they have todo is pass there hand by it or just have a timer when it detected someone.

Here's what I have an idea of what I need

1 servo

1 Pic micro controller 16F627A

1 Ir receiver

1 Ir led

and I already know the resistors and caps I need.

Should I go with a different approach for programing or do you think that this sounds like a pretty solid toilet flusher?

Hi Techbuilder,

No sense “re-inventing the wheel”.
To get an idea of various ways, already in use.

Paste this:
automatic flush infrared

Into here:
http://www.google.com/patents

It is perfectly legal and acceptable to adopt patent ideas for your own use, but not for resale or distribution.
(Edit: For the record. The above statement is incorrect. It is NOT “legal and acceptable to adopt patent ideas for your own use”. The law allows some very special exceptions but I was in error stating this so broadly. Thanks to tenaja for correcting my mistake. –Adam-)

You can get an idea of what is needed to “do the job”. The whole mechanical side may be a problem.

-Adam-

sayzer
- 30th January 2008, 14:01
Here is another idea.

Install all your IR equipment there.

But, connect the circuit to the door lock.

If the toilet is NOT flushed, the door remains locked.


This way, your roomies will learn to listen to you and also will learn to flush it.

When they eventually flash, play an MP3 saying "AHAA !"


--------------------

Luciano
- 30th January 2008, 14:32
Hi,

On Monday, Lego celebrated the 50th anniversary of the day
it filed its first patent for the iconic plastic brick....

Lego Mindstorms NXT automatic toilet flusher:
http://www.battlebricks.com/roboflush/index.html

Link to the video:
http://www.youtube.com/watch?v=xvZU2PchUmY

Best regards,

Luciano

Techbuilder
- 30th January 2008, 14:38
lol that would be funny to lock them in


Although the patents didn't have the simplicity I was looking for

I know the mechanical way I want to set it up I just don't know what would be easier to program.

Any ideas?

I was thinking about purchasing the Sharp GP2D12
but instead I already have an IR receiver and IR Led.

What do you think the best approach is?

tenaja
- 30th January 2008, 16:06
It is perfectly legal and acceptable to adopt patent ideas for your own use, but not for resale or distribution....

Actually, this is not a true statement. Sure, it is highly unlikely you will get caught or sued, but if you do get caught, you may find yourself in court (or settling).

Acetronics2
- 30th January 2008, 16:29
I was thinking about purchasing the Sharp GP2D12
but instead I already have an IR receiver and IR Led.

What do you think the best approach is?


Best or simpliest ???

for "private" use the sharp module will HIGHLY simplify the thing ( and the programming ! ) ...

looking to the cost ... an IR Led, plus a phototrans. will make it.

Alain

Techbuilder
- 30th January 2008, 17:09
Well I do want the simplest
but I don't have very much money either.

I have a book that kind of describes what I want to do but it is in assembly or c,
I can't tell but it's not in basic.

What would you describe the level of difficulty of the programming going with the cheap option?

skimask
- 30th January 2008, 17:35
Well I do want the simplest
but I don't have very much money either.
I have a book that kind of describes what I want to do but it is in assembly or c,
I can't tell but it's not in basic.
What would you describe the level of difficulty of the programming going with the cheap option?

A momentary switch bolted to the door frame connected to a solenoid that throws the flush handle and/or lifts the trap at the bottom of the tank.
Door opens one way, it brushes the lever, but it's the wrong way to close the contacts. Maybe the lever is on a one-way hinge so it can flip the one way without a problem.
Door closes the other way, it brushes the lever, and it's the right way to close the contacts.
The solenoid is bolted to the wall behind the toilet. The arm of the solenoid is connected to a cable that pulls the trap at the bottom of the toilet tank.
Use a solenoid like one from a trunk release of a car, or door lock or something...anything.

I think that's about as simple as you can get...1 12v battery pack + small charger, 1 level switch and attaching hardware, 1 junk solenoid from a salvage yard, some wires and a piece of cable.

No programming, no PIC, no nothing, just a bit of hardware...done...
That and kicking your roommates square in the ding-ding.
I mean, that's just plain nasty...

Pic_User
- 30th January 2008, 17:41
What if, Techbuilder’s next step was to get them to close the door… :eek:

skimask
- 30th January 2008, 18:00
What if, Techbuilder’s next step was to get them to close the door… :eek:

Oh....now that's just nastier...:D

How about the foot switch? Gotta step in to step out....

Techbuilder
- 30th January 2008, 19:08
lol you guys are nuts

I just want to flush the toilet by moving my hand across the IR beam
and the servo push the handle down.

If I used a car solenoid it would break the handle of the toilet
lol

and I don't want a whole bunch of messy wires just something plan and simple.

If I put wires up connecting from the door to the toilet there just going to take it down when we have guests.

lol

No one has a solution

electronically? lol

I am surprised you guys haven't said to attach a cap to the door knob and if they don't flush the toilet then IR receiver sends the signal to power the transistor to charge the cap, and shock them when they touch the handle.
lol

Good Idea though

I just want something clean

Archangel
- 30th January 2008, 21:59
lol you guys are nuts

I just want to flush the toilet by moving my hand across the IR beam
and the servo push the handle down.

If I used a car solenoid it would break the handle of the toilet
lol

and I don't want a whole bunch of messy wires just something plan and simple.

If I put wires up connecting from the door to the toilet there just going to take it down when we have guests.

lol

No one has a solution

electronically? lol

I am surprised you guys haven't said to attach a cap to the door knob and if they don't flush the toilet then IR receiver sends the signal to power the transistor to charge the cap, and shock them when they touch the handle.
lol

Good Idea though

I just want something clean
Hi Techbuilder,
Your problem is not technical, it is more a matter of hygiene training, essentially political. . .
some people train dogs by rubbing their nose in it, you might try that either directly, by giving them a whirl or indirectly by putting up a board with their names and stars and sad faces, and make sure everyone sees it!
JS

Jerson
- 31st January 2008, 01:26
Hi everyone maybe you can help me out
Here's what I have an idea of what I need

1 servo

1 Pic micro controller 16F627A

1 Ir receiver

1 Ir led

and I already know the resistors and caps I need.

Should I go with a different approach for programing or do you think that this sounds like a pretty solid toilet flusher?
Well, you seem to be on the right track except that you need a solenoid valve to make this viable. Instead of the servo, you fit a solenoid valve in series with the flush outlet; of course you have to remove the manual flush valve. This will work on a direct inlet pipe only. No cisterns here.

The other 'political' approach is to do what my little kids do. "If you don't flush, next time, I will not flush"

JF

Techbuilder
- 31st January 2008, 01:50
I wouldn't need a solenoid if I have the servo

Here's how the servo is

(it's a rough sketch)

Pic_User
- 31st January 2008, 02:28
Hi Techbuilder,
A regular hobby servo actuating the flush handle, may not have enough torque. I guess the force needed depends upon the toilet model.
-Adam-

Techbuilder
- 31st January 2008, 03:23
Handle only requires 1 to 2 pounds to press down
And a hobby servo can do that easily.

That's why I decided to go with that

Jerson
- 31st January 2008, 03:38
If you think a servo will work, why not try it out? I have a hunch though ....

JF

Techbuilder
- 31st January 2008, 03:54
I tried it yesterday and it flushed
but I had it connected to an RC Receiver instead of a PIC.

I just need help with electrical not mechanical (got that working yesterday)

I just wanted to know since I am a beginner at PICs

if it would be easier to do it with the Sharp GP2D12
or IR receiver and IR Led.

Now I know the Sharp is easier but how difficult would it be to make a program
with the IR receiver and IR Led?

Archangel
- 31st January 2008, 04:31
I think I would move. Anyone who fails to flush may well fail to wash, and then handle your dishes, food etc . . . Opinions are like . . .roommates, some of them just do not wash . . . If you are really determined to do this, a car lock servo would be concealable in tank or behind it pulling up on the flapper, or use the servo to turn a shaft which has a string or cable . . .

Techbuilder
- 31st January 2008, 08:48
Yeah it's a annoying

They wouldn't mess with it if it was just attached to the knob
but I really don't think I have to mess with anything besides that.

b1arrk5
- 1st February 2008, 01:17
Take a look at the Parallax website, they have some tutorials that you can download. One of them gives an example of using the Basic Stamp freqout command to drive an infrared emitter, and then collecting the signal if it is reflected back by an object in close proximity. The neat thing about their approach is that they demonstrate that by changing the modulated frequency you can determine a relative distance to the object. So, no one in the room, no reflection, someone approaches the toilet, wait, they leave, then gosub flush. I would suggest that you also monitor the temperature of the water feed line into the toilet. If unused, the water temperature will be close to room temperature. If you sense a drop in temperature while the infrared sensor senses someone close, or shortly thereafter, then that person flushed, (your fresh water should be colder,) and you don't waste any water flushing a second time.

I'm sure that the infra-red information is in the 'Toddler' robot section of the Parallax site, and I think it appears in a few other places. You'll have to experiment to find the maximum range. Radio-Shack now carries some Parallax sensors, they have a passive infra-red motion sensor, I believe that it's only seven or eight dollars. Might be worth a look.

Good luck!

Jerry.

Techbuilder
- 1st February 2008, 13:39
That's kind of want to do

What I want is just an IR sensor that reads when a hand has been passed by it and turns the servo all the way to the left (or right) and flushes the toilet.

I made a drawing

Pic_User
- 1st February 2008, 15:17
Some ideas about this here:
Infrared Proximity Sensor
http://www.g9toengineering.com/AllSaints/infraredproximity.htm

-Adam-

Techbuilder
- 1st February 2008, 20:51
Some ideas about this here:
Infrared Proximity Sensor
http://www.g9toengineering.com/AllSaints/infraredproximity.htm

-Adam-

This is exactly what I am talking about

but how hard would it be to interface with a PIC?

BobK
- 2nd February 2008, 01:58
Hi Techbuilder,

I really like your determination to build something. BUT, if they won't flush the toilet, what makes you think they'll wave their hand in front of a motion sensor that'll cause the toilet to flush? Here's an idea---get an under the carpet pressure pad and hook it up to an 12Fpic. Get a pretty pink toilet mat to pu over the pad. The system will sit in a WHILE/WEND loop until the USER is off the pad then it activates your solenoid to flush the toilet. Oh my gosh. I can feel the idea juices starting to flow. Is it exciting. Keep going and let us know your progress. I love this idea stuff.

HTH,

BobK

Techbuilder
- 2nd February 2008, 05:58
I asked them would you at least wave your hand
and they said they would.

We don't have a carpet

Plus I think the way I drew it would be the best solution
to get them in the habbit

Yelling does nothing

Techbuilder
- 2nd February 2008, 20:23
Hey Pic_User or anyone

Is it difficult to interface the that link that you gave me to a pic?

All I want it to do is when it comes in contact, to rotate the servo all the way to the right or all the way to the left.

Pic_User
- 3rd February 2008, 02:09
Hey Pic_User or anyone

Is it difficult to interface the that link that you gave me to a pic?

All I want it to do is when it comes in contact, to rotate the servo all the way to the right or all the way to the left.
Hi Techbuilder,

search Google:
IS471FE
Find this (second hit):
http://document.sharpsma.com/files/Light_Detecting_Device-opic_AN.pdf
On this Sharp application note:
Light Detecting Device-opic
Search for:
IS471FE
Page 5 tells us:
the parameters of the IS471FE
Page 24 shows us the internal / external hook-ups of the IS471FE
<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2326&stc=1&d=1202004439">
Mostly it looks like it will operate with 5V DC input.
It has “open collector” output.
It has a built in 10k “pull-up” resistor.

so it LOOKs like you could use a circuit like this:
<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2325&stc=1&d=1202004281">
Thanks to:
Garrett Hamilton–Smith, Raihan Khondker, and Will Norris,
School of Information Technology and Engineering, University of Ottawa
http://www.g9toengineering.com/AllSaints/infraredproximity.htm

-Adam-

Techbuilder
- 3rd February 2008, 04:38
Hi Techbuilder,

search Google:
IS471FE
Find this (second hit):
http://document.sharpsma.com/files/Light_Detecting_Device-opic_AN.pdf
On this Sharp application note:
Light Detecting Device-opic
Search for:
IS471FE
Page 5 tells us:
the parameters of the IS471FE
Page 24 shows us the internal / external hook-ups of the IS471FE
<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2326&stc=1&d=1202004439">
Mostly it looks like it will operate with 5V DC input.
It has “open collector” output.
It has a built in 10k “pull-up” resistor.

so it LOOKs like you could use a circuit like this:
<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2325&stc=1&d=1202004281">
Thanks to:
Garrett Hamilton–Smith, Raihan Khondker, and Will Norris,
School of Information Technology and Engineering, University of Ottawa
http://www.g9toengineering.com/AllSaints/infraredproximity.htm

-Adam-

Thanks, would it be hard to compile a code to detect using this method?

Pic_User
- 3rd February 2008, 04:48
Hi Techbuilder,

You could consider the module like a push button. Your program would need to watch for a low or 0 (zero) to know someone / some thing had come close to the sensor module.

-Adam-

Techbuilder
- 3rd February 2008, 04:59
Ohh ok

I get it

So if I want to change the range to about 6 inches would that be done by changing the resistance to the IR leds?

Pic_User
- 3rd February 2008, 05:07
That web page said "approximately 15cm". I had to use an on-line calculator because I am an old phart, and it said almost 6 inches (5.9").

Techbuilder
- 3rd February 2008, 05:15
Cool

thanks I appreciate it

and I appreciate everyone else helping me

Well I am going to order that Sharp IS471FE and then write a program
well try and then post my progress.

Thanks everyone

:)

Pic_User
- 3rd February 2008, 05:23
Techbuilder,

How about:
You order the Sharp IS471FE and start the program right away, while you are waiting.

You can substitute a switch.

When the IS471FE gets there you can just add it.

This is actually a good way to build and test as you go.

-Adam-

Techbuilder
- 3rd February 2008, 05:33
That's a good idea


thanks Pic_User

Techbuilder
- 8th February 2008, 23:25
Something is wrong with my proximity sensor

When I was done setting up the circuit on this website my led was on constanly

http://www.g9toengineering.com/AllSaints/infraredproximity.htm

Here's some pictures of my bread board

Techbuilder
- 8th February 2008, 23:56
Here's the data sheet, I think the people that design the circuit got the pins wrong

http://www.alldatasheet.com/datasheet-pdf/pdf/42903/SHARP/IS471F.html

I don't know maybe you can help me out

mackrackit
- 9th February 2008, 01:58
Can not see very well from your pictures, but it looks like the cap is connected to the IR and can not tell where the LED is connected.

Make sure every thing is like it is on the last page of the data sheet.

Pic_User
- 9th February 2008, 04:07
Hi Techbuilder,

Nice job building all of that.
The layout and diode orientation is good.
Glad to see the little light blockers on the back side of the LEDs.
What type of IR diodes did you use?

It looks like the diagram on the webpage agrees with the data sheet.

Picture 3 looks like only the electrolytic capacitor is attached to pin 1 of the device.
Is there a hidden wire from device pin 1 to V+ or is it missing?

Also:
I don’t know why but, IR “Emitters” seem to have a different convention from the visible LEDs.
The shorter lead is the Anode (+) positive polarity. Not like normal LED.

-Adam-

Techbuilder
- 9th February 2008, 11:04
Why thank you :)

No there is no wire going to the positive, except that it is on the same row as pin 1
should I connect it to positive?

in his picture there was no wire going from the cap to positive.

Also when I take the IR LEDS out the Green led is still on constant

The IR LEDs are the ones that were put on the site
they are Fairchild QED234 Infrared LEDs that I purchased from digi key.

The only things that I used different was the radial electrolytic cap instead of the ceramic.
But it was still rated at 0.33uf

Pic_User
- 9th February 2008, 16:18
Why thank you :)

No there is no wire going to the positive, except that it is on the same row as pin 1
should I connect it to positive?

in his picture there was no wire going from the cap to positive.

Also when I take the IR LEDS out the Green led is still on constant

The IR LEDs are the ones that were put on the site
they are Fairchild QED234 Infrared LEDs that I purchased from digi key.

The only things that I used different was the radial electrolytic cap instead of the ceramic.
But it was still rated at 0.33uf
The capacitor substitute should be fine in this application. Just be aware of the polarity.

I agree the picture on the web page looks like there is no connection from (the junction of pin 1 and the capacitor) to 5V+.

Here are other clues to the contrary.


Garrett Hamilton–Smith, Raihan Khondker, and Will Norris
"Connect the Cathode of D1 and pin 1 of the IC to same common point to be connected to +5V."

<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2350&stc=1&d=1202573428">

Techbuilder
- 9th February 2008, 16:35
Cool I got it working!!!!

Yay now I am one step further to completing the automatic toilet flusher.

Thanks Pic_User :)

Pic_User
- 9th February 2008, 16:59
Cool I got it working!!!!

Yay now I am one step further to completing the automatic toilet flusher.

Thanks Pic_User :)Great news Techbuilder,

Can you give us your impressions of the results?
Do you get the same range as the web site 15 cm (5.9”)? Reflected..
Does the “target” surface color / shininess make a difference?
Does ambient light clobber it?
How much range if you detach the IR Emitters, put extension wires on them, and point them at the sensor (beam break)? Like across a door way...

-Adam-

Techbuilder
- 10th February 2008, 03:28
Well that's a good idea so
better yet I made a video

http://www.youtube.com/watch?v=sR0uQbD6D2E

mackrackit
- 10th February 2008, 11:35
COOL!
What was the problem before?

Techbuilder
- 10th February 2008, 18:22
Thanks, the reason it wasn't working was because pin 3 was not going to positive so for some reason the led kept being on but once I supplied the 5 volts + to pin 3
it worked.

mackrackit
- 10th February 2008, 18:30
Thanks, Good info.

Pic_User
- 10th February 2008, 18:39
Thanks, the reason it wasn't working was because pin 3 was not going to positive so for some reason the led kept being on but once I supplied the 5 volts + to pin 3 it worked. Hi Techbuilder,
Do you mean pin 3, or pin one (1) to plus (+)?
<IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2351&stc=1&d=1202668677">
-Adam-

Techbuilder
- 10th February 2008, 18:43
Yeah actually your right

it was pin 1 that I supplied the + to because pin 3 goes to ground

Sorry my mistake

Techbuilder
- 10th February 2008, 20:21
IRLED1 var PORTB.0
Servo var PORTB.1

TRISB=%00000001

Loop:
If IRLED1 =1 then
Pulsout 0,130
pause 10
pulsout 0,150
else
pulsout 0,150
endif
Goto Loop

End


This is the code I made do you think this might work?

Basically I want it to read the input and if the proximity sensor is activated then have it move the servo all the way to the right or left.

To find the center of the servo
I knew that dead center was 1.5ms and since I am using a 4mhz crystal the time interval of PULSOUT is in units of 10 us.

So I used this equation to find my pulse
1.5ms = 1500us
and then 1500/10= 150

and clockwise is 1.3ms so I did the same equation for that

mackrackit
- 11th February 2008, 00:33
Can not comment about the servo, I do not know which one you are using.

In your code

Change
Pulsout 0,130

to

Pulsout Servo,130

Use either the full pin name ( PORTB.0 ) or the var assigned to it. Works much better I think.

Techbuilder
- 11th February 2008, 08:16
But would it work if I corrected that?

skimask
- 11th February 2008, 08:47
But would it work if I corrected that?

If you don't have

include "bs1defs.bas"

or

include "bs2defs.bas"

in your program, it could very well fix it.
(Ref: Section 4.11, page 28-29 of the PBP manual)

Techbuilder
- 12th February 2008, 14:03
Here's the final bread board

Maybe I am missing something I don't know
maybe you can point it out.

I used a 16F627A

Pic_User
- 12th February 2008, 15:38
Here's the final bread board

Maybe I am missing something I don't know
maybe you can point it out.

I used a 16F627A

Looks good.
I didn’t check the PIC pin-out, expect you did that.
Looks like a 4.7k (4k7) resistor to +, on a pin probability MCLR = good.
Should work.
But:
You should have a ceramic or low inductance capacitor, right close to the PIC, between power pins. About ~ 0.1 microfarads.

I always put an electrolytic capacitor on the +/- “rail” (power) where it comes onto the solder-less bread board. About ~ 100 microfarads.
It would not hurt to put another electrolytic capacitor on the same power pins as the previous ceramic. About ~ 10 to 100 microfarads. Yes all the capacitors are in parallel which seems strange to beginners. You will get the idea as you start to learn about faster circuit dynamics…

Also, I like to hang an LED with a current limit resistor on the power rail. This helps us avoid “dumb time”, when the power is off and the green trigger LED will not come on no matter how many things we try. :)
Disclaimer: This is something I have heard about. I have NEVER had this happen to me. :o
-Adam-

Techbuilder
- 12th February 2008, 17:49
Thanks but it didn't work :(
When I programmed the chip and put it on there nothing happened
Was it because of my trisb?

Or is it because of how I connected my Sharp IC to my micro controller?

Pic_User
- 12th February 2008, 18:44
Thanks but it didn't work :(
When I programmed the chip and put it on there nothing happened
Was it because of my trisb?

Or is it because of how I connected my Sharp IC to my micro controller?Techbuilder,

We need to see your circuit drawn as a schematic (schematic = 1000 words or 10 pictures)

First you should try to find out if you have a hardware or software problem.

Software = Fix code
Hardware = Fix hardware

Hardware:
You need to test each portion of your circuit as a module.

Disconnect the wire between the proximity detector and the PIC input pin.

Run the PIC with a push button input.
Put a 10k resistor from plus (+) to the input pin, connect a switch (or wire you can “make and break”) from the same pin to ground.
This simulates the proximity detector.
When you momentarily connect that input pin to ground, does your servo work?

Yes = Problem with the proximity detector or input connection.
No = Problem with the PIC code, PIC circuit or servo.

To just ask without some sort out of problems puts the burden on the person not needing the help. :)

-Adam-

Techbuilder
- 12th February 2008, 19:59
Ok, Well here is the schematic.....


There is a possibility it is the servo but I changed the software to turn on a LED when the proximity sensor is active and nothing.

So it's either the circuit or the software
but take a look at the schematic down bellow
to see if I might of forgot something crucial.

My guess is that it is the program, but it might be the interface from the sensor to the pic

gebillpap
- 12th February 2008, 21:46
Maybe this can work better in case it is only code problem
Loop:
If IRLED1 =1 then
for a=1 to 100 'allow several pulses for the servo to reach the requested position
Pulsout 0,140 'could be 100=1ms to 200=2ms
pause 10
next a
else
pulsout 0,150 '150=1,5ms middle position
pause 10
endif
Goto Loop



Also check your servo if it is damaged since you power it with 9V instead of the usual 5V most RC servos work.

Bill

Techbuilder
- 12th February 2008, 22:31
Thanks

I appreciate it :)

Although the servo was modified along time ago for continuous rotation,
Although it still works

5volts is actually low for a servo, that's the lowest amount of voltage you can imply.
In the book I own PIC basic projects
it has a servo page and it states that servos can run from 5vdc to 9vdc and 5volts was not recommended.

I tested it out and it works fine

I believe for it to be the sensor

mackrackit
- 13th February 2008, 00:17
Post the code you are currently trying.

Write the code to make a pin high or low output. No pulses for testing and use an LED instead of the servo.

What is the voltage at the sensor out put when connected to the PIC?

Techbuilder
- 13th February 2008, 01:15
Doesn't RBO and RB1 and so fourth supply 5+ to the pin?

skimask
- 13th February 2008, 01:19
Doesn't RBO and RB1 and so fourth supply 5+ to the pin?

Yep, at roughly 25mA per pin, at MOST! Try to draw any more than that, and you'll end with a pin that won't supply squat.

mackrackit
- 13th February 2008, 02:44
Doesn't RBO and RB1 and so fourth supply 5+ to the pin?

In your case RB0 is an input so it is looking for 0 volts to 1.2 volts for a LOW and 3.6 volts to 5 for HIGH. It is best to use a pull up or pull down resistor so the pin will be 0 or 5 and not floating around. Another part or two but I like using external pulls and not rely on the internals.

So, when the sensor is sending its high signal to the PIC and connected to the PIC, what is the voltage.

Try making the pin high or low with out the sensor.

Techbuilder
- 13th February 2008, 04:58
Ok so I tried it with an led and it was working so I am guessing it is the servo
the potentiometer must be broken in the servo

When I get the new servo in the mail I will try it out

thanks everyone

by the way once everything works I will put up a "How to" for this automatic toilet flusher
once I am done.

Just in case anyone else wants to build it

mackrackit
- 13th February 2008, 06:09
Glad you found the problem!

Just curios, what servo are you using?

Techbuilder
- 13th February 2008, 09:43
Well I still don't know if it is the servo
because when I compiled and programed it
the led was supposed to stay on and the other was supposed to be low
unless it made contact, then the other led that was low now becomes high and the other led that was high before now becomes low.

Here is the code



LEDSW var PORTB.0
LED1 var PORTB.1
LED2 var PORTB.2

TRISB=%00000001

Loop:
If LEDSW=1 then
High LED1
LOW LED2
else
LOW LED1
HIGH LED2
endif
Goto Loop

End

mackrackit
- 13th February 2008, 10:29
And....what happens. Does anything light up? Did you try LEDSW HIGH by running a jumper to the +5 bus?

Might help to know the voltage output of the sensor. Possible it needs conditioned before the PIC. Even it the voltage is correct the current may not be high enough to over come the pull down resistor.

Techbuilder
- 13th February 2008, 10:34
One LED stays on until the sensor makes contact
but the other one does nothing.

mackrackit
- 13th February 2008, 10:53
One LED works as expected. The sensor and PIC work together. The code looks OK.

Are you by chance missing an IR LED? Maybe that is the one not lighting, or on the wrong pin?

gebillpap
- 13th February 2008, 15:02
Perhaps Portb.1 is damaged(from 9V??? through the servo???) if only LED2 works as expected.
Test by replacing LED1 with LED2 and vice versa in your program.
Or try to move LED1 to another pin e.g. portb.5 just in case portb.1 is not correctly configured(depends on PIC as some pins do other things as well).
Remember to change the TRIS register also.
Bill

Techbuilder
- 13th February 2008, 19:31
Perhaps Portb.1 is damaged(from 9V??? through the servo???) if only LED2 works as expected.
Test by replacing LED1 with LED2 and vice versa in your program.
Or try to move LED1 to another pin e.g. portb.5 just in case portb.1 is not correctly configured(depends on PIC as some pins do other things as well).
Remember to change the TRIS register also.
Bill



Portb doesn't see 9 volts if you took a look at my schematic it has a separate power supply.
The potentiometer is what connects to the pic from the servo.


One LED works as expected. The sensor and PIC work together. The code looks OK.

Are you by chance missing an IR LED? Maybe that is the one not lighting, or on the wrong pin?


No everything is there and facing right

mackrackit
- 14th February 2008, 07:02
The only thing I can say to try now is a different pin for the LED that is not working (or a different chip ) you could have a bad one.

Sorry I can not be of more help.

Techbuilder
- 14th February 2008, 16:24
No it's not your fault

I will try with just a regular switch and then see what happens

What resistor should I use for connecting a switch to a pin?

mackrackit
- 14th February 2008, 16:40
I use a 10K normally. Higher - more resistance- is fine if you do not have a 10K.
The PBP manual under the BUTTON command has a schematic.

Techbuilder
- 14th February 2008, 20:47
Cool thanks
:)

mackrackit
- 21st February 2008, 03:21
Techbuilder

I saw this and thought about your project.
https://www.gettoilettunes.com/?gclid=CLvajN2n1JECFREcagod0iI2bQ
A few modifications and...well they would have to be trained to put the lid down.

Techbuilder
- 22nd February 2008, 01:38
Sorry guys I haven't put any information up
I got ripped off by this online company

http://www.e-clec-tech.com

Never got the servos and they were way over priced

but it was a lesson learned.

I had to re order the servos but this time it is from amazon so this time I should receive my item.

Also I have the flu and I have been in bed for a week
it sucks but I will get better.

As for the cap

It is connected to pin 1 and 3 of the IR IC which is in the schematic

Techbuilder
- 22nd February 2008, 22:08
I got it to work!!!!!!!!!

Although I got to adjust the ms because it only moves like 3mm but it should be done soon!


Ps I found out what was wrong

The servo was not connected right to the pic
I had the postive going to the pic pin and the signal was going to positive
I got the new servo in and now all I have todo is make some adjustments in the software

So you will here from me soon

Techbuilder
- 27th February 2008, 12:16
Can't figure out the delay for the servo

Here's my program




IRLED1 var PORTB.0
Servo var PORTB.1

TRISB=%00000001
Loop:
If IRLED1 =1 then
Pulsout Servo,110
pause 10
Pulsout Servo,150
else
Pulsout Servo,110
endif
Goto Loop

End


I Want it to move the servo to the right to it's most and delay for two seconds and
then come back to center.

If anyone can help me out
it would be much appreciated

Bruce
- 27th February 2008, 17:22
Does this work?



x var byte
IRLED1 var PORTB.0
Servo var PORTB.1

PORTB = 0 ' setup for high-going pulsout
TRISB=%00000001

Loop:
If IRLED1 = 1 then
goto Flush ' flush
else ' else center
for x = 1 to 20
pulsout Servo,150
pause 20
next x
endif
goto Loop

Flush:
for x = 1 to 20
Pulsout Servo,200
pause 20
next x
pause 2000
Goto Loop

Techbuilder
- 28th February 2008, 04:43
Thanks for the code bruce
I appreciate it

Although it didn't work
instead of not moving enough like my code
this code twitches every two seconds unless it makes contact which it just go's to center
and the twitches are just a little more then mine was at last time

Luciano
- 28th February 2008, 08:13
Hi,

(A long-lasting project).

Your room mates will very soon say:
OK, we will flush the toilet but you turn off the light at night so we can sleep!

Seriously, what they think about your efforts?

Best regards,

Luciano

sayzer
- 28th February 2008, 09:43
Hi,

(A long-lasting project).

Your room mates will very soon say:
OK, we will flush the toilet but you turn off the light at night so we can sleep!

Seriously, what they think about your efforts?

Best regards,

Luciano


Luciano,

I think they will soon say, "let us help you with your Automatic Toilet Flusher Project".



:) :)

Techbuilder
- 28th February 2008, 10:00
lol well I have a sleeping disorder so they are used to me up

I just want this thing to work.

:(

I will get it though

Bruce
- 28th February 2008, 12:21
Funny that should work. Here's a few things to check.

Make sure you're using a separate power supply for your servo, and you have a common ground between them. Running a servo from your controller power supply can cause problems if you aren't using a hefty bench type power supply with a lot of filtering to remove motor noise.

Make sure you're using the correct voltage for your servo. These normally run on 4.8 to 6V. If you're trying to operate your servo from 9V that may be a problem. Most hobby type servos can't handle 9V, and a 5V control pulse from the PIC is going to look pretty weak to a servo operating at 9V.

I tested the above code example, and it works as expected with a Hitec HS311 servo operating at 5V with a 16F627. Note some servos will move 90 degrees right or left, so you can tweak the value in the Flush routine between 200 to 250 to extend the rotation range.

My HS311 moves full right with 250, and centers with 150.

Techbuilder
- 28th February 2008, 12:49
Funny that should work. Here's a few things to check.

Make sure you're using a separate power supply for your servo, and you have a common ground between them. Running a servo from your controller power supply can cause problems if you aren't using a hefty bench type power supply with a lot of filtering to remove motor noise.



Yep I am using a separate power supply for both and each is filtered



Make sure you're using the correct voltage for your servo. These normally run on 4.8 to 6V. If you're trying to operate your servo from 9V that may be a problem. Most hobby type servos can't handle 9V, and a 5V control pulse from the PIC is going to look pretty weak to a servo operating at 9V.


Yep I used 5volts and I even tried it with 6





I tested the above code example, and it works as expected with a Hitec HS311 servo operating at 5V with a 16F627. Note some servos will move 90 degrees right or left, so you can tweak the value in the Flush routine between 200 to 250 to extend the rotation range.

My HS311 moves full right with 250, and centers with 150.



I am using a hi-tec HS-322HD

And I used another servo which was a futaba S3003
but it was modified for continues rotation but it was rotating in 90% degree section
but that was when it was not in contact but when it was in contact it didn't move just like the hs-322HD

mackrackit
- 28th February 2008, 12:53
but that was when it was not in contact but when it was in contact it didn't move just like the hs-322HD
You mean in contact with the handle? If so, maybe the servo is not strong enough?

Techbuilder
- 28th February 2008, 13:01
You mean in contact with the handle? If so, maybe the servo is not strong enough?

No contact with the IR led


Although I figured out that I have to modify the servo to do 180 degrees
because mine only does 60 degrees, still doesn't explain why it is only going off when it is not in contact with the IR led.

Techbuilder
- 29th February 2008, 08:04
Actually if I spin it by hand it spins enough
so I don't believe that's the problem.

Techbuilder
- 1st March 2008, 21:54
It is not connected
the only thing that it is connected is to the IR receiver which it needs to be

JohnnyV
- 20th May 2008, 00:14
Hey everyone, I've been working on a very similar project (also my first PIC only project), before I even discovered this thread. I'm having a problem getting my servo to move 90 degrees. I'm using a parallax standard servo (left over from my Basic Stamp days), which is based on a futabu (http://www.parallax.com/dl/docs/prod/motors/stdservo.pdf).

I tried using the code that Bruce posted, but the servo only moves about 10 degrees each time the move loop is called. I also tried using a modified version of the BS2 code in the pdf I linked, but I get the same result. How can I get my servo to move the full 90 degrees?

Here is the code I'm using:


@ __config _INTOSC_OSC_NOCLKOUT &_WDT_ON &_PWRTE_ON &_MCLRE_OFF &_BODEN_ON &_CP_OFF &_DATA_CP_OFF &_MCLRE_OFF


servo1 var Porta.0
x var byte

low servo1
HIGH PORTB.3

loop: pause 500
low portb.3
pause 500
high portb.3
GOTO move
pause 2000
low portb.3
GOTO loop

move: for x = 200 to 1200
pulsout servo1,x
pause 18
next x
pause 2000
return


I have the LED blink so I can be sure that I know the program is working properly and I can tell when the servo should be moving.

Thanks for the help in advance!

BTW, I'm making the project because I have a cat that is toilet trained, not because room mates don't flush :p

skimask
- 20th May 2008, 03:29
And the PIC you are using is ______________________(fill in the blank).
Kinda handy to have that sort of info, dontcha think?

Servo pulse width is GENERALLY centered around 1.5ms...which means that there's probably something wrong here:


move: for x = 200 to 1200

JohnnyV
- 20th May 2008, 12:03
I'm using a 16F627A

and yes, I've tried changing those numbers and I've tried using the numbers that Bruce posted, but I still get the same result regardless. I've also tried using a different servo (another parallax one)

skimask
- 20th May 2008, 13:42
I'm using a 16F627A
and yes, I've tried changing those numbers and I've tried using the numbers that Bruce posted, but I still get the same result regardless. I've also tried using a different servo (another parallax one)

So, you're running at 4Mhz (INTOSC). The PBP manual tells us that at 4Mhz, pulsout has a granularity of 10us. Your loop runs from 200 to 1200, meaning 2000us (2ms) to 1200 (12ms). A bit out of the range of a normal servo ya think? Unless you've got one of the oddball ones...

Also, try turning off the WDT and Brown-Out reset for grins... You might be killing the battery voltage when the servo tries to move and causing a reset.

Bruce
- 20th May 2008, 16:15
Use GOSUB VS GOTO if the routine you're going to uses RETURN to get back.

Disable onboard comparators with CMCON=7 before trying to use a pin that
has the comparator feature.

Give this a shot;


@ __config _INTOSC_OSC_NOCLKOUT &_WDT_ON &_PWRTE_ON &_MCLRE_OFF &_BODEN_ON &_CP_OFF &_DATA_CP_OFF &_MCLRE_OFF


servo1 var Porta.0
x var byte
CMCON=7 ' <-- disable analog comparators

low servo1
HIGH PORTB.3

loop:
pause 500
low portb.3
pause 500
high portb.3
GOSUB move ' <-- use GOSUB VS GOTO
pause 2000
low portb.3
GOTO loop

move:
for x = 200 to 100 STEP -1 ' 2mS to 1mS pulse
pulsout servo1,x
pause 18
next x
pause 2000

for x = 100 to 200 ' 1mS to 2mS pulse
pulsout servo1,x
pause 18
next x
pause 2000
return

END
This should cycle your servo from one side to the other. Tested with a
Parallax servo.

JohnnyV
- 20th May 2008, 23:17
Bruce, works beautifully, thank you!