Shop OBEX P1 Docs P2 Docs Learn Events
Running multiple sensors with BS2? — Parallax Forums

Running multiple sensors with BS2?

Shadowcasterx4ffcShadowcasterx4ffc Posts: 13
edited 2008-03-08 20:25 in BASIC Stamp
I'm having some problems with BS2 programming. I'm not entirely sure how to make multiple programs and sensors·run at the same time using a single Board of Education. I'm trying to control a fan (using a temperature sensor)·and a light bulb (using a light sensor) with an RC4 board, which is hooked up to the BoE. We're not having problems with the RC4 or BoE, it's just the coding itself.

Comments

  • UghaUgha Posts: 543
    edited 2008-03-06 17:59
    First, I'm not sure what an RC4 board is so this may not apply to you:
    The BS2 can only do one thing at a time.

    So you have to figure out a way to do everything you need to at once.

    I'm hoping your using some kind of relay or H-bridge to control your fan.
    Otherwise it could seriously damage you stamp.

    Get back to us on how your fan/lightbulb is setup.

    Is the RC4 board some kinda relay board?
  • Shadowcasterx4ffcShadowcasterx4ffc Posts: 13
    edited 2008-03-06 18:01
    Yeah, the RC4 is a relay board.

    I'm working on a greenhouse with some other guys at school, so we need to be able to run multiple sensors such as temperature, light, and moisture, so we can control sprinklers and lights.

    Thanks for the help anyway.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Eugene

    Greenhouse Project
  • UghaUgha Posts: 543
    edited 2008-03-06 18:15
    This is the basic concept you should use I guess, written in pseudo-code

    Have two bit variables... lets say its named Fan and Light

    Start:
    Check temp sensor
    if temp is too high and fan = 0 THEN turn on fan
    else if temp is too low and fan = 1 THEN turn off fan
    check light sensor
    if light sensor is dark and Light = 0, turn on light
    if light sensor is light and Light = 1, turn off light
    pause X
    goto start

    That's the basic flow I'd use... you need a loop that will do the sensor checks and execute the shutons and shutoffs
    of the relays as needed.
    The pause X is because you'll need to play with this number and see what a good pause time is. I'm afraid that if
    its too low then the fans/lights will flicker as they reach the detection threshold you set.
    Also remember that you need to have the light sensor far enough away from the bulb to not be triggered by it.

    If you need actual code, I can supply you with that, I'm just in a bit of a hurry at the moment.

    Disclaimer: I'm a newbie, taking my advice may be hazardous to your health(electronics).
  • Shadowcasterx4ffcShadowcasterx4ffc Posts: 13
    edited 2008-03-06 20:13
    Thanks. I'll see if I can get the actual code up tomorrow.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Eugene

    Greenhouse Project
  • Lee HarkerLee Harker Posts: 104
    edited 2008-03-06 20:22
    Well your view of "at the same time" and the Stamps are a bit different. It is true that the Stamp and most other processors can perform only one command at a time. Fortunately, it performs them so fast that it appears in most cases that they are happening at the same time. In your particular case, you could easily control a light and fan and read a few sensors in plenty of time to handle a greenhouse. The reason is that the temperature and other conditions will not change that much in a few milliseconds. Your readings could be·monitored once·every second and the Stamp would spend most of its time waiting for the next job to do.
  • Shadowcasterx4ffcShadowcasterx4ffc Posts: 13
    edited 2008-03-06 20:36
    Well, it's gonna be getting it's jobs to do. We have a solenoid to control the water flow, as well as the fan/light for simulated wind and light. I supposed we're also gonna have a heater, so it should have enough to do.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Eugene

    Greenhouse Project
  • UghaUgha Posts: 543
    edited 2008-03-06 21:13
    The BS2 should handle all that fairly easily.

    Do you need anything else from us?

    PS: I love your avatar image.
  • Shadowcasterx4ffcShadowcasterx4ffc Posts: 13
    edited 2008-03-06 21:27
    I'll get back to you guys tomorrow on it. I'm not the one who actually does the programming. I take care of anything outside of programming (as we haven't started building yet) such as this. I actually joined up because we're basically at a standstill with the project right now. We don't have the tub for the dirt for the greenhouse so we can't start building yet, and we have this issue that I posted here. We also need a USB serial adapter for the new laptop that we just got, and we're waiting on a crapload of new sensors from Parallax. The ones that we're using are the little tiny ones that are less than a square centimeter big.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Eugene

    Greenhouse Project
  • Shadowcasterx4ffcShadowcasterx4ffc Posts: 13
    edited 2008-03-07 22:03
    I had the coding guy try your idea, but he still can't get it right. If possible, can we have some code for this? Thanks.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Eugene
    Greenhouse Project
  • RDL2004RDL2004 Posts: 2,554
    edited 2008-03-08 11:18
    I would highly recommend that your coding guy download and read the documentation for "Process Control" and "Industrial Control" from the Stamps in Class series. They are free downloadable pdf documents and are available from this page:

    www.parallax.com/tabid/535/Default.aspx

    If you are new to microcontrollers you might want to start with "What's a Microcontroller" first.

    What you're trying to do is actually fairly easy and is something that Basic Stamps excel at.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Rick
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-03-08 17:50
    Shadowcasterx4ffc

    Do you have the Demo Code for the RC4
    If you do not here is the Demo Code

    I· would run the demo code for the RC4 first and understand how to control it
    Then run the Demo for the Temperature Sensor that you are going to use and learn how to control it
    Then run the Demo for the Light Sensor that you are going to use and learn how to control it

    Once you have learn·how to control each item then write a routine that check·each sensor and base on the set point that you have for·each sensor will turn that relay on then go back to the routine and check the sensors again

    I have found until you have a good understanding of the sensors that you are going to use it is very hard to get a routine written that will work
    Ugha has the right· idea.gif·here


    Ugha
    ·
    Start:
    Check temp sensor
    if temp is too high and fan = 0 THEN turn on fan
    else if temp is too low and fan = 1 THEN turn off fan
    check light sensor
    if light sensor is dark and Light = 0, turn on light
    if light sensor is light and Light = 1, turn off light
    pause X
    goto start

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 3/8/2008 6:34:03 PM GMT
  • trini4lifetrini4life Posts: 4
    edited 2008-03-08 18:57
    I am building a device that uses 2 GP2D12 distance sensors. It will measure the thickness or width of an object placed between the sensors. I need to find a way using PBasic to have the sensors turn on and off alternately. One turns on for 50ms then off, then the 2nd sensor turns on for 50ms. Any help would be greatly appreciated.
  • ColtColt Posts: 24
    edited 2008-03-08 20:06
    ·· I used something similar to control a travel refrigerator, I'll attach the code. It's not the final code, but just a basic program. Some of the stuff in the code isnt hooked up or tested, but you'll get the general idea of what is going on. When the temp reached a certain setpoint it would cycle the cooler on and off. I ran the code for a month or so, just controling the cool cycle· ( on and off ) and it just exactly what it was supposed to do.·· Adding more sensors shouldnt be any big deal, just think it out...
  • Shadowcasterx4ffcShadowcasterx4ffc Posts: 13
    edited 2008-03-08 20:25
    Thanks guys. I'll have the guy check it out when we get back to school.

    Anyway, I don't think we have the demo code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Eugene
    Greenhouse Project

    Post Edited (Shadowcasterx4ffc) : 3/10/2008 4:40:08 PM GMT
Sign In or Register to comment.