element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Serial won't work!
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 14 replies
  • Subscribers 402 subscribers
  • Views 1190 views
  • Users 0 members are here
  • help
  • work
  • heating
  • code
  • please
  • serial
  • won't
  • arduino
Related

Serial won't work!

Former Member
Former Member over 11 years ago

I'v bin trying to making a heating auto heating system that turns the knob with a servo, I can change the var upload and it will change position but every time i try to set up commands thought serial I get nothing, not even printing the serial I just sent.  I'v tried this over and over again in different variations and am starting to get sick of just having my arduino uno just hanging from my wall doing nothing. please help.

 

 

my code:

 

#include <Servo.h>

Servo officeHeat;

int heat40 = 800;

int heat45 = 950;

int heat50 = 1150;

int heat55 = 1325;

int heat60 = 1500;

int heat65 = 1700;

int heat70 = 1825;

int heat75 = 1975;

int heat80 = 2150;

int officeHeatSetTo = heat60;

 

void setup(){

  Serial.begin(9600);

  officeHeat.attach(9);

}

 

 

void loop(){

//check if serial is available

  while(Serial.available() > 0){

    //read serial and set var

    int heatCommand = Serial.read();

    //if the command is A then set heat to 65

    if(heatCommand == 'A'){

      officeHeatSetTo = heat65;

    }

}

  officeHeat.writeMicroseconds(officeHeatSetTo);

//tell computer the current set temp.

  while(true){

    if(officeHeatSetTo == 800){

    Serial.println("40");

  }

    if(officeHeatSetTo == 950){

    Serial.println("45");

  }

    if(officeHeatSetTo == 1150){

    Serial.println("50");

  }

    if(officeHeatSetTo == 1325){

    Serial.println("55");

  }

    if(officeHeatSetTo == 1500){

    Serial.println("60");

  }

      if(officeHeatSetTo == 1700){

    Serial.println("65");

  }

      if(officeHeatSetTo == 1825){

    Serial.println("70");

  }

      if(officeHeatSetTo == 1975){

    Serial.println("75");

  }

      if(officeHeatSetTo == 2150){

    Serial.println("80");

  }

  delay(1000);

}

}

  • Sign in to reply
  • Cancel
Parents
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago

    what you need is something like this (Which works on my UNO)

     

    #define ServoEnabled 1 // change to 1 to enable servo output, 0 to disable
    #if ServoEnabled
    #include <Servo.h>
    #endif
    #define heat40  800
    #define heat45  950
    #define heat50  1150
    #define heat55  1325
    #define heat60  1500
    #define heat65  1700
    #define heat70  1825
    #define heat75  1975
    #define heat80  2150
    #define  printDelay 1000 // 1 second between prints
    int HeatSetting = 0;
    int newHeatSetting = 0;
    long printTimer = 0;
    #if ServoEnabled
    Servo officeHeat;
    #endif
    void setup() 
    {
       Serial.begin(9600);
       HeatSetting = heat60;
       newHeatSetting = HeatSetting;
       
    #if ServoEnabled
      officeHeat.attach(9,800,2150);
    #endif
       printTimer = millis() + printDelay;
    }
    void loop() { 
      // Any new commands ?
      check_serial();
      
    #if ServoEnabled
      check_Servo();
    #endif
      // Check if time to print heater setting
      if (millis() > printTimer) 
      {
        Serial.print("Temp Set to ");
        Serial.println(HeatSetting, DEC);
        printTimer = millis()+printDelay;
      }
      // Do other stuff
    }
    void check_serial()
    {
      char a=Serial.read();
      if ((a>='0')&& (a<='Z'))
        {
        switch (a)
          {
            case 'A' :newHeatSetting = heat40; break;
            case 'B' : newHeatSetting = heat45; break;
            case 'C' : newHeatSetting = heat50; break;
            case 'D' : newHeatSetting = heat55; break;
            case 'E' : newHeatSetting = heat60; break;
            case 'F' : newHeatSetting = heat65; break;
            case 'G' : newHeatSetting = heat70; break;
            case 'H' : newHeatSetting = heat75; break;
            case 'I' : newHeatSetting = heat80; break;
            case '0' : Serial.println("0 Received"); break;
            case '1' : Serial.println("1 Received"); break;
            case '2' : Serial.println("2 Received"); break;
            case '3' : Serial.println("3 Received"); break;
            case '4' : Serial.println("4 Received"); break;
            case '5' : Serial.println("5 Received"); break;
            case '6' : Serial.println("6 Received"); break;
            case '7' : Serial.println("7 Received"); break;
            case '8' : Serial.println("8 Received"); break;
            case '=' : Serial.println(HeatSetting, DEC); break;
            default : break;
          }
        }  
    }
    #if ServoEnabled
    void check_Servo()
    {
      if (newHeatSetting != HeatSetting)
      {
        officeHeat.writeMicroseconds(HeatSetting);
        HeatSetting = newHeatSetting;
      }
    }
    #endif

     

    this will only change the servo when the current value is different from the new value, it does not waste time in delays and has a nice structured case for managing commands

     

    regards

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
Reply
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago

    what you need is something like this (Which works on my UNO)

     

    #define ServoEnabled 1 // change to 1 to enable servo output, 0 to disable
    #if ServoEnabled
    #include <Servo.h>
    #endif
    #define heat40  800
    #define heat45  950
    #define heat50  1150
    #define heat55  1325
    #define heat60  1500
    #define heat65  1700
    #define heat70  1825
    #define heat75  1975
    #define heat80  2150
    #define  printDelay 1000 // 1 second between prints
    int HeatSetting = 0;
    int newHeatSetting = 0;
    long printTimer = 0;
    #if ServoEnabled
    Servo officeHeat;
    #endif
    void setup() 
    {
       Serial.begin(9600);
       HeatSetting = heat60;
       newHeatSetting = HeatSetting;
       
    #if ServoEnabled
      officeHeat.attach(9,800,2150);
    #endif
       printTimer = millis() + printDelay;
    }
    void loop() { 
      // Any new commands ?
      check_serial();
      
    #if ServoEnabled
      check_Servo();
    #endif
      // Check if time to print heater setting
      if (millis() > printTimer) 
      {
        Serial.print("Temp Set to ");
        Serial.println(HeatSetting, DEC);
        printTimer = millis()+printDelay;
      }
      // Do other stuff
    }
    void check_serial()
    {
      char a=Serial.read();
      if ((a>='0')&& (a<='Z'))
        {
        switch (a)
          {
            case 'A' :newHeatSetting = heat40; break;
            case 'B' : newHeatSetting = heat45; break;
            case 'C' : newHeatSetting = heat50; break;
            case 'D' : newHeatSetting = heat55; break;
            case 'E' : newHeatSetting = heat60; break;
            case 'F' : newHeatSetting = heat65; break;
            case 'G' : newHeatSetting = heat70; break;
            case 'H' : newHeatSetting = heat75; break;
            case 'I' : newHeatSetting = heat80; break;
            case '0' : Serial.println("0 Received"); break;
            case '1' : Serial.println("1 Received"); break;
            case '2' : Serial.println("2 Received"); break;
            case '3' : Serial.println("3 Received"); break;
            case '4' : Serial.println("4 Received"); break;
            case '5' : Serial.println("5 Received"); break;
            case '6' : Serial.println("6 Received"); break;
            case '7' : Serial.println("7 Received"); break;
            case '8' : Serial.println("8 Received"); break;
            case '=' : Serial.println(HeatSetting, DEC); break;
            default : break;
          }
        }  
    }
    #if ServoEnabled
    void check_Servo()
    {
      if (newHeatSetting != HeatSetting)
      {
        officeHeat.writeMicroseconds(HeatSetting);
        HeatSetting = newHeatSetting;
      }
    }
    #endif

     

    this will only change the servo when the current value is different from the new value, it does not waste time in delays and has a nice structured case for managing commands

     

    regards

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Reject Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube