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 Help with adding to my 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
  • Replies 13 replies
  • Subscribers 392 subscribers
  • Views 993 views
  • Users 0 members are here
Related

Help with adding to my code

toxsickcity
toxsickcity over 9 years ago

Hi all,

 

 

I would like some help

Can someone guide me how to add functionality to my program to enable the arduino board to trigger an output when a set temperature is triggered.

 

I want to use my Sensors 1 and Sensor 2 to add 2 output triggers when a set temperature is reached with a minimum time to be triggered to stop relay hammer.

 

 

My Project is a WALL COMPUTER

 

I am building a special computer which has many thermal sensors and lighting effects for all components.

 

My plan is to have a cool lighting system and an automated fan speed system,

 

So when Video Card 1 / Video Card 2 / Power Supply / HDD / CPU / Water Temp, heat up

each device's lighting should glow red instead of blue, and want the relay to trigger.

 

I have brought a 2 channel Fully Isolated Photo Relay board and it has low or high level inputs to trigger the relays.

I have this part

 

http://www.ebay.com/itm/DC-5V-2-Channel-Double-Photo-Coupler-Isolated-Relay-H-L-Trigger-Layer-PCB-board-/201137319240

 

I have had much help making my arduino uno board control 2 LED strips cycle the Blue to RED  via thermal input.

It uses 6 PWM outputs and 2 Analog for the Sensors.

 

The program has been made from ideas of

http://www.jerome-bernard.com/blog/2013/01/12/rgb-led-strip-controlled-by-an-arduino/

 

I need to add code which I don't have yet. I don't know what code to use and don't know how to implement it to use the existing code I have

 

I am a noob and don't understand any of the code.

 

for example, I spent hours trying to remove green from the colour circle and failed.

I don't know what is going on with code..

 

I want to make the arduino board control both channels from my 2 thermos sensors.

 

at X temp. turn on

relay 1 must be controlled by sensor 1

relay 2 must be controlled by sensor 2

 

Any anyone can guide me I'd really appreciate this.

As this project is nearing completion and need my arduino working.

 

If you have any questions please don't hesitate to ask

 

Cheers

Shaun

Attachments:
code.txt.zip
  • Sign in to reply
  • Cancel

Top Replies

  • toxsickcity
    toxsickcity over 9 years ago in reply to mcb1 +1
    A Massive thank you for your help, I was too tired after work last night to fiddle but after today, its the weekend!! many thanks, I will report my findings tonight if I have enough energy!
  • mcb1
    mcb1 over 9 years ago in reply to toxsickcity

    toxsickcity

     

    Firstly I don't have your setup, so it's very hard to give you code that works.

    All I can do is provide some pointers to help you work out what is happening.

     

     

    The numbers at lines 89 and 95 (turn on line numbering under preferences)

      rgb[0] = (rgbval & 0x00FF0000) >> 16; // there must be better ways

      rgb[1] = (rgbval & 0x0000FF00) >> 8;

      rgb[2] = rgbval & 0x000000FF;

     

    are getting a value using some maths.

    The 0x signifies a hex number and if you plug it into windows calculator (macs must have an equivalent) on programmer mode you can display the binary equivalent.

       imageimage

     

    (rgbval & 0x00FF0000) is an AND function, where the 24bit number held in rgbval is AND'ed with hex FF0000.

    This bascially extracts the last 8 bits of the rgbval (ie the MSB 8 bits).

    The >> 16 signifies shifting the result 16 places towards the decimal point.

     

    So they start with a 24 bit number and seperate it into three 8 bit numbers.

     

    Because you changed the FF00 into 0000 you have effectively removed the middle parts of the rgbval number, which I presume is the green .

     

    There is a brightness setting here in line 52 (and 53 for the other set)

    long bright[3] = { 107, 67, 256};

     

    If the green LED is on pin 10, then you could try changing the 67 to something lower instead.

     

     

    Original sketch

    This sketch seems to add up lots of things, store as a large number then break it down to individually control the pins.

    For your Red or Blue, I'm wondering if you start with a neutral colour at (20 degC), and if it's lower then increase the Blue, or hotter increase the red.

     

    You could speed it up by stepping one up while stepping the other down to double the effect.

     

     

    Hope this helps

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • toxsickcity
    toxsickcity over 9 years ago in reply to mcb1

    Thanks so much for your help,

     

    I have played with these values and yes I does change how green operates..

     

    It is helpful but with wanted to add that 3rd set of LED strip and sensor,

    I need to remove the pin usage.

     

    Can I ask for your explanation of the following?

     

     

    Line 24,  #define RED       9// pin for red LED

     

    How does it know to use 3 pins for the pins 9, 10 and 11?

     

    is it something with the Line 61 and 62?

      for (k=0; k<3; k++) {

        pinMode(RED + k, OUTPUT);

    does K represent how many pins to use?

     

     

    as I was helped with adding a 2nd set of pwm pins as the code wanted to use pins 3,4,5 for the 3,5,6 i have configured

    so the code is different, it states to use pins 3,5,6 with the

     

    Line 34 int secondPins [] = { 3,5,6};

    vs Line 24 which only says  #define RED       9// pin for red LED

     

    at this stage I only want to play with the code to see if I can remove 1 pin from each RGB strip and I will play with the colouring later..

     

    the code system in the software is also pretty good as it kind of tells me whats wrong when I randomly remove code to trial editing image hjahaha

     

    i hope you can shed some light on this..

    Thanks for your interest and help,

     

    Would you like me to draw a schematic diagram and attach photos of the way I have it wired?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • mcb1
    mcb1 over 9 years ago in reply to toxsickcity

    toxsickcity

    Which one do I start with ....I'm at work so I don;t have full access to the IDE.

    Yes basically line 61, 62 are definng the other pins.

    RED (9) + k (0) = 9, then RED (9) + k (1) = 10, then RED (9) + k (2) = 11 is how it works.

    K never reaches more than 2 ...

    Look at the reference under For ....  basically you specify the start (0) ; Limit (K <3) K is less than 3; increment (k++) which is K + 1.

     

    Line 34 is defining an array.

    The best way is to think of a calendar. It is months [12] and for each month they have a certain number of days.

    Line 34 is saying the array called secondPins[0] contains 3, secondPins[1] contains 4, and secondPins[2] contains 5.

    Because you haven't said what size the array is it is happy when there is no more data.

     

    There are some mixtures of methods used for this sketch .... which makes it harder to get your head around.

     

     

    I suggest you download this book.

    https://juniorfall.files.wordpress.com/2011/11/arduino-cookbook.pdf

    https://github.com/shihyu/Arduino/blob/master/books/Oreilly.Arduino.Cookbook.2nd.Edition.Dec.2011.pdf

     

     

    Mark

    • Cancel
    • Vote Up 0 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