Combining a touch sensor mpr121 with a heating element Peltier Teci


I am working on a project which implies a heating system. The idea is that when the touch sensor is touched (mpr121) then the heat on the Peltier Teci will turn on for a few seconds. I am in the process of making the code and need some help. So far the serial monitor shows that the touch sensor is being touched, but the heating element does not turn on. Thanks!!

#include <Wire.h>
#include “Adafruit_MPR121.h”

#ifndef _BV
#define _BV(bit) (1 << (bit))

int peltier = 4; //The N-Channel MOSFET is on digital pin 4
int power = 50; //Power level from 0 to 99%
int peltier_level = map(power, 0, 99, 0, 255); //This is a value from 0 to 255 that actually controls the MOSFET

// You can have up to 4 on one i2c bus but one is enough for testing!
Adafruit_MPR121 cap = Adafruit_MPR121();

// Keeps track of the last pins touched
// so we know when buttons are ‘released’
uint16_t lasttouched = 0;
uint16_t currtouched = 0;

void setup() {
pinMode(peltier, OUTPUT);

while (!Serial) { // needed to keep leonardo/micro from starting too fast!
// pinMode(MPR121, INPUT);


Serial.println(“Adafruit MPR121 Capacitive Touch sensor test”);

// Default address is 0x5A, if tied to 3.3V its 0x5B
// If tied to SDA its 0x5C and if SCL then 0x5D
if (!cap.begin(0x5A)) {
Serial.println(“MPR121 not found, check wiring?”);
while (1);
Serial.println(“MPR121 found!”);

void loop() {
// Get the currently touched pads
currtouched = cap.touched();

for (uint8_t i=0; i<12; i++) {
// it if is touched and wasnt touched before, alert!
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
Serial.print(i); Serial.println(“touched”);
// if it was touched and now isnt, alert!
// if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
// Serial.print(i); Serial.println(" released");
// }
if(currtouched = cap.touched()){

if(Serial.available() > 0)
float option =;
if(option == ‘a’)
power += 5;
else if(option == ‘z’)
power -= 5;

if(power > 99) power = 99;
if(power < 0) power = 0;

peltier_level = map(power, 0, 99, 0, 255);

Serial.print(" PLevel=");

analogWrite(peltier, peltier_level); //Write this new value out to the port

// reset our state
lasttouched = currtouched;

// comment out this line for detailed data from the sensor!

// debugging info, what
Serial.print("\t\t\t\t\t\t\t\t\t\t\t\t\t 0x"); Serial.println(cap.touched(), HEX);
Serial.print(“Filt: “);
for (uint8_t i=0; i<12; i++) {
Serial.print(cap.filteredData(i)); Serial.print(”\t”);
Serial.print(“Base: “);
for (uint8_t i=0; i<12; i++) {
Serial.print(cap.baselineData(i)); Serial.print(”\t”);

// put a delay so it isn’t overwhelming

Before you post your code (in code tags, obviously) please use the IDE’s auto format tool

float option =;
if(option == 'a')

Unusual choice of data type.

How do you know the Peltier doe not turn on? Have you looked at the signal with an oscilloscope. You are using a digital signal to switch a mosfet, have you looked at the signal on the gate of the mosfet? Do you know the Peltier is still functional?



Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Please edit your post to add code tags.

Also, post a wiring diagram (photo of a hand drawn diagram) showing how the Peltier is wired, and how it is powered. Typically a 12V 6-10 Ampere power supply is used.