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 Help to arduino code
  • 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 Not Answered
  • Replies 3 replies
  • Subscribers 402 subscribers
  • Views 305 views
  • Users 0 members are here
Related

Help to arduino code

Former Member
Former Member over 13 years ago

Hi. (First I must say that I am from Denmark, so i hope that you understand my english.)

 

I hope that someone will help me. I have tried to make a code for my arduino uno. 

 

I want to have 3 LED's to increase light dependent on a signal from at tempeature sensor.

They should do it in different intervals, so that LED1 should increase light when the signal from the temperature sensor is between 165 and 200, and hold full light to everything above 200.

 

The LED2 should start at 200 and increase up to 225, and hold full light to everuthing above 225.

 

The LED3 should start at 225 and increase up to 240, and hold full light to everuthing above 240.

 

 

 

I have used PWM to control the LED's, but they all light all the time and when the temperature changes they increase and decrease in an uncontrolled way.

 

So my qustions are:

 

1. Why does the LED's light all the time and why do they increase and decrease uncontrolled?

 

As mentioned above, I would like to keep the LED's fully lighted if the value exceeds the limits in the 'if' statement.

 

So second question:

2. Can i in some way use 'constrain' to hold the LED's on when the temperature input signal is over the value that the light should increase on? IF not, what can I use?

 

I have attached the code.

Attachments:
LED_som_funktion_af_temp.ino.zip
  • Sign in to reply
  • Cancel
Parents
  • anhtien
    0 anhtien over 13 years ago

    Without knowing your schematics, here are few things you might want to check:

    1. Is the analog 0 pin connected properly to your temp sensor ? If it's a DHT11, you might want to use a 10K ohm between pin 2 (data) to VCC to prevent fluctuation, adafruit has a good schematic for DHT11 as a starting point, note that they use pwm pin 2 in their code, so you want to modify the code to your connection.

    2. Why do you clip the constraint to 0, 200 and then test data up to 240? It looks like a bug, maybe you want to use val = constraint (165, 240) or something, what happen if value is somewhere between 0 and 165, there is no code to do anything for the LEDs

    3. your 500ms delay seems too fast, why so fast? I usually have a delay like 10sec and even that I find it too much work for the arduino.

    Good luck.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 13 years ago in reply to anhtien

    anhtien: Thanks for your answer.

     

    1. Right now im using a pot meter instead of the temperature sensor, but i dont have a 10K ohm resistor in circuit. I am not sure if it will help me, because I am reading the signal that goes in on analog 0 with the 'serial monitor' and there dosnt seem to be any interruptions.

     

    2. I attahced the wrong code image  I have attahced the right one now.

     

    3. It dosnt have to be so fast, but i dont see why it should be a problem?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 13 years ago in reply to anhtien

    anhtien: Thanks for your answer.

     

    1. Right now im using a pot meter instead of the temperature sensor, but i dont have a 10K ohm resistor in circuit. I am not sure if it will help me, because I am reading the signal that goes in on analog 0 with the 'serial monitor' and there dosnt seem to be any interruptions.

     

    2. I attahced the wrong code image  I have attahced the right one now.

     

    3. It dosnt have to be so fast, but i dont see why it should be a problem?

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