element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • 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 hysteresis with DS18B20-W sensor.
  • 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
  • Replies 3 replies
  • Subscribers 391 subscribers
  • Views 1854 views
  • Users 0 members are here
Related

hysteresis with DS18B20-W sensor.

ustrup
ustrup over 7 years ago

Hello I really need help and input on some code I am making.

I have a Arduino Uno v3, I am using for controlling some heating elements, true some solidstate relay, the teknik part is working fin, but I need/ or wont to program a hysteresis of 1 degrade celcius in my code.

 

CODE:

 

#include <DallasTemperature.h>

#include <LiquidCrystal.h>

#include <OneWire.h>

#include <EEPROM.h>

#include <math.h>

 

 

#define ONE_WIRE_BUS A0//DS18B20 connectet to A0

 

 

const int rs = 12, en =11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);// lcd displayet is runing on this pins.

 

 

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

 

 

int potpin = A5;// 10 k ohm pot connetet to A5

int potmeter;

float TempAct;

 

 

 

 

void setup(){

  sensors.begin();

  lcd.begin(16,2);

  analogWrite(3, 0);

  Serial.begin(9600);

  pinMode(potpin,INPUT);//pot

  pinMode(7,OUTPUT);//relaypin 500W heat element

  pinMode(9,OUTPUT);//relaypin 2000W heat element

   lcd.print("YES MASTER");

   delay(2500);

   lcd.clear();// YES MASTER is on screen for 2,5 ss, then the screen clears.

  

}

void loop(){

  float Potmeter;

  sensors.requestTemperatures();//arduino is asking for temp

  TempAct = sensors.getTempCByIndex(0);// the temp is read digital.

  Serial.println(TempAct);// the data is send serial.

  lcd.setCursor(0,0);

  lcd.print("C ");

  lcd.print(TempAct);// what is shoe on the lcd

  lcd.setCursor (0,1);//position on the lcd

  lcd.print("SET TO:");

  Potmeter = 0;

  int x;

  for (x = 0; x < 100; x++)

 

    Potmeter += analogRead(potpin);

 

 

  Potmeter = (((Potmeter/100) * (5.0 / 1023.0)) * 16) + 20;

  lcd.print(round(Potmeter*2)/2);

  lcd.print(" ");

  Serial.println(Potmeter);

 

  if (Potmeter > TempAct){

     digitalWrite (7, LOW);

     digitalWrite (9, LOW);

  }

  if (TempAct > Potmeter){

     digitalWrite (7, HIGH);

     digitalWrite (9, HIGH);

  }

  delay(250);

}

I need help / input to have I get it to reat with 1 degrede celcius on the screen and in the program, so that the relays don,t goes on/off all the time

 

thank in advars for the help

  • Sign in to reply
  • Cancel

Top Replies

  • beacon_dave
    beacon_dave over 7 years ago in reply to ustrup +4
    thank you very much, but were and have can I declare hysteresis? If Potmeter contains the value in degrees then to add a one degree hysteresis window then adjust its value by +-0.5 when you compare it…
  • beacon_dave
    beacon_dave over 7 years ago +3
    Perhaps try something like: if (TempAct < Potmeter - hysteresis) { // below threshold, turn on heater } if (TempAct > Potmeter + hysteresis) { // above threshold, turn off heater }
Parents
  • ustrup
    ustrup over 7 years ago

    thank you very much, but were and have can I declare hysteresis?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • ustrup
    ustrup over 7 years ago

    thank you very much, but were and have can I declare hysteresis?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • beacon_dave
    beacon_dave over 7 years ago in reply to ustrup

    thank you very much, but were and have can I declare hysteresis?

     

    If Potmeter contains the value in degrees then to add a one degree hysteresis window then adjust its value by +-0.5 when you compare it with the value from the sensor. e.g.

     

    if (TempAct < Potmeter - 0.5)  
    {  
       // below threshold, turn on heater  
    }  
      
    if (TempAct > Potmeter + 0.5)  
    {  
       // above threshold, turn off heater  
    } 

     

    You could create the value as a variable and declare it at the top of your code.

     

    ( You may want to look at using a PID algorithm due to the typical latency and overshoot found in heating control situations.

    https://playground.arduino.cc/Code/PIDLibrary )

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Cancel
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