Notifications
Clear all

need help with sketch for an Arduino temperature controller.

65 Posts
5 Users
14 Likes
6,814 Views
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2043
 

@will 

It has a diode inbuilt to protect the driving transistor.

Also the Arduino or anything using the module is protected by the fact it uses an optocoupler.

https://www.handsontec.com/dataspecs/module/2Ch-relay.pdf

 


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 

@robotbuilder 

Thanks a lot for looking it up.

That means that the relay is safe and so is the Arduino pin connected to it since it only has to run the optocoupler instead of needing to drive the could directly.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@thenewdays)
Member
Joined: 2 years ago
Posts: 29
Topic starter  

@will, @robotbuilder

That is good news about the relay, i didn't look at the specs, it was for another project (fermenter) that is still have to put together.

Apologies for the bad schematic, I usually draw them by hand and much cleaner. 

temp con

The Max6675 works and reads the temp with the demo sketch.

Something is missing to return the sketch to the beginning of the void loop, it runs the whole sketch and gets stuck at the beginning of the void loop. I don't know how else to explain it.

I am not stupid, I just say things that are.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 

@thenewdays 

Thanks, the wiring looks reasonable, so we can probably scratch that off the list.

OK, which demo sketch did you use for the MAX6675 ?

You should not drive the relay from the Arduino, it can't handle the power required. It may be that the power is only used for the optocoupler and your diagram just doesn't show what's powering the relay coil.

You're drawing power for a lot of different elements, so it may be a good idea to put a couple of 100 uF electrolytic capacitors on your external breadboard (one on each side)across the + and - rails to provide a buffer for the other components.

Please set DEBUG to true and watch the serial monitor to verify that it is, truly looping. I can't think of anything that would prevent it from doing so.

Also, please send me a copy of the sketch you're working on. The last one you posted doesn't even compile so it can't be the one you're using for testing.

Another test I suggested earlier is to print the values of temp and pot every time through the loop to verify whether it is looping or not.

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@thenewdays)
Member
Joined: 2 years ago
Posts: 29
Topic starter  

I double checked and compiles no issues. The other 2 are the test files.

I thought there was a virtual arduino where you can see the output.

I am not stupid, I just say things that are.


   
ReplyQuote
(@thenewdays)
Member
Joined: 2 years ago
Posts: 29
Topic starter  

https://wokwi.com https://wokwi.com/

virtual arduino

I am not stupid, I just say things that are.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7070
 

@will That's excellent advice from @will @thenewdays.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.


   
Thenewdays reacted
ReplyQuote
(@thenewdays)
Member
Joined: 2 years ago
Posts: 29
Topic starter  

https://wokwi.com/projects/328336990541972051

not sure if this will work, virtual arduino so you can see the code in action.

I am not stupid, I just say things that are.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 
Posted by: @thenewdays

https://wokwi.com/projects/328336990541972051

not sure if this will work, virtual arduino so you can see the code in action.

Does this mean that you're not really running it on an Arduino ?

By the way, your temp_con.ino still won't compile clean because you have two includes for MAX6675.h and my Arduino IDE chokes on that and stops compiling.

Here's an updated version of the sketch. I have changed the relay logic (I was assuming that ON was HIGH and OFF was LOW), but apparently they've chosen the opposite so I have adjusted the code. I've also used pinMode to specify input for the pot and output for the relay and initialized the relay off in setup().

I have also modified the code to re-read the MAX6675 only after 300 ms following the previous reading as specified in the serial thermocouple.ino.

Again, I can't test it but it compiles clean on my system.

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 
Posted by: @thenewdays

https://wokwi.com/projects/328336990541972051

not sure if this will work, virtual arduino so you can see the code in action.

Screen Shot 2022 04 07 at 8.14.56 PM

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
(@thenewdays)
Member
Joined: 2 years ago
Posts: 29
Topic starter  

I am using the downloaded version of arduino 1.8.19, not the windows store version.

the temp is reading but relay not working.

 

 

I am not stupid, I just say things that are.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 

So it sounds like everything is working except for the relay. I can't explain that, since it appears that the sketch duplicates what's being done in the relay test sketch.

I would note, however that the wiring in your wokwi diagram doesn't match your Fritzing diagram.

Try using an LED and 330 ohm resistor in series instead of the relay. The LED should be the opposite of the heating pattern. That is, LED on means heating off and LED off means heating on. This is because the relay uses HIGH to switch off and LOW to switch on.

Anything seems possible when you don't know what you're talking about.


   
Ron reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 

@thenewdays 

I (finally) found another error in the temp_con1.ino file.

In the "turnHeatOn()" subroutine, change

if (heaterOn)

to

if (!heaterOn)  // Added ! to test negative instead of positive

 

Anything seems possible when you don't know what you're talking about.


   
Ron reacted
ReplyQuote
(@thenewdays)
Member
Joined: 2 years ago
Posts: 29
Topic starter  

Ok, I will try that. 

I am not stupid, I just say things that are.


   
ReplyQuote
(@thenewdays)
Member
Joined: 2 years ago
Posts: 29
Topic starter  

It works fine with the led. 

I am not stupid, I just say things that are.


   
ReplyQuote
Page 3 / 5