Hard ware
ESP 32 - 1
TTP223 Touch sensor -1
12c LCD Display - 1
bread borad -1
jumper wires
Circuit |
|
---|---|
Touch Sensor 1 | to GPIO 14 (Next) |
Touch Sensor 2 | to GPIO 27 (Back) |
I2C LCD SDA | to GPIO 21 |
I2C LCD SCL | to GPIO 22 |
Code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define TOUCH_NEXT 14 // Touch Sensor 1 for Next Step
#define TOUCH_BACK 27 // Touch Sensor 2 for Previous Step
#define MAX_RECIPES 100
#define MAX_STEPS 5
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust address if needed
unsigned long lastTouchTime = 0;
int currentRecipe = 0;
int currentStep = 0;
// Example: 10 recipes, each with 5 steps
const char* recipes[MAX_RECIPES][MAX_STEPS] = {
{"Boil water", "Add rice", "Simmer 15min", "Drain water", "Serve hot"},
{"Heat pan", "Crack egg", "Flip egg", "Add salt", "Serve"},
{"Toast bread", "Apply butter", "Spread jam", "Cut in half", "Enjoy"},
{"Boil milk", "Add tea powder", "Simmer", "Add sugar", "Strain & serve"},
{"Chop veg", "Add oil", "Stir-fry", "Add spices", "Serve hot"},
{"Cut mango", "Add sugar", "Blend", "Chill in fridge", "Serve"},
{"Boil potato", "Mash with butter", "Add salt", "Mix well", "Serve"},
{"Grate carrot", "Add milk", "Boil", "Add sugar", "Cook till soft"},
{"Heat oil", "Add mustard", "Add curry leaves", "Add veg", "Cook and serve"},
{"Mix flour", "Add water", "Knead dough", "Roll flat", "Cook on tawa"}
};
void setup() {
pinMode(TOUCH_NEXT, INPUT);
pinMode(TOUCH_BACK, INPUT);
lcd.init();
lcd.backlight();
showStep();
}
void loop() {
if (millis() - lastTouchTime > 800) {
if (digitalRead(TOUCH_NEXT) == HIGH) {
nextStep();
lastTouchTime = millis();
} else if (digitalRead(TOUCH_BACK) == HIGH) {
previousStep();
lastTouchTime = millis();
}
}
}
void nextStep() {
currentStep++;
if (currentStep >= MAX_STEPS || recipes[currentRecipe][currentStep] == NULL) {
currentStep = 0;
currentRecipe++;
if (currentRecipe >= MAX_RECIPES || recipes[currentRecipe][0] == NULL) {
currentRecipe = 0;
}
}
showStep();
}
void previousStep() {
currentStep--;
if (currentStep < 0) {
currentRecipe--;
if (currentRecipe < 0 || recipes[currentRecipe][0] == NULL) {
// Go to last valid recipe
currentRecipe = getLastValidRecipe();
}
currentStep = getLastValidStep(currentRecipe);
}
showStep();
}
void showStep() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("R:");
lcd.print(currentRecipe + 1);
lcd.print(" Step:");
lcd.print(currentStep + 1);
lcd.setCursor(0, 1);
lcd.print(recipes[currentRecipe][currentStep]);
}
int getLastValidRecipe() {
for (int i = MAX_RECIPES - 1; i >= 0; i--) {
if (recipes[i][0] != NULL) return i;
}
return 0;
}
int getLastValidStep(int recipe) {
for (int i = MAX_STEPS - 1; i >= 0; i--) {
if (recipes[recipe][i] != NULL) return i;
}
return 0;
}
#include <LiquidCrystal_I2C.h>
#define TOUCH_NEXT 14 // Touch Sensor 1 for Next Step
#define TOUCH_BACK 27 // Touch Sensor 2 for Previous Step
#define MAX_RECIPES 100
#define MAX_STEPS 5
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust address if needed
unsigned long lastTouchTime = 0;
int currentRecipe = 0;
int currentStep = 0;
// Example: 10 recipes, each with 5 steps
const char* recipes[MAX_RECIPES][MAX_STEPS] = {
{"Boil water", "Add rice", "Simmer 15min", "Drain water", "Serve hot"},
{"Heat pan", "Crack egg", "Flip egg", "Add salt", "Serve"},
{"Toast bread", "Apply butter", "Spread jam", "Cut in half", "Enjoy"},
{"Boil milk", "Add tea powder", "Simmer", "Add sugar", "Strain & serve"},
{"Chop veg", "Add oil", "Stir-fry", "Add spices", "Serve hot"},
{"Cut mango", "Add sugar", "Blend", "Chill in fridge", "Serve"},
{"Boil potato", "Mash with butter", "Add salt", "Mix well", "Serve"},
{"Grate carrot", "Add milk", "Boil", "Add sugar", "Cook till soft"},
{"Heat oil", "Add mustard", "Add curry leaves", "Add veg", "Cook and serve"},
{"Mix flour", "Add water", "Knead dough", "Roll flat", "Cook on tawa"}
};
void setup() {
pinMode(TOUCH_NEXT, INPUT);
pinMode(TOUCH_BACK, INPUT);
lcd.init();
lcd.backlight();
showStep();
}
void loop() {
if (millis() - lastTouchTime > 800) {
if (digitalRead(TOUCH_NEXT) == HIGH) {
nextStep();
lastTouchTime = millis();
} else if (digitalRead(TOUCH_BACK) == HIGH) {
previousStep();
lastTouchTime = millis();
}
}
}
void nextStep() {
currentStep++;
if (currentStep >= MAX_STEPS || recipes[currentRecipe][currentStep] == NULL) {
currentStep = 0;
currentRecipe++;
if (currentRecipe >= MAX_RECIPES || recipes[currentRecipe][0] == NULL) {
currentRecipe = 0;
}
}
showStep();
}
void previousStep() {
currentStep--;
if (currentStep < 0) {
currentRecipe--;
if (currentRecipe < 0 || recipes[currentRecipe][0] == NULL) {
// Go to last valid recipe
currentRecipe = getLastValidRecipe();
}
currentStep = getLastValidStep(currentRecipe);
}
showStep();
}
void showStep() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("R:");
lcd.print(currentRecipe + 1);
lcd.print(" Step:");
lcd.print(currentStep + 1);
lcd.setCursor(0, 1);
lcd.print(recipes[currentRecipe][currentStep]);
}
int getLastValidRecipe() {
for (int i = MAX_RECIPES - 1; i >= 0; i--) {
if (recipes[i][0] != NULL) return i;
}
return 0;
}
int getLastValidStep(int recipe) {
for (int i = MAX_STEPS - 1; i >= 0; i--) {
if (recipes[recipe][i] != NULL) return i;
}
return 0;
}
How It Works
-
Each tap on the touch sensor shows the next step.
-
After the last step of a recipe, it switches to the next recipe.
-
After the last recipe, it loops back to the first.

0 Comments