# BASIC Stamp Project

#### DRock

Joined May 7, 2011
68
Hey everyone,

I am a recent Mechanical Engineer grad and I am now trying to learn more about the electronic aspect of things. It is no secret that most of the new technology coming out is being pushed by electronics and not so much the mechanical aspect.

I bought the Parallax "What's a Microcontroller?" kit which comes with the BS2 and an educational PCB setup with a little breadboard. I have a moderate understanding of programming and electronics and how they work but I don't know many of the devices or how you can use them together to perform a specific function.

I have a couple projects that I am looking to tackle and plan on using this as a test bed for my prototypes. The first one I am trying to use the BS2 microcontroller to detect when a mercury switch completes the circuit and then display either through a numbered LED or an LCD screen which one of the switches tripped.

I am trying to set it up so that I can have anywhere from 5-7 possible switches 50 yards or so away from the main base that will transmit a signal to the base when the circuit is completed.

Basically each mercury switch is going to be used to make a sensor to detect when a component is tilted and when the circuit completes it will transmit the signal to the base and the base will display which one tripped. The problem I am having is I have no idea how to do this with a wireless setup and I have no idea how I am going to build the sensor.

I am hoping some of you more knowledgeable people can offer me some insight as to how I can accomplish this in the most cost effective manner.

I believe each sensor will need its own TX chip, batteries, and mercury switch but will the base need a separate RX chip for each unit or can I use a single one? I have been scouring Google for help but I cannot find any useful info concerning the building and wiring of the sensor.

Thanks in advance for any help!

#### ErnieM

Joined Apr 24, 2011
8,153
Hey I got that same kit a bunch of years ago, it has some nice projects to describe the basics of a lot of micro controller applications. AFAIK the largest hole in it is the lack of an analog to digital converter on the Stamp so you never get to do anything with that. I would still recommend it without reservation.

I believe the Stamp has an RS232 interface that is capable of communications over the distances you want. So you have several remote switches you want to tie into a mother ship. As defined, the RS232 is intended for communications between two devices, you cannot just connect a large number together.

That doesn't quite mean you need a pair of Stamps for each switch (plus 1 to combine all the readings), but you would need to add some sort of switch to connect each remote switch to the local RS232.

That said, making an RS232 link just to send 1 bit of information (switch on or off) sounds like some serious overkill. I would look at just using the switch and some wires for each remote sensor, then perhaps some protection circuitry on the Stamp end. But just basically 2 wires from the Stamp to each Switch.

#### DRock

Joined May 7, 2011
68
It is quite an awesome little kit and it has really taught me a lot so far as to how all this stuff works. I need to keep the costs down so using several microcontrollers would be out of the question.

What other method would you recommend so I can transmit the on/off signal? Like I said I am new to the device aspect and if using a RS232 is overkill then I would definitely like to change my design to incorporate something easier and cheaper.

Is there a way I could do this without the use of a microcontroller? I originally bought the kit to use with my other project but I thought that I could work it into this one but it seems it might be overkill like you said.

#### elec_mech

Joined Nov 12, 2008
1,500
DRock,

Always good to see another ME go to the Dark Side.

First question is can you physically link (wire) these sensors together so that they can all share the same transmitter? If yes, you can go with something like these:

http://www.sparkfun.com/products/8945

http://www.sparkfun.com/products/10533

If not, you'll need dedicated transmitters sending unique IDs to a single receiver. I think Zigbee modules do this, but you're looking at over $23 a module (quick search). This is$20 a pop and may work at a glance:

http://www.sparkfun.com/products/10665

I'm sure others can offer more sites to check out for RF gear.

Whoops, typed too soon, $19 apiece: http://www.parallax.com/Store/Acces...ageindex/2/Level/a/ProductID/639/Default.aspx These should do what you want without too high a learning curve. Thread Starter #### DRock Joined May 7, 2011 68 Ok so it seems like it would cost too much money for each sensor to have its own transmitter with unique ID. I do have a backup plan though and that is sending a signal to the receiver saying that ANY of the switches could have tripped, and then it just requires a physical inspection up close to see which one it was. I want to maintain the wireless aspect because of mobility reasons, but now I am not sure I even need to use a microcontroller after switching to Plan B. The new method would have a receiver base, with an audio alarm and LED light that will go off when any of the mercury switches are tripped. That would probably bring the total cost per sensor down to around$10-$15 as opposed to$40-$50. Now using this new plan couldn't I just use the same transmitter with the same ID for every sensor, such as the first one you linked? Thank you very much for the reply! Thread Starter #### DRock Joined May 7, 2011 68 I have attached a rough MSPaint sketch of how I would like the system to work. The thin lines represent the wireless connection to the base, which ideally you could wear around as a beeper type device. Basically, as I previously stated, the new design will give an auditory and LED indication that any of the sensors have tripped and the person can then walk over to see which one it was. Ideally, this system could work in conjunction with another similar system within the same communication range without getting the sensors mixed up. I will cross that bridge when I come to it but I am fearing this added complexity level may not be in the budget for my project. I hope this may clear up any questions still remaining. Thanks! #### Attachments • 14.3 KB Views: 22 #### ErnieM Joined Apr 24, 2011 8,153 Arggg... wireless. I missed that. I havn't done much with wireless stuff but if I were I would look into wireless products over at Sparkfun. You can get a transmitter/receiver pair for under$10, and as they have 2 different frequency options you can have 1 frequency go master->(all slaves) and tell which slave to update, other frequency used by each slave in turn to go (1 slave)->master.

Would be overkill to put Stamps out there as it could be done with a less costly PIC, software is near trivial but you would need the hardware programmer, which is about the cost of 1 Stamp.

Anyway, it's your project, I'm just tossing out ideas.

#### elec_mech

Joined Nov 12, 2008
1,500
DRock,

Okay, I pontificated last night and this morning and think I have a cost-effective solution.

First, I forgot to fully hash out the wireless options I mentioned previously. Those are modems and send serial data wirelessly. This means you need a microcontroller on both the transmitting and receiving side. Obviously, BS2 are pricey, but you could go with a PICAXE which only runs a few bucks a chip and provides free BASIC software, if I'm not mistaken. So, you'd be looking at $8-10 per transmitter (~$4 for PICAXE and ~$4 for the transmitter), then another$5 for the receiver and of course the Stamp (or a PICAXE).

However, if you want to forgo microcontrollers you can use a $10 RC car for each sensor. I used one recently to allow me to make four buttons wireless for a large two-digit display. If you get an RC car with four true switches - up/down and left/right - you can use it for up to 8 sensors. The receiver is connected to a drive motor and a steering motor. These are controlled with H-bridges, so when you press UP, the drive motor, having two contacts, sends a high (+) signal to one contact and a low (ground, 0V) to the other. When yoy press DOWN, the signals reverse. This means you do not want to effectively press UP and DOWN together (can't do this on the remote because it is a single switch and only allows you one position at a time), but using each remote as a sensor means you want to be careful to avoid doing this. Also, this assumes you never have more than one of your sensors tripping (sending a signal) at a time. If this is cool, you can use up to 8 RC cars, at$10 each, to get you 8 sensors. Note most RC cars (the cheap ones we're talking about) are sold with one of two frequencies, either 27MHz or 49MHz, so be sure you buy them with the same frequency. This also means you can create two independent zones of up to 8 sensors each, 16 total as you mentioned earlier.

Here is a quick chart

UP DOWN LEFT RIGHT Sensor
0 0 0 0 None - no sensor tripped
1 0 0 0 #1
0 1 0 0 #2
1 1 X X Not allowed
0 0 1 0 #3
0 0 0 1 #4
X X 1 1 Not allowed
1 0 1 0 #5
1 0 0 1 #6
0 1 0 0 #7
0 1 0 1 #8

If you want to get fancy, you can add pulses to each sensor, so 1 pulse (meaning one beep or one blink of an LED) for sensor 1, etc. To keep it simple, you can simply use AND gates or similar to decode the incoming signal and light up a specific LED to let you know which sensor is tripped.

#### DRock

Joined May 7, 2011
68
Thank you both very much for the help! I think you have provided me with all the necessary information to make some huge progress now that I finally know what direction to head in.

I didn't even think of the RC car idea, I have been playing with my expensive Traxxas and Parkzone toys for so long I forgot how cheap you can get some of those things.

I will definitely check around for a cheap car that I could potentially utilize, but I think I may end up going with the PIC because it would be a smaller overall package and it would require me to learn more about how everything works together.

I will absolutely be using the RC cars for some other projects though where space is not a huge concern.

I am going to do some more research and try to come up with a schematic/diagram and I will be sure to update this thread once I figure that out...or with any questions that may come up as I go along!

Thanks again!

#### ErnieM

Joined Apr 24, 2011
8,153
RC cars... good idea if you can get the range you need.

At one place I worked for our neighboring company needed a large supply of radio controls, and found the cheapest cost effective solution was to buy RC cars, cut out the controls, and toss the cars. I discovered this one day when I went out back and found literally hundreds of identical 1/8 scale mini Coopers in the dumpster. They had even conveniently put them all back in the boxes to move them out in bunches. All the parts including the screws were in there.

I took em home, put em back together, and gave em out to the neighborhood kids who loved em. Of course all they were was push cars, but they were still cool toys.

#### DRock

Joined May 7, 2011
68
I am going to go out right now and buy a couple RC cars to mess around with, hopefully I can get my first prototype up and running within a week or so. I am starting to think I picked the harder of my two projects to start off with haha, the other one only involves using a laser range finder to drive a servo and no wireless.

I am definitely learning a lot as I go along though, gives me something to do while trying to find a job haha!

#### elec_mech

Joined Nov 12, 2008
1,500
DRock,

Here is what I used:

http://www.newbright.com/product/view/id/53

Walmart and Target both carry similar New Bright RC cars for $10 each. I even saw a similar car, same controls, different manufacturer, in Crackle Barrel for$10 too.

#### DRock

Joined May 7, 2011
68
Just placed the order!

This stuff looks complicated, any suggestions on where to start reading up on how to use/program the PICAXE?

#### elec_mech

Joined Nov 12, 2008
1,500
I haven't used one, but I think the starter pack you've ordered will have enough to get you started. If you want to start now, check out their website:

http://www.rev-ed.co.uk/picaxe/

I know there is tons of support, similar to the BS2. You might do a search on this forum for PICAXE and see what you come up with. I know there are a few if not many people here who've used it.

I think once you get the starter pack and go through an example or two, you'll get up and running quickly since you already know the BS2. There may be a few minor differences in how things are used or called out - just refer to the program guide or equivalent for how the syntax is implemented and called out for different commands.

Just ask if you run into any snafus, there are plenty of people here to help.

#### DRock

Joined May 7, 2011
68
I have been having a lot of fun reading, programming, and building but I haven't found a lot of details on infrared.

The space I would use the system in would be wide open and I could mount an IR receiver outside so that it could accept a signal from an IR transmitter. Would this method be cheaper/easier than using the RF combo I just purchased?

Thanks!

#### elec_mech

Joined Nov 12, 2008
1,500
Hi DRock,

Yes and no and at a price. To do this, you need a transmitter and a receiver. IR LED (transmitter) are about a buck or so, so not bad. Receiver go higher, a quick look on Parallax shows $4 each, so not bad either. Now here's the rub, IR transmitters, while cheaper, are line-of-sight only. This means you have to have a direct line of sight between the transmitter and receiver. Think of TV remote - if it ain't pointed right at the sensor, you can't change the channel. Someone walk between the transmitter and receiver? No communication. If your data stream was long, you could lose it midway and have to start the transmission over. Not the case with your application of a single switch signal, but good to keep in mind. I believe the data rate would also be slower - again a non-issue in this application. This also means for multiple sensors, assuming they aren't all in the same spot, you'll need both a transmitter and receiver for each, so about$5 for each sensor you want to add. If you want to go nuts, you could probably use discrete logic like a 555 timer to send x pulses at x duty cycle from each sensor to determine which sensor was tripped, so that lowers your cost too. Then you only need a single microcontroller to interpret the data.

If you were making a motion sensor/burglar alarm or something where the receiver and transmitter stayed stationary and no obstacles between them, then I'd say go for the IR sensors.

If you're moving and the sensors are stationary, then this probably isn't the option for you. Also, IR receivers need hardware filters to help block out noise from lights and other signals which further limits their veiwing angle. The ones you ordered don't need to be line-of-sight and aren't as suspectible to noise, so if you're moving or obstacles, such as people, come between you and the sensors, there is no problem.

#### DRock

Joined May 7, 2011
68
Thank you very much, it seems that using the IR might be a better method for this project. I am a little confused why I need a receiver and transmitter in each sensor, why can't I use just a transmitter and 555 timer to send the pulse to indicate which one has tripped? I am unsure what function the receiver would perform when used with the sensor.

Also, do you think I could use a PICAXE for the receiving base module or would I have to use a more complex microcontroller like the Stamp?

Thank you very much for your replies, you have been extremely helpful!

#### ErnieM

Joined Apr 24, 2011
8,153
IR receivers are pretty cool units with a few features you should know about. They not only look for an IR signal, they look for a modulated IR signal, at a rate of 30.0, 36.0, 36.7, 37.9, 38.0, 40.0, 56.8, or 56.9 KHz, and if they see a signal at that rate they signal high, and if the don't they signal low.

So you need two 555's (a 556?) to transmit an on-off keyed signal. You could have several receivers to "look in all directions." It may be possible to mix a few transmitters at different frequencies but that at best would make 4 "channels" with the frequencies listed above.

IR Receivers are \$1.50 single piece at Digikey.

#### be80be

Joined Jul 5, 2008
2,051
I would use a picaxe one of the 8 pin type and the sony remote encoding to make a transmitter or receivers. You then can have a lot of channels. http://inklesspress.com/picaxe_projects.htm

The picaxe is a way more capable uc then the stamp.