Urgent help needed!!! Trigger a heat pad with a capacitive sensor

Hi Folks,

I'm new enough to arduino, so excuse my lack of knowledge on this matter. Essentially I have a circuit set up with a Tip122 transistor that switches the circuit which turns on the heat pad. Currently I have a button to turn this on and off. What I'm looking to do is substitute the button with a capacitive sensor to turn it on and off.

I've attached a schematic of the heat pad circuit and I've also attached a schematic of the capacitive sensor circuit. Essentially I want to add the capacitive sensor circuit to the existing heat pad circuit, remove the button and substitute it with a capacitive sensor

I hope this makes sense

Thanks folks

Hi Folks,

I'm new enough to arduino, so excuse my lack of knowledge on this matter. Essentially I have a circuit set up with a Tip122 transistor that switches the circuit which turns on the heat pad. Currently I have a button to turn this on and off. What I'm looking to do is substitute the button with a capacitive sensor to turn it on and off.

I've attached a schematic of the heat pad circuit and I've also attached a schematic of the capacitive sensor circuit. Essentially I want to add the capacitive sensor circuit to the existing heat pad circuit, remove the button and substitute it with a capacitive sensor

I hope this makes sense

Thanks folks

What you want to do sounds possible.

So you've set up the heating pad, you have some code for it (which you haven't shown us) and it works. Good start.

Now you need to set up the capacitive sensor circuit, find or write some code for that and get that working, switching something, maybe an LED.

When you've done that you can have a go at putting the two programs together and post your attempt here, telling us what works and what doesn't.

Then we can help you.

Steve

I've attached a schematic of the heat pad circuit

I cannot find that one.

You should also post your code (don't forget to use code tags, the </> button in the editor) as if my guess about the heat pad circuit is correct, the main changes are in the code of your project.

Don't cross post!

Doesn't the green LED need a current limit resistor?

Threads merged.

Capacitive touch sensors stand and fall with good grounding of the project, so battery power usually doens't work.

Or look into ready made touch sensors, based on the TTP223 IC. Haven't tried on battery yet, expect that to work as well. They work great on normal power.

Hi Folks,

Thanks for the feedback, it's very much appreciated

Please find attached the code, I keep getting error messages not sure what exactly I'm doing wrong

const int sensorPin = 4; // the number of the pushbutton pin
const int heatPin1 = 10; // the number of the LED pin

int in = 2;
int out = 4;
int state = HIGH;
int r;
int p = LOW;

long time = 0;
long debounce = 200;

// variables will change:

void setup() {
// initialize the LED pin as an output:
pinMode(heatPin1, OUTPUT);

// initialize the sensor pin as an input:
pinMode(sensorPin, INPUT);
pinMode(4, INPUT);
pinMode(8, OUTPUT);

}

void loop(){
// read the value from the sensor:
int sensor_value = analogRead(sensorPin);

if (sensor_value < 15) {
// prints the value into the serial monitor
Serial.print(sensor_value );
// turn the LED on - this is just to show circuit is working
digitalWrite(outPin, HIGH);
// print to serial monitor
Serial.println("-Light on");
// turn the heatpad on
digitalWrite(heatPin, HIGH);
// print to serial monitor
Serial.println("-heat on");
// delay for ease of reading
delay(1000);
r = digitalRead(4);
if (r == HIGH && p == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
digitalWrite(8, state);
p = r;
}

}
else {
// turn the heating off
digitalWrite(heatPin1, LOW);

}
}

  1. please use code tags, as explained in the sticky.
  2. please post the actual errors you get (again using code tags for readability).
 digitalWrite(outPin, HIGH);

There is no outpin declared of set up with pinMode().

digitalWrite(heatPin, HIGH);

Do you mean heatPin1?

p = r;
   }
}  // *******  this } closes loop and should not be there. Caused the else to be hung out
else
{

Make all variables that deal with time (time and debounce) unsigned long to avoid the warning.

Fix those and it will compile. Don't know if it will "work".

Please follow the advice of wvmarle in reply #9. It makes it easier for everyone.

Hi Folks,

Many thanks again

Here's the updated code but still getting an error that says:
'outpin' not declared in this scope

Here is the updated code:

const int sensorPin = 4; // the number of the pushbutton pin
const int heatPin1 = 10; // the number of the LED pin

int in = 2;
int out = 4;
int state = HIGH;
int r;
int p = LOW;

long time = 0;
long debounce = 200;

// variables will change:

void setup() {
// initialize the LED pin as an output:
pinMode(heatPin1, OUTPUT);

// initialize the sensor pin as an input:
pinMode(sensorPin, INPUT);
pinMode(4, INPUT);
pinMode(8, OUTPUT);
digitalWrite(outPin, HIGH);
digitalWrite(heatPin, HIGH);

}

void loop(){
// read the value from the sensor:
int sensor_value = analogRead(sensorPin);

if (sensor_value < 15) {
// prints the value into the serial monitor
Serial.print(sensor_value );
// turn the LED on - this is just to show circuit is working
digitalWrite(outPin, HIGH);
// print to serial monitor
Serial.println("-Light on");
// turn the heatpad on
digitalWrite(heatPin, HIGH);
// print to serial monitor
Serial.println("-heat on");
// delay for ease of reading
delay(1000);
r = digitalRead(4);
if (r == HIGH && p == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
digitalWrite(8, state);

else {
// turn the heating off
digitalWrite(heatPin1, LOW);

}
}

LIAM_MAD:
Here's the updated code but still getting an error that says:
'outpin' not declared in this scope

True.
That's because you didn't declare that variable anywhere, exactly as the compiler tells you.

Here is the updated code:

How hard is it really to follow simple instructions, such as code tags?

So declare an outPin variable.

long time = 0;       
long debounce = 200;

Hint: those are 2 variables declared as long data type. Hint hint: they should be unsigned long

You did not fix the heatPin error.

I will not respond to any more posts that have code improperly posted or advice ignored.

Hi Folks,

Apologies for my coding but I'm new to this, so excuse me.

Here's the updated code, it's compiling for me but the serial monitor isn't showing for me. No date available to see.

Also the sensor is not really behaving the way it should. Both LEDS are on but not reacting when I touch the foil

const int sensorPin = 4; // the number of the pushbutton pin
const int heatPin1 = 10; // the number of the LED pin

int in = 2;
int out = 4;
int state = HIGH;
int r;
int p = LOW;

unsigned long time = 0;
unsigned long debounce = 200;

// variables will change:

void setup() {
// initialize the LED pin as an output:
pinMode(heatPin1, OUTPUT);

// initialize the sensor pin as an input:
pinMode(sensorPin, INPUT);
pinMode(4, INPUT);
pinMode(8, OUTPUT);
digitalWrite(8, HIGH);

}

void loop(){
// read the value from the sensor:
int sensor_value = analogRead(sensorPin);

if (sensor_value < 15) {
// prints the value into the serial monitor
Serial.print(sensor_value );
// turn the LED on - this is just to show circuit is working
digitalWrite(8, HIGH);
// print to serial monitor
Serial.println("-Light on");
// turn the heatpad on
digitalWrite(heatPin1, HIGH);
// print to serial monitor
Serial.println("-heat on");
// delay for ease of reading
delay(1000);
r = digitalRead(4);
if (r == HIGH && p == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
digitalWrite(8, state);

}
else {
// turn the heating off
digitalWrite(heatPin1, LOW);

}
}

LIAM_MAD:
Apologies for my coding but I'm new to this, so excuse me.

You still didn't bother to read the sticky, did you?

void setup() {
  // initialize the LED pin as an output:
  pinMode(heatPin1, OUTPUT);   
     
    
  // initialize the sensor pin as an input:
  pinMode(sensorPin, INPUT); 
  pinMode(4, INPUT);
  pinMode(8, OUTPUT);
  digitalWrite(8, HIGH);
  
      
}

why don't you add Serial.begin (9600); // ??

READ THE WAY TO POST YOUR CODE OR NO HELP WILL BE COMING,

you have been asked SEVERAL times now!! :frowning:

Hi Folks,

Ive' added the serial begin 9600, it's just saying:
-heat on, light on

Both LEDS are on but the sensor isn't working, nothing is changing on the monitor when I touch the
sensor.

Thanks folks

const int sensorPin = 4;     // the number of the sensor pin
const int heatPin1 =  10;      // the number of the LED pin

int in = 2; 
int out = 4;  
int state = HIGH;  
int r;           
int p = LOW; 
      
unsigned long time = 0;       
unsigned long debounce = 200;


// variables will change:


void setup() {
  // initialize the LED pin as an output:
  pinMode(heatPin1, OUTPUT);   
     
    
  // initialize the sensor pin as an input:
  pinMode(sensorPin, INPUT); 
  pinMode(4, INPUT);
  pinMode(8, OUTPUT);
  digitalWrite(8, HIGH);
  Serial.begin(9600); 
  
      
}

void loop(){
  // read the value from the sensor:
  int sensor_value = analogRead(sensorPin);

  if (sensor_value < 115) {
    // prints the value into the serial monitor
    Serial.print(sensor_value );
    // turn the LED on - this is just to show circuit is working
    digitalWrite(8, HIGH);
    // print to serial monitor
    Serial.println("-Light on");
    // turn the heatpad on
    digitalWrite(heatPin1, HIGH);
    // print to serial monitor
    Serial.println("-heat on");
    // delay for ease of reading
    delay(1000);
      r = digitalRead(4);
  if (r == HIGH && p == LOW && millis() - time > debounce) {
    if (state == HIGH)
      state = LOW;
    else 
      state = HIGH;
    time = millis();    
  }
  digitalWrite(8, state);
 
    
    
  } 
  else {
    // turn the heating off
    digitalWrite(heatPin1, LOW);
    
  }
}

Fix your formatting and you will quickly see the problem: you only print something when the sensor reading is <115 and you never switch off any LEDs.

Also give your pins good names declared as const byte variables, and use those instead of pin numbers.

I've made some adjustments, Still the sensor is not working, the led won't turn off when the sensor is touched, apologies it's probably something minor I'm just not seeing.

const int sensorPin = 4;     // the number of the sensor pin
const int heatPin1 =  10;      // the number of the LED pin

int in = 2;
int out = 4;
int state = HIGH;
int r;
int p = LOW;

unsigned long time = 0;
unsigned long debounce = 200;


// variables will change:


void setup() {
  // initialize the LED pin as an output:
  pinMode(heatPin1, OUTPUT);


  // initialize the sensor pin as an input:
  pinMode(sensorPin, INPUT);
  pinMode(4, INPUT);
  pinMode(8, OUTPUT);
  digitalWrite(8, HIGH);
  Serial.begin(9600);


}

void loop() {
  // read the value from the sensor:
  //make sure pads are off
  Serial.println("I'm off, thanks.");
  int sensor_value = (4);
 

  if (sensor_value < 15) {
    // prints the value into the serial monitor
    Serial.print(sensor_value );
    // turn the LED on - this is just to show circuit is working
    digitalWrite(8, HIGH);
    // print to serial monitor
    Serial.println("-Light on");
    // turn the heatpad on
    digitalWrite(heatPin1, HIGH);
    // print to serial monitor
    Serial.println("-heat on");
    // delay for ease of reading
    delay(1000);
    r = digitalRead(4);
    if (r == HIGH && p == LOW && millis() - time > debounce) {
      if (state == HIGH)
        state = LOW;
      else
        state = HIGH;
      time = millis();
    }
    digitalWrite(8, state);



  }
  else {
    // turn the heating off
    digitalWrite(heatPin1, LOW);

  }
}[code]

[/code]