Hi All,
I am new here, I hope to get some help to make a NTC 10K thermistor to work with my arduino project…
I hope everyone is well to get some help on my code for project I am doing.
I have tried for days and I just don’t get it. it may stand to you guys.
My project is using a program thats gets written to a programmable circuit (Arduino) that reads a sensor I didn’t like the ONEWIRE sensor and now wish to use 10K type which are much much smaller and can better hide!
I have made my code from searching all over the internet and putting them together… in the end I got it working but now which to use those 10k thermistor as they are tiny and can fit in smallest places…
Can you guys can read my program and help to see where I am going wrong. I have marked areas of interest with // areas.
Everytime I compile I am getting GetTemp4 was not declared in this scope Line 65
float temperature = constrain(getTemp4(), MIN_TEMP, MAX_TEMP);
thanks, Please read on as I attached other code I stole the thermistor program
// LINE 6-17 = new code trying to make use of TEMP_PIN A0 which is a thermistor.
// LINE 41 added TEMP-PIN as an input
// Lines 57-58 I copied from another code.
// LINES 87-134 I have disabled to try and start using a new Thermistor line 6
#define TEMP_PIN A0
//int adc = 0;
//int blue = 0, red = 0;
double ReadThermistor(int adc) {
double resistance = ((1024.0/adc) - 1); //calculate from voltage divider, for 10k resistor
double Temp4 = log(resistance);
// calculate the temperature, in K, using 4 thermistor model/material specific parameters A, B, C, D
// here we use the values for the Sparkfun/Hactronics version of the Vishay 10k NTC thermistor
Temp4 = 1 / (0.003354016 + 0.0002569850 * Temp4 + 0.000002620131 * Temp4 * Temp4 + 0.00000006383091 * Temp4 * Temp4 * Temp4);
Temp4 = Temp4 - 273.15; // Convert Kelvin to Celsius
return Temp4;
}
//#include "OneWire.h"
//#include "Streaming.h"
//const int DS18S20a_Pin = 2; //DS18S20 Signal pin on digital 2
#define MIN_TEMP 10
#define MAX_TEMP 45
#define RELAY1 4 // Relay on digital pin 4
//OneWire ds(DS18S20a_Pin);
#define SIZE 255
#define DELAY 0
#define HUE_MAX 6.0
#define HUE_DELTA 0.01
int firstPins [] = { 3,5};
long rgb[2];
long rgbval;
float hue=0.0, saturation=1, value=1;
long bright[2] = { 256, 256};
long k, temp_value;
void setup () {
pinMode(TEMP_PIN, INPUT);
randomSeed(analogRead(4));
pinMode(RELAY1, OUTPUT);
Serial.begin(57600);
for (k=0; k<2; k++) {
pinMode(firstPins[k], OUTPUT);
rgb[k]=0;
analogWrite(firstPins[k], rgb[k] * bright[k]/256);
}
}
void loop() {
adc = analogRead(TEMP_PIN);
int temp4 = ReadThermistor(adc);
pinMode(RELAY1, OUTPUT); //new
//This is to make use of temperature to setup lighting and activate relay switches based of heat etc
// float temperature = constrain(getTemp(), MIN_TEMP, MAX_TEMP); // REMOVED LINE TO NOW USE DIFFERENT SENSOR the gettemp is below and cannot work out how to attach new sensor
float temperature = constrain(getTemp4(), MIN_TEMP, MAX_TEMP); // I HAVE RENAMED Temp to Temp4 to make it clear as the code above Lines 11-16
float deltaTemp = (MAX_TEMP - MIN_TEMP);
float deltaHue = 4 - 0;
hue = map((temperature - MIN_TEMP) * 100, 0, deltaTemp * 100, deltaHue * 100, 0) / 100.0;
rgbval=HSV_to_RGB(hue, saturation, value);
rgb[0] = (rgbval & 0x00FF0000) >> 16;
rgb[1] = (rgbval & 0x0000ff00) >> 8;
for (k=0; k<2; k++) {
analogWrite(firstPins[k], rgb[k] * bright[k]/256);}
//SECTION CONTROL RELAY SWITCH
if (temperature < 40) {
digitalWrite(4,HIGH);
} else if (temperature > 36) {
digitalWrite(4,LOW);
}
}
//SENSORS SECTION
// I DISABLED THIS PART OF CODE TO ALLOW USE OF MY NEW SENSOR NOT THE ONEWIRE TYPE.
//float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius
//byte data[12];
// byte addr[8];
// if ( !ds.search(addr)) {
// //no more sensors on chain, reset search
// ds.reset_search();
// return -10;
// }
// if ( OneWire::crc8( addr, 7) != addr[7]) {
// Serial.println("CRC is not valid!");
// return -10;
// }
// if ( addr[0] != 0x10 && addr[0] != 0x28) {
// Serial.print("Device is not recognized");
// return -10;
// }
// ds.reset();
// ds.select(addr);
// ds.write(0x44,1); // start conversion, with parasite power on at the end
// byte present = ds.reset();
// ds.select(addr);
// ds.write(0xBE); // Read Scratchpad
// for (int i = 0; i < 9; i++) { // we need 9 bytes
// data[i] = ds.read();
// }
// ds.reset_search();
// byte MSB = data[1];
// byte LSB = data[0];
// float tempRead = ((MSB << 8) | LSB); //using two's compliment
// float TemperatureSum = tempRead / 16;
// return TemperatureSum;
//}
// End Sensors
//THIS SECTION IS CREATING COLOURS TO DISPLAY ON LED STRIP
long HSV_to_RGB( float h, float s, float v ) {
/* modified from Alvy Ray Smith's site: http://www.alvyray.com/Papers/hsv2rgb.htm */
// H is given on [0, 6]. S and V are given on [0, 1].
// RGB is returned as a 24-bit long #rrggbb
int i;
float m, n, f;
// not very elegant way of dealing with out of range: return black
if ((s<0.0) || (s>1.0) || (v<1.0) || (v>1.0)) {
return 0L;
}
if ((h < 0.0) || (h > 6.0)) {
return long( v * 255 ) + long( v * 255 ) * 256 + long( v * 255 ) * 65536;
}
i = floor(h);
f = h - i;
if ( !(i&1) ) {
f = 1 - f; // if i is even
}
m = v * (1 - s);
n = v * (1 - s * f);
switch (i) {
case 6:
case 0:
return long(v * 255 ) * 65536 + long( n * 255 ) * 256 + long( m * 255);
case 1:
return long(n * 255 ) * 65536 + long( v * 255 ) * 256 + long( m * 255);
case 2:
return long(m * 255 ) * 65536 + long( v * 255 ) * 256 + long( n * 255);
case 3:
return long(m * 255 ) * 65536 + long( n * 255 ) * 256 + long( v * 255);
case 4:
return long(n * 255 ) * 65536 + long( m * 255 ) * 256 + long( v * 255);
case 5:
return long(v * 255 ) * 65536 + long( m * 255 ) * 256 + long( n * 255);
}
}
}
I have copy and pasted some code from this program which is simpler and use RGB… I want only RedBlue and my main code has what I need… as to why I want to make the sensor in this code work my mine
https://create.arduino.cc/projecthub/be … led-6c8cdf
#define TEMP_PIN A0
#define RED_PIN 9
#define GREEN_PIN 10
#define BLUE_PIN 11
int adc = 0;
int blue = 0, red = 0;
double ReadThermistor(int adc) {
double resistance = ((1024.0/adc) - 1); //calculate from voltage divider, for 10k resistor
double Temp = log(resistance);
// calculate the temperature, in K, using 4 thermistor model/material specific parameters A, B, C, D
// here we use the values for the Sparkfun/Hactronics version of the Vishay 10k NTC thermistor
Temp = 1 / (0.003354016 + 0.0002569850 * Temp + 0.000002620131 * Temp * Temp + 0.00000006383091 * Temp * Temp * Temp);
Temp = Temp - 273.15; // Convert Kelvin to Celsius
return Temp;
}
void setLED(int blue, int red){
analogWrite(BLUE_PIN, blue);
analogWrite(RED_PIN, red);
}
void setup(){
Serial.begin(9600);
pinMode(BLUE_PIN, OUTPUT);
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(TEMP_PIN, INPUT);
}
void loop(){
adc = analogRead(TEMP_PIN);
int temp = ReadThermistor(adc);
Serial.println(temp);
red = map(temp, 20, 40, 0, 255);
blue = 255 - red;
setLED(blue, red);
}
Cheers.
Shaun