Hello,
I need a little assistance. I am making a smoker that I want to use a Arduino Mega, a Max6675 thermocouple, HC-05, a Arduino compatible relay, and MIT App Inventor to control. I am having an issue getting the proper code with Arduino itself. I have a basic app made and it will connect to the HC-05 but I have no function. I'm curious to see if anyone has tried to do this already and can get me in the right direction. I would like to be able to set the temperature from my phone and have the relay turn the electric burner off once the thermocouple reaches the proper temp and turn burner back on when temperature gets too low. Please help.
All of these things have been done- A good place to start is to use the search bar in the top left of this page, search for each of the components individually or in combinations.
I suggest the following development path.
-
Write an arduino sketch to blink the LED- this gets your dev environment set. Change it to make it flash at a different rate.
-
Write an arduino sketch to read the thermocouple and print the output.
-
Write an arduino sketch to open and close the relay under arduino program control (similar to blinking the LED in step 1)
-
Combine 2 and 3 above to open/close relay at a fixed temperature (specify different 'on' and 'off' temperatures otherwise your relay will switch all the time and wear out)
-
Figure out how to read a value from the serial port. Use this instead of the fixed value in 4.
-
Starting with a fresh sketch connect the bluetooth module and figure out how to read and send data over bluetooth.
-
Combine 6 and 4 together and you have a complete solution (and lots of new knowledge)
Thank you for responding,
Do you have any suggestions on how to get a larger number like 300 and so on to be added to the arduino from a mobile device? I'm running into an issue getting the arduino to accept the number. If you know of another forum to direct me to that would be very appreciated.
Thank you.
Perhaps you can give a bit more detail about your problem? Even better if you can post the code of the troublesome section.
The project that I am working on is a wireless smoker. I have an electric hotplate that that I am trying to interface the Arduino with. I am using an HC-05, Arduino Mega ADK, a four channel arduino compatible relay, and an app I create with the MITapp Inventor 2 website.
I have the code in the attachment. I have the relay powering up like it is supposed to and the HC-05 is linking and sending information to the serial port of the Arduino, but when looking at the serial monitor I enter in a "1" it displays a 49.00. I really appreciate you taking the time to help me.
Any information I can get is going to be very helpful
Smoker_Project_Rev_3.ino.ino (2.13 KB)
I can not really test what I made of the "work" you posted.
But I hope it will behave a little bit more like you wanted
'0'....'9' is accepted as command, '1' activates the temperature control, all other switch off.
//#include <SoftwareSerial.h>
#include <max6675.h>
//int bluetoothTx = 0; // Keep these here forever
//int bluetoothRx = 1;
//SoftwareSerial bluetooth(bluetoothTx,bluetoothRx);
const byte thermo_gnd_pin = A4;
const byte thermo_vcc_pin = A3;
const byte thermo_so_pin = A2;
const byte thermo_cs_pin = A1;
const byte thermo_sck_pin = A0;
const byte RELAY1 = 2;
const byte RELAY2 = 3;
const byte RELAY3 = 4;
const byte RELAY4 = 5;
MAX6675 thermocouple(thermo_sck_pin, thermo_cs_pin, thermo_so_pin);
void setup() {
// bluetooth.begin(9600);
Serial.begin(9600);
pinMode(thermo_vcc_pin, OUTPUT);
pinMode(thermo_gnd_pin, OUTPUT);
digitalWrite(thermo_vcc_pin, HIGH);
//digitalWrite(thermo_gnd_pin, LOW); // is low already
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);
Serial.print(F("Temp Fahrenheit "));
Serial.print(thermocouple.readFahrenheit());
}
byte operationMode = '0';
void loop()
{
static unsigned int lastDisplay;
int temp_Fahrenheit = thermocouple.readFahrenheit();
if (millis() - lastDisplay > 1000) {
Serial.println(temp_Fahrenheit);
lastDisplay = millis();
}
if (Serial.available()) {
byte serChar = Serial.read();
if (serChar >= '0' && serChar <= '9') {
operationMode = serChar;
}
Serial.print(F("in '"));
Serial.write(serChar);
Serial.print(F("' "));
Serial.println(serChar);
}
switch (operationMode) {
case '1':
digitalWrite(RELAY1, LOW);
digitalWrite(RELAY2, temp_Fahrenheit <= 100);
digitalWrite(RELAY3, temp_Fahrenheit > 100);
digitalWrite(RELAY4, LOW);
break;
default:
digitalWrite(RELAY1, LOW);
digitalWrite(RELAY2, LOW);
digitalWrite(RELAY3, LOW);
digitalWrite(RELAY4, LOW);
}
}
Thank you that helps, but is there a way that I can set the desired temperature with out using a switch case. I want to be able to send the temperature for 100-400 degrees Fahrenheit. I want all numbers in between. Otherwise I will need a lot of cases and only being able to have 10 case wont meet my needs. I really appreciate the help.
This is an extension with ints parsing commands (note the changed serial speed 115200).
//#include <SoftwareSerial.h>
#include <max6675.h>
//int bluetoothTx = 0; // Keep these here forever
//int bluetoothRx = 1;
//SoftwareSerial bluetooth(bluetoothTx,bluetoothRx);
const byte thermo_gnd_pin = A4;
const byte thermo_vcc_pin = A3;
const byte thermo_so_pin = A2;
const byte thermo_cs_pin = A1;
const byte thermo_sck_pin = A0;
const byte RELAY1 = 2;
const byte RELAY2 = 3;
const byte RELAY3 = 4;
const byte RELAY4 = 5;
MAX6675 thermocouple(thermo_sck_pin, thermo_cs_pin, thermo_so_pin);
bool printTempRegularly = true;
byte operationMode = '0';
int wishedTemp = 100;
int deadZone = 2;
void setup() {
// bluetooth.begin(9600);
Serial.begin(115200);
pinMode(thermo_vcc_pin, OUTPUT);
pinMode(thermo_gnd_pin, OUTPUT);
digitalWrite(thermo_vcc_pin, HIGH);
//digitalWrite(thermo_gnd_pin, LOW); // is low already
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);
printHelpAndState();
printTemp(thermocouple.readFahrenheit());
}
void loop()
{
static unsigned int lastDisplay;
int temp_Fahrenheit = thermocouple.readFahrenheit();
if (printTempRegularly && (millis() - lastDisplay > 1000)) {
printTemp(temp_Fahrenheit);
lastDisplay = millis();
}
switch (operationMode) {
case '1':
digitalWrite(RELAY1, LOW);
if (temp_Fahrenheit < (wishedTemp - deadZone)) {
digitalWrite(RELAY2, HIGH);
digitalWrite(RELAY3, LOW);
} else if (temp_Fahrenheit > (wishedTemp + deadZone)) {
digitalWrite(RELAY2, LOW);
digitalWrite(RELAY3, HIGH);
}
digitalWrite(RELAY4, LOW);
break;
default:
digitalWrite(RELAY1, LOW);
digitalWrite(RELAY2, LOW);
digitalWrite(RELAY3, LOW);
digitalWrite(RELAY4, LOW);
}
serialHandler();
}
void printTemp(int value) {
Serial.print(F("Temp Fahrenheit "));
Serial.println(value);
}
// Command line stuff
void pPS(const char* ptr) {
byte curr;
if (ptr) {
while (curr = pgm_read_byte_near(ptr++)) {
Serial.write(curr);
}
}
}
void pEqOnOff(bool val) {
Serial.print(F(" = ")); Serial.print(val ? F("ON") : F("OFF"));
}
void repFlipBool(const char* named, bool& Val) {
Val = !Val;
repBool(named, Val);
}
void repBool(const char* named, bool Val) {
pPS(named);
pEqOnOff(Val);
}
void repBoolNl(const char* named, bool Val) {
repBool(named, Val);
Serial.println();
}
void withOneInt(char* buf, void (*alAction)(int)) {
char* satis;
(*alAction)((int)strtol(++buf, &satis, 0));
}
void setSwitchTemp(int value) {
wishedTemp = value;
}
void setDeadZone(int value) {
deadZone = value;
}
void printHelpAndState() {
Serial.print(F("m<x> operational mode\t= '"));
Serial.write(operationMode);
Serial.write('\'');
Serial.println();
Serial.print(F("t<num> set temperature\t= "));
Serial.println(wishedTemp);
Serial.print(F("d<num> set dead zone\t= "));
Serial.println(deadZone);
repBoolNl(PSTR("s showTempEachSec"), printTempRegularly);
Serial.println(F("? this help"));
}
void processCmd(char* buff) {
switch (*buff) {
case 's':
repFlipBool(PSTR("showTempEachSec"), printTempRegularly);
Serial.println();
break;
case 'm': operationMode = buff[1]; break;
case 't': withOneInt(buff, setSwitchTemp); break;
case 'd': withOneInt(buff, setDeadZone); break;
case '?': printHelpAndState(); break;
}
}
void serialHandler()
{
const byte sCBMax = 30;
static char sCBuffer[sCBMax];
static byte buffIndex = 0;
byte inChar;
bool doCheck = false;
while (Serial.available()) {
inChar = Serial.read();
if (inChar == 13) {
doCheck = true;
} else if (inChar != 10) {
if ((buffIndex == 0) && isWhitespace(inChar)) {
continue;
}
sCBuffer[buffIndex++] = inChar;
doCheck = (buffIndex == (sCBMax - 1));
}
if (doCheck) {
sCBuffer[buffIndex] = 0;
doCheck = false;
if (buffIndex != 0) {
processCmd(sCBuffer);
buffIndex = 0;
} else {
Serial.println();
}
}
}
}
Output
m<x> operational mode = '0'
t<num> set temperature = 100
d<num> set dead zone = 2
s showTempEachSec = ON
? this help
Temp Fahrenheit 32
Temp Fahrenheit 32
Temp Fahrenheit 32
Temp Fahrenheit 32
Temp Fahrenheit 32
Temp Fahrenheit 32
Temp Fahrenheit 32
Thank you for all the help I got it to work off a switch case.
Thank you again
So it would be nice to post the working code.
Here is the code that you guys helped with. I have new revisions incorporating another thermocouple and an LCD. Again thank you for all of the help.
Take a look at this project. It's very mature and works quite well
on my smoker.
Hi,
I'm working on a similar application. However, being the lazy SOB that I am, I want to be able to control the temp of my smoker from a web browser. Where I am having difficulty is in the area of reading values from web form input.
I have experience with "C" code, but very little with HTML, PHP, or other web languages.
A little direction would be helpful.
Here's the simple (stripped down) version of the code I am using:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 0, 177 }; // ip in lan
byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
void setup(){
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.begin(9600);
Serial.println("Temp Set test");
}
void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("");
client.println("");
client.println("Arduino GET test page");
client.println("");
client.println("");
client.println("
Temperature Setting
");// mousedown buttons
client.println("Turn Smoker On/Off");
client.println("
<input type="button" value="ON" onmousedown="location.href ('/?on');"/>");
client.println("<input type="button" value="OFF" onmousedown="location.href ('/?off');"/>"); /**/
// How do I read the value of these buttons?
client.println("Set Smoker Temp");
client.println("
<input type="number" name="Temp" min="100" max="250" step="5">");
client.println("
<input type="submit">");
client.println("");
client.println("");
delay(1);
//stopping client
client.stop();
}
}
}
}
First the usual lecture: use code tags (</>) around your code
like this
Search for 'arduino web blink' to find lots of tutorials on how to do this eg LED Control with Arduino Ethernet Shield Web Server
Thank you For all your help i know its been a while since I post but I have finished the code and the project. I didn't use a WiFi module I used Bluetooth. Here is the code.