Connect with us

Arduino Programming Help

Discussion in 'Microcontrollers, Programming and IoT' started by Jaderman, Jul 9, 2010.

Scroll to continue with content
  1. Jaderman


    Dec 12, 2009
    I've been trying to write this "supper easy" (what I thought in the beginning) and I just can't figure it out, so I thought why not see if someone else (who is smarter than me) can help me. I've had AWSOME help on here on my last question so now I'll try it again.
    So, I'm trying to make a Hot Bed (isn't what it sounds like it is) that has a automatic lid opener. a Hot Bed is a box with a window on top for sun to come in and warm the box up that has plants inside so your crop will yield longer and grow faster. We used to use one but quit because we would always forget to open up the lid to let it cool off so we would then all we would have is brown little stubbles. Then if the lid is automatic, we won't have to worry about opening or closing the lid.
    Here's my latest code that I wrote up (that didn't work):

    #define tempSensor 0
    #define MotorUp 12
    #define MotorDown 11

    int temp_val = 0;
    int x = 0;

    void setup() {
    x = temp_val;
    Serial.begin (9600);
    pinMode (MotorUp, OUTPUT);
    pinMode (MotorDown, OUTPUT);

    void loop() {

    x = temp_val;
    temp_val = analogRead(tempSensor); // tempSensor is the Photo cell that will be inside
    // the hot bed.
    while (x > 50) { // 50 is roughly the hottest temperature that
    Serial.print("Temp Sensor Reads: "); // the bed should reach
    Serial.println( temp_val );

    digitalWrite(MotorUp,HIGH); // this (should) opens up the lid

    while (x < 45); // this is the coolest that it should get
    Serial.print("Temp Sensor Reads: ");
    Serial.println( temp_val );

    digitalWrite(MotorDown,HIGH); // then the lid closes

    I would greatly appreciate comments, help, corrections, anything. Thanks. :)
  2. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    Jan 21, 2010
    So what doesn't this program do?

    It looks like it tries to keep closing the lid even if it's closed (which is a bad idea unless you have limit switches). It does the same when temp > 50 (keeps trying to open it).

    You don't ever initialise the MotorUp and MotorDown signals.

    You never call the setup routine

    Your syntax for the while commands seems badly wrong (there is no identification of the code block to execute, so it's likely the next statement is the entire block.

    You have mismatching braces.

    The code would never compile. Don't you think that you should at least do some basic tests (even attempting to compile the code?) before you ask for help?
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day