# Using a 556 to control RC servo speed

#### MikeK

Joined Apr 1, 2016
34
Your suggestions worked out fine, thanks. Yes, I noticed that one led had been left hanging high, put a low command on a next line, that fixed that.
After downloading the commands that looked good, I tested the board at the track, no noise problems, that's a big one. I installed the PTs into the track, and even the one 3 ft up the track worked, no complaints. Sometimes that PT doesn't trip, but it may be because there are two overhead lights there, and the loco can't block them. I'll continue to check that, I'll take out one lite.
Sometimes the servo wanders, a minor glitch. The instructions say don't leave a serial pin unconnected, so I tied the ones from the 8 to the 14. Any better ideas?
The last thing is to put in the lines to power the recorder. I've decided to use one with a nice bell, and a horn in the background, blaring away. That should do.

#### bertz

Joined Nov 11, 2013
327
The instructions say don't leave a serial pin unconnected, so I tied the ones from the 8 to the 14. Any better ideas?
I'm not sure what you're trying to do here, but the serial in pin on both the 14M2 and the 08M2 is pin #2. If you don't have the programming circuit permanently installed on your board, then this pin should be tied to ground via a 10k resistor. I've gotten away without doing this on some of my projects but servos and motors can be problematic, so it's best to tie this pin to ground. My bad for not bringing it up sooner.

Sometimes the servo wanders, a minor glitch.
I'm not so sure what you mean by "wanders". This could be the dreaded servo jitter, in which case it's not such a minor glitch. Back in post #60 I stated that for a "typical" servo the signal pulse is between 0.75 and 2.25 milliseconds. However, I went and looked up the spec sheet for the Tower Pro SG90 and low and behold, we see that the pulse range is from 1.00 to 2.00 milliseconds. That means you will have to go in and modify the program so that the range stays between 100 and 200. More specifically, change the 80 to 125 and change the 150 to 175. This will keep it in the middle of the operating range and hopefully stabilize it. Also, if you have some spare servos see if it "wanders" on all of them or just this one. Sometimes you get a servo with a noisy pot and it will jitterbug all over the place.

The last thing is to put in the lines to power the recorder. I've decided to use one with a nice bell, and a horn in the background, blaring away.
I've used these sound cards to play three different sound effects on a robotics project I recently worked on. I have some thoughts on modifying these sound cards for use with the Picaxe, but let's get this servo issue sorted out first. You don't want your crossing gate jumping around when it's supposed to be at rest.

#### MikeK

Joined Apr 1, 2016
34
[/URL][/IMG] I'll try to put a video here, to show the system working. You can just barely hear the sound recording, but all is working well.
[/URL][/IMG]
I don't think the download went well...I'll try a different photo site.

Last edited:

#### ScottWang

Joined Aug 23, 2012
6,873
You could upload the video files on youtube and make a links to the forum or using the media(film symbol) function to do the links, if you want to upload the video file to the forum, there is a file size limits as 10MB and compress the file to *.zip and click "Upload a File" to upload it.

#### MikeK

Joined Apr 1, 2016
34
Very strange. I have uploaded files before, and think it will still upload pics, but this 3GP video won't. Also, I can not find the 'manage attachments' button, wonder if is is connected to my password problems, maybe I'm not actually 'logged on'.
PS the video is only half a meg.

#### ScottWang

Joined Aug 23, 2012
6,873
Our system of forum didn't support the *.3gp file, you could compress the *.3gp file to *.zip and upload it.
There is no manage attachments' button, we only have the "Upload a File" button and it is at the right side of the "Post Reply" button.

#### bertz

Joined Nov 11, 2013
327
[/URL][/IMG] I'll try to put a video here, to show the system working. You can just barely hear the sound recording, but all is working well.
[/URL][/IMG]
I don't think the download went well...I'll try a different photo site.
Nicely done, Mike. Congrats!
You might consider one of these and a better speaker to boost the volume from your sound card.

Last edited:

#### MikeK

Joined Apr 1, 2016
34
Before I create the printed circuit board, I want to have the command for the recorder. I was using the pin B.2 which you had an LED on. It sort of works, but I want the recorder on it's own pin. 3 and 12 seem to be the only ones left. I think a simple 'go high' and 'go low' after the sensor is tripped and right before the end is all that is needed, right? I may try it for experience, I have saved the commands that work.
Were you able to see the video? I can e-mail it to you. I may have to find another camera to record in a different format.

#### bertz

Joined Nov 11, 2013
327
Before I create the printed circuit board, I want to have the command for the recorder. I was using the pin B.2 which you had an LED on. It sort of works, but I want the recorder on it's own pin. 3 and 12 seem to be the only ones left. I think a simple 'go high' and 'go low' after the sensor is tripped and right before the end is all that is needed, right? I may try it for experience, I have saved the commands that work.
Were you able to see the video? I can e-mail it to you. I may have to find another camera to record in a different format.
Hi Mike, I'm delighted that this project is working out well for you. Unfortunately the video files never uploaded successfully so I was unable to view the result of your efforts.

I've attached a revised schematic showing the sound card connected to the 08M2 which is where you want it to go. Now I'm assuming that the sound card you are using is a variant of the ones I've been using since you mentioned in an earlier post you got yours from the same vendor. I modified my cards so that I could power them from the 5 volts on the board and carry a common ground. See the attached photo.

From my experience based on the sound cards I've been using, all that is required to trigger the sound card is a brief pulse, since we are emulating a pushbutton. I removed the pushbutton and connected the signal lead directly to the Picaxe output pin. You must carry a common ground for this to work.

#### bertz

Joined Nov 11, 2013
327
I think a simple 'go high' and 'go low' after the sensor is tripped and right before the end is all that is needed, right? I may try it for experience, I have saved the commands that work.
The code you want to modify is the 08M2 program. This should do it for you:
Code:
'******************RR Crossing Gate2.0.bas****************
'Version 2.0
'AJZ/May 9, 2016
'this code is used to drive a servo operated crossing gate
'based on a digital input signal
'added an output for an MP3 sound card

'====Input=======
symbol trigger = pinC.1        'signal to raise & lower the gate

'===Outputs===
symbol gate_Servo  = C.2    'PWM out to servo
symbol noise = C.4            'output to sound card

'===Variables===
symbol pos0 = b0

'===Constants====
symbol abit = 500            'delay-wait for last car
symbol rate_Servo = 5        'sets servo speed

'===Directives===
#com 3                'specify serial port
#picaxe 08M2            'specify processor
servo gate_Servo, 150        'initialize servo in raised position

main:
do
if trigger = 1 then        'train detected
exit
end if
loop while trigger = 0
gosub activate
goto main

activate:
high noise                    'activates MP3
pause abit                    '500 ms pulse
low noise                    'end pulse
for pos0 = 150 to 80 step -1         'lower the gate
servopos gate_Servo, pos0
pause rate_servo            'sets the lower speed
next pos0
do
if trigger = 0 then        'train clears the sensor
exit
end if
loop while trigger = 1
pause abit                    'pause to let the last car clear
for pos0 = 80 to 150             'raise the gate
servopos gate_Servo,pos0
pause rate_Servo            'sets the raise speed
next pos0
return

#### MikeK

Joined Apr 1, 2016
34
I'll work on the sound shortly, it will be good practice. Meanwhile, I checked the Express PCB site, found their prices way too high for me. I'll look into other ways to get pc boards. I can always use my proto-boards, but it's a very slow process creating a board.

#### MikeK

Joined Apr 1, 2016
34
Building my proto board, will find a pc board maker eventually with good prices. Anyway, with two Picaxes on the one board, they don't want to share the programming input..can that be done, so both chips could be re-programmed (separately, of course) in the future, on the board?

#### bertz

Joined Nov 11, 2013
327
Building my proto board, will find a pc board maker eventually with good prices. Anyway, with two Picaxes on the one board, they don't want to share the programming input..can that be done, so both chips could be re-programmed (separately, of course) in the future, on the board?
It can be done but you'll have to add a 4-pole DIP switch to your board.

#### MikeK

Joined Apr 1, 2016
34
Yeah, that's what I thought. Actually, there is no importance for the board to have programming capabilities, the chips can be programmed on other boards. That would make this one simpler.
How necessary is a socket? Once the chip is programmed, that should be it??? Could something happen to necessitate re-programming the chip? On the other hand, how troublesome are the cheap sockets?
I found this site https://www.itead.cc/open-pcb/small-batches-pcb/small-batches-2-layer-pcb.html for pc boards, from China. Their prices are better than others. Looks like I would have to acquire and learn Gerber files. Is that difficult? Expensive?
After you make a pc board, is there some sealer to protect it from moisture/corrosion? Would Future clear acrylic work? It's sold as floor sealer, but I use if for a final coat on my trains and buildings and such. It's clear acrylic paint, apparently.
You haven't asked about my avatar. Being a flying modeler, you might appreciate that it's an airship. Not light enough to fly, just testing construction procedures. It proved my theory that plastic in the right shape will hold up it's own weight. A little bigger, and it would fly RC control. A little bigger than a Greyhound bus, and it would lift one person. Mike

#### bertz

Joined Nov 11, 2013
327
How necessary is a socket? Once the chip is programmed, that should be it??? Could something happen to necessitate re-programming the chip? On the other hand, how troublesome are the cheap sockets?
Lots of things could happen relating to model railroading that would require re-programming your chips. Some examples: adding another crossing gate; more flashing signals; track signals; a signalman popping out of his shanty. You get the idea. My experience is that a model railroad is a dynamic thing, not build it and forget it. How boring is that?
As far as soldering the chips directly to the board, forget it. Even using cheap sockets is better than that. There is no issue with being troublesome. So go ahead and plan on using sockets for your chips. Don't create an issue where there is none.
Whether you want to add programming capabilities to your board is strictly up to you. I've done it both ways. The downside to removing the chips to program off-line is you risk damaging the chip mechanically or zapping it with a static electricity discharge.
Looks like I would have to acquire and learn Gerber files. Is that difficult? Expensive?
You don't acquire Gerber files. Gerber files are generated by the PCB software you choose to create your boards. There are other threads in this Forum which discuss the pros and cons of the various types of PCB software (e.g. Eagle). Since I etch my own boards, I have been perfectly satisfied with Express PCB. I tried Eagle, but the learning curve was too steep or I was too stupid. Either way, I really wasn't interested.
And one more thing, you cannot convert Express PCB files directly to Gerber files.
After you make a pc board, is there some sealer to protect it from moisture/corrosion? Would Future clear acrylic work? It's sold as floor sealer, but I use if for a final coat on my trains and buildings and such. It's clear acrylic paint, apparently.
I have no idea what Future is. But I have never coated any of my boards and it has never been a issue. With that having been said, I can't see that there would be any harm in it.