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'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
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.
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.
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);
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);
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);
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,
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);
}
}
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]