r/Arduino_AI • u/Rhusko • Feb 20 '24
seesdadw
can someone help me program an reverse vending machine?? codes??
r/Arduino_AI • u/Rhusko • Feb 20 '24
can someone help me program an reverse vending machine?? codes??
r/Arduino_AI • u/Inside-Reference9884 • Mar 25 '24
i have written a code for arduino to run two motors via a l298n motor driver and a hc-o5 bluetooth module but when i send signal from my android device the motors are not working.
does anyone know about it ?
r/Arduino_AI • u/ripred3 • Dec 21 '24
Currently I'm really impressed with PearAI's editor and AI/chat assist, and the Cursor IDE too.
Curious to see what anyone else is using. I'm really looking forward to when these modern IDE's allow for local agents and complex workflow assistance.
I have to say, for radical changes that involve multiple files, Cursor is pretty amazing at getting everything right when you want to re-factor a large subsystem of a multi-file project.
r/Arduino_AI • u/xanthium_in • Jun 12 '24
r/Arduino_AI • u/ripred3 • Mar 04 '25
For those that didn't see the other post here is a link to a full `Checkers.ino` game and the main header file we also use today.
Today's game is Connect Four, using emoji's sent to the output Serial monitor for a nicer game interface, that you can play against the Arduino, or have the Arduino play both sides! 😀
Have Fun! Change it up.. Make your own thinking games..
ripred
Example Game Output:

ConnectFour.ino
/**
* ConnectFour.ino - Connect Four game implementation using Minimax library
*
* This sketch implements a Connect Four game that can be played:
* - Human vs. AI
* - AI vs. AI (self-play)
*
* The game interface uses Serial communication for display and input.
* Board visualization uses emoji symbols for better visual experience.
*
* March 3, 2025 ++tmw
*/
#include "Minimax.h"
// Constants for board representation
#define EMPTY 0
#define RED 1 // Human player
#define BLUE 2 // AI player
// Game configuration
#define MINIMAX_DEPTH 4 // Search depth for AI
#define MAX_MOVES 7 // Maximum possible moves (columns) for one position
// Board dimensions
#define ROWS 6
#define COLS 7
// Game modes
#define MODE_HUMAN_VS_AI 0
#define MODE_AI_VS_AI 1
// Game state - represents the board
struct ConnectFourState {
byte board[ROWS][COLS];
bool blueTurn; // true if it's blue's turn, false for red's turn
// Initialize the board with empty cells
void init() {
blueTurn = false; // Red goes first
// Initialize empty board
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLS; col++) {
board[row][col] = EMPTY;
}
}
}
};
// Move structure - for Connect Four, a move is just a column choice
struct ConnectFourMove {
byte column;
ConnectFourMove() : column(0) {}
ConnectFourMove(byte col) : column(col) {}
};
// Game logic implementation
class ConnectFourLogic : public Minimax<ConnectFourState, ConnectFourMove, MAX_MOVES, MINIMAX_DEPTH>::GameLogic {
public:
// Find the row where a piece would land if dropped in the given column
int findDropRow(const ConnectFourState& state, int col) {
for (int row = ROWS - 1; row >= 0; row--) {
if (state.board[row][col] == EMPTY) {
return row;
}
}
return -1; // Column is full
}
// Check if there's a win starting from a specific position
bool checkWin(const ConnectFourState& state, int startRow, int startCol, int piece) {
// Check horizontal
int count = 0;
for (int c = max(0, startCol - 3); c < min(COLS, startCol + 4); c++) {
if (state.board[startRow][c] == piece) {
count++;
if (count >= 4) return true;
} else {
count = 0;
}
}
// Check vertical
count = 0;
for (int r = max(0, startRow - 3); r < min(ROWS, startRow + 4); r++) {
if (state.board[r][startCol] == piece) {
count++;
if (count >= 4) return true;
} else {
count = 0;
}
}
// Check diagonal (top-left to bottom-right)
count = 0;
for (int i = -3; i <= 3; i++) {
int r = startRow + i;
int c = startCol + i;
if (r >= 0 && r < ROWS && c >= 0 && c < COLS) {
if (state.board[r][c] == piece) {
count++;
if (count >= 4) return true;
} else {
count = 0;
}
}
}
// Check diagonal (top-right to bottom-left)
count = 0;
for (int i = -3; i <= 3; i++) {
int r = startRow + i;
int c = startCol - i;
if (r >= 0 && r < ROWS && c >= 0 && c < COLS) {
if (state.board[r][c] == piece) {
count++;
if (count >= 4) return true;
} else {
count = 0;
}
}
}
return false;
}
// Check for a win more efficiently (check entire board)
bool hasWin(const ConnectFourState& state, int piece) {
// Horizontal check
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col <= COLS - 4; col++) {
if (state.board[row][col] == piece &&
state.board[row][col+1] == piece &&
state.board[row][col+2] == piece &&
state.board[row][col+3] == piece) {
return true;
}
}
}
// Vertical check
for (int row = 0; row <= ROWS - 4; row++) {
for (int col = 0; col < COLS; col++) {
if (state.board[row][col] == piece &&
state.board[row+1][col] == piece &&
state.board[row+2][col] == piece &&
state.board[row+3][col] == piece) {
return true;
}
}
}
// Diagonal check (top-left to bottom-right)
for (int row = 0; row <= ROWS - 4; row++) {
for (int col = 0; col <= COLS - 4; col++) {
if (state.board[row][col] == piece &&
state.board[row+1][col+1] == piece &&
state.board[row+2][col+2] == piece &&
state.board[row+3][col+3] == piece) {
return true;
}
}
}
// Diagonal check (top-right to bottom-left)
for (int row = 0; row <= ROWS - 4; row++) {
for (int col = 3; col < COLS; col++) {
if (state.board[row][col] == piece &&
state.board[row+1][col-1] == piece &&
state.board[row+2][col-2] == piece &&
state.board[row+3][col-3] == piece) {
return true;
}
}
}
return false;
}
// Evaluate board position from current player's perspective
int evaluate(const ConnectFourState& state) override {
// Check for terminal states first (wins)
if (hasWin(state, RED)) {
return state.blueTurn ? 10000 : -10000; // Perspective of current player
}
if (hasWin(state, BLUE)) {
return state.blueTurn ? -10000 : 10000; // Perspective of current player
}
int score = 0;
// Evaluate potential threats and opportunities
// For each cell, check how many pieces are in a row in each direction
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLS; col++) {
if (state.board[row][col] != EMPTY) {
continue; // Skip filled cells
}
// Create a temporary copy of state to modify
ConnectFourState tempState = state;
// Check potential for RED
tempState.board[row][col] = RED;
if (checkWin(tempState, row, col, RED)) {
score -= 100; // Potential win for RED
}
// Check potential for BLUE
tempState.board[row][col] = BLUE;
if (checkWin(tempState, row, col, BLUE)) {
score += 100; // Potential win for BLUE
}
}
}
// Favor center columns for better control
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLS; col++) {
if (state.board[row][col] == RED) {
// Penalize RED pieces (from BLUE's perspective)
// Value center columns more
score -= 3 * (COLS - abs(col - COLS/2));
} else if (state.board[row][col] == BLUE) {
// Reward BLUE pieces (from BLUE's perspective)
// Value center columns more
score += 3 * (COLS - abs(col - COLS/2));
}
}
}
// Invert score if it's red's turn (adjust for perspective)
return state.blueTurn ? score : -score;
}
// Generate all valid moves from the current state
int generateMoves(const ConnectFourState& state, ConnectFourMove moves[], int maxMoves) override {
int moveCount = 0;
// A move is valid if the column is not full
for (int col = 0; col < COLS && moveCount < maxMoves; col++) {
if (findDropRow(state, col) >= 0) {
moves[moveCount] = ConnectFourMove(col);
moveCount++;
}
}
return moveCount;
}
// Apply a move to a state, modifying the state
void applyMove(ConnectFourState& state, const ConnectFourMove& move) override {
// Find the lowest empty row in the selected column
int row = findDropRow(state, move.column);
if (row >= 0) {
// Place the piece
state.board[row][move.column] = state.blueTurn ? BLUE : RED;
// Switch turns
state.blueTurn = !state.blueTurn;
}
}
// Check if the game has reached a terminal state (win/loss/draw)
bool isTerminal(const ConnectFourState& state) override {
// Check if either player has won
if (hasWin(state, RED) || hasWin(state, BLUE)) {
return true;
}
// Check for a draw (board is full)
for (int col = 0; col < COLS; col++) {
if (findDropRow(state, col) >= 0) {
return false; // There's still at least one valid move
}
}
return true; // Board is full, it's a draw
}
// Check if the current player is the maximizing player
bool isMaximizingPlayer(const ConnectFourState& state) override {
// BLUE is the maximizing player (AI)
return state.blueTurn;
}
};
// Global variables
ConnectFourState gameState;
ConnectFourLogic gameLogic;
Minimax<ConnectFourState, ConnectFourMove, MAX_MOVES, MINIMAX_DEPTH> minimaxAI(gameLogic);
int gameMode = MODE_HUMAN_VS_AI; // Default to Human vs AI
// Function to display the board with emoji symbols
void displayBoard(const ConnectFourState& state) {
// Column numbers with emoji numbers for consistent spacing
Serial.println("\n 0️⃣ 1️⃣ 2️⃣ 3️⃣ 4️⃣ 5️⃣ 6️⃣");
for (int row = 0; row < ROWS; row++) {
Serial.print(" ");
for (int col = 0; col < COLS; col++) {
switch (state.board[row][col]) {
case EMPTY:
Serial.print("⚪"); // White circle for empty
break;
case RED:
Serial.print("🔴"); // Red circle
break;
case BLUE:
Serial.print("🔵"); // Blue circle
break;
}
Serial.print(" ");
}
Serial.println();
}
// Display column numbers again at the bottom with emoji numbers
Serial.println(" 0️⃣ 1️⃣ 2️⃣ 3️⃣ 4️⃣ 5️⃣ 6️⃣");
Serial.print(state.blueTurn ? "Blue's turn" : "Red's turn");
Serial.println();
}
// Function to get a move from human player
ConnectFourMove getHumanMove() {
ConnectFourMove move;
bool validMove = false;
while (!validMove) {
// Prompt for input
Serial.println("Enter column (0-6):");
// Wait for input
while (!Serial.available()) {
delay(100);
}
// Read the column
move.column = Serial.parseInt();
// Clear the input buffer
while (Serial.available()) {
Serial.read();
}
// Check if the column is valid
if (move.column < COLS) {
// Check if the column is not full
if (gameLogic.findDropRow(gameState, move.column) >= 0) {
validMove = true;
} else {
Serial.println("Column is full. Try another one.");
}
} else {
Serial.println("Invalid column. Please enter a number between 0 and 6.");
}
}
return move;
}
// Function to get AI move
ConnectFourMove getAIMove() {
Serial.println("AI is thinking...");
unsigned long startTime = millis();
ConnectFourMove move = minimaxAI.findBestMove(gameState);
unsigned long endTime = millis();
Serial.print("AI chose column: ");
Serial.println(move.column);
Serial.print("Nodes searched: ");
Serial.println(minimaxAI.getNodesSearched());
Serial.print("Time: ");
Serial.print((endTime - startTime) / 1000.0);
Serial.println(" seconds");
return move;
}
// Function to check for game over
bool checkGameOver() {
if (gameLogic.isTerminal(gameState)) {
displayBoard(gameState);
// Determine the winner
if (gameLogic.hasWin(gameState, RED)) {
Serial.println("Red wins!");
} else if (gameLogic.hasWin(gameState, BLUE)) {
Serial.println("Blue wins!");
} else {
Serial.println("Game ended in a draw!");
}
Serial.println("Enter 'r' to restart or 'm' to change mode.");
return true;
}
return false;
}
// Function to handle game setup and restart
void setupGame() {
gameState.init();
Serial.println("\n=== CONNECT FOUR ===");
Serial.println("Game Modes:");
Serial.println("1. Human (Red) vs. AI (Blue)");
Serial.println("2. AI vs. AI");
Serial.println("Select mode (1-2):");
while (!Serial.available()) {
delay(100);
}
char choice = Serial.read();
// Clear the input buffer
while (Serial.available()) {
Serial.read();
}
if (choice == '2') {
gameMode = MODE_AI_VS_AI;
Serial.println("AI vs. AI mode selected.");
} else {
gameMode = MODE_HUMAN_VS_AI;
Serial.println("Human vs. AI mode selected.");
Serial.println("You play as Red, AI plays as Blue.");
}
}
void setup() {
Serial.begin(115200);
while (!Serial) {
; // Wait for serial port to connect
}
randomSeed(analogRead(0));
setupGame();
}
void loop() {
// Display the current board state
displayBoard(gameState);
if (checkGameOver()) {
while (!Serial.available()) {
delay(100);
}
char choice = Serial.read();
// Clear input buffer
while (Serial.available()) {
Serial.read();
}
if (choice == 'r') {
setupGame();
} else if (choice == 'm') {
gameMode = (gameMode == MODE_HUMAN_VS_AI) ? MODE_AI_VS_AI : MODE_HUMAN_VS_AI;
setupGame();
}
return;
}
// Get and apply move based on game mode and current player
ConnectFourMove move;
if (gameMode == MODE_HUMAN_VS_AI) {
if (!gameState.blueTurn) {
// Human's turn (Red)
move = getHumanMove();
} else {
// AI's turn (Blue)
move = getAIMove();
delay(1000); // Small delay to make AI moves visible
}
} else {
// AI vs. AI mode
move = getAIMove();
delay(2000); // Longer delay to observe the game
}
// Apply the move
gameLogic.applyMove(gameState, move);
}r/Arduino_AI • u/Machiela • Dec 10 '23
Doubled in size since August. All we need now is more traffic, people! Get posting!
edit: locked due to constant bot posts.
r/Arduino_AI • u/hamna_hasan • Jul 24 '24
Hello everyone,
I am working with the Arduino Mega for the water enrichment project and need help. The project objective is as follows: Our objective is to create an HMI system for our piping and tank system prototype. This HMI system should display temperature, pressure, and O2/CO2 concentrations in water. The above sensors and motors are connected to a control system via the Arduino Mega. It should also be able to display an animation of the tank levels rising and falling as well as the piping systems filling up with gas and water. The issue is as follows: Our current touchscreen is the Nextion Basic 7'' HMI LCD Touch Display which is only able to support images not animations. For our project, we are looking for a touchscreen wherein we can create the animation ourselves and run it, while also being compatible with the Arduino Mega. I would appreciate some guidance on how to resolve this issue. Ultimately, we are looking for a touchscreen that supports creating animations/running animations and is also compatible with Arduino (if not compatible, then attachable to a module that is compatible with Arduino). Unfortunately, my team and I are under a deadline of one month so we cannot purchase screens outside of Canada.
Thank you so much for your help, I appreciate any advice on our issue.
Hamna
r/Arduino_AI • u/ripred3 • Dec 03 '24
r/Arduino_AI • u/Inside-Reference9884 • Oct 10 '24
What to do if my stm32f103c8t6 is not connecting to my laptop are there any methods that can I use to solve this problem.
r/Arduino_AI • u/Business-Constant540 • May 07 '24
i have this PID control that i wanna use to stabilize a drone, idc about flight right now, i just want it to spin the motors at 50% speed and then add the PID output to the base speed "
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#include <ArduPID.h>
Adafruit_MPU6050 mpu;
ArduPID controlRoll;
ArduPID controlPitch;
double rollSP = 0;
double pitchSP = 0;
double rollInput;
double pitchInput;
double rollOutput;
double pitchOutput;
// Initially set low PID values for smoother control
double rollP = 0.1;
double pitchP = 0.1;
double rollI = 0.0;
double pitchI = 0.0;
double rollD = 0.1;
double pitchD = 0.1;
const int esc1Pin = 17;
const int esc2Pin = 5;
const int esc3Pin = 18;
const int esc4Pin = 19;
int valanMax = 950;
int valanMin = 450;
void setup(void) {
Serial.begin(115200);
while (!Serial) {
delay(10); // Wait for serial monitor to open
}
// Attempt communication with MPU6050
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
// Initial motor spin at slightly above minimum (adjust if needed)
analogWrite(esc1Pin, valanMin + 10);
analogWrite(esc2Pin, valanMax - (valanMin + 10));
analogWrite(esc3Pin, valanMin + 10);
analogWrite(esc4Pin, valanMax - (valanMin + 10));
mpu.setAccelerometerRange(MPU6050_RANGE_16_G);
mpu.setGyroRange(MPU6050_RANGE_250_DEG);
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.println("");
delay(100);
pinMode(esc1Pin, OUTPUT);
pinMode(esc2Pin, OUTPUT);
pinMode(esc3Pin, OUTPUT);
pinMode(esc4Pin, OUTPUT);
controlRoll.begin(&rollInput,&rollOutput,&rollSP,rollP,rollI,rollD);
controlPitch.begin(&pitchInput,&pitchOutput,&pitchSP,pitchP,pitchI,pitchD);
}
void loop() {
// Base speed for 50% throttle with slight adjustment (optional)
const double baseSpeed = valanMin + (valanMax - valanMin) * 0.5 + 10;
// Read sensor data
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
// Calculate roll and pitch angles from accelerometer data
int gradosRoll = atan2(a.acceleration.y, a.acceleration.z) * RAD_TO_DEG;
int gradosPitch = atan2(-a.acceleration.x, a.acceleration.z) * RAD_TO_DEG;
// Optional gyro drift compensation (adjust values as needed)
g.gyro.x = g.gyro.x + 0.01;
g.gyro.y = g.gyro.y + 0.085;
// Set roll and pitch inputs for PID controller
rollInput = gradosRoll;
pitchInput = gradosPitch;
// Perform PID calculations to determine motor adjustments
controlRoll.compute();
controlPitch.compute();
// Calculate motor signal with base speed (adjusted for deadzone)
int motorSignal = map(rollOutput + pitchOutput + baseSpeed, -valanMax, valanMax, valanMin + 10, valanMax);
// Constrain motor signal within valid ESC range
motorSignal = constrain(motorSignal, valanMin + 10, valanMax);
// Set motor signals for each ESC with direction control
analogWrite(esc1Pin, motorSignal);
analogWrite(esc2Pin, valanMax - motorSignal);
analogWrite(esc3Pin, motorSignal);
analogWrite(esc4Pin, valanMax - motorSignal);
// Uncomment for debugging (optional)
Serial.print("Grados Roll:");
Serial.print(gradosRoll);
Serial.print(" Grados Pitch:");
Serial.print(gradosPitch);
Serial.print(" senal motor:");
Serial.println(motorSignal);
delay(100);
}
"r/Arduino_AI • u/vsc1234 • Oct 06 '24
Hello all! I'm a software engineer and new in Arduino, but I've been looking for ways to translate what I ask to an LLM into serial commands to the board.
In my setup, I use a local LLM (llama3 on this case) to process natural language input, which is then converted into serial commands that my Arduino board understands. The board responds with a red light for “no” and a green light for “yes.”
This project demonstrates how we can bridge the gap between human language and hardware, enabling real-time responses to simple questions. Maybe It opens up possibilities for more intuitive human-computer interaction.
Thank you all!
r/Arduino_AI • u/ripred3 • Feb 25 '25
The full project is now up on github! It's only 3 files: server.py, openai.yaml, and instructions.txt. The repository can be found here and will likely be changing often for a few weeks:
https://github.com/ripred/Arduino-Project-Manager-GPT
I will be making a video soon about what to do with these files and how to configure your own openAI account's Custom GPT if there's interest.
All the Best!
ripred
edit: If any of you use this to make your own version I'd love to see it posted here!
r/Arduino_AI • u/[deleted] • Apr 22 '24
How do i find an AI that can read neo r6 gos output and tell the user their location based on the data given
If there isn’t something like that available, how would I make my own
r/Arduino_AI • u/giults • May 13 '24
👋 Hey everyone, Giulia here, UX Lead at Arduino! 🌟
As part of our ongoing efforts to enhance user experience, our UX team is deep diving into understanding the challenges you encounter while using Arduino, especially in light of the exciting potential of AI. We're keen to learn how AI is revolutionising and how your coding and creation processes.
We'd love to hear from you! Your experiences and feedback are incredibly important to us. Would you mind sparing a few minutes to fill out this Survey?
We really appreciate your time and contribution.
Thanks for being a part of the Arduino community!
r/Arduino_AI • u/BreakfastKnown4433 • Oct 12 '23
r/Arduino_AI • u/TechInnovationsAkash • Oct 01 '24
Check out this new project ‼️‼️
r/Arduino_AI • u/yasinthadinuk • Dec 26 '23
r/Arduino_AI • u/Ok_Past8596 • Feb 16 '25
r/Arduino_AI • u/Shoddy-Return-680 • Nov 26 '23
r/Arduino_AI • u/ripred3 • Feb 21 '25
This all takes place live on my local hard drive and Arduino Nano. All of the files are left there for me to do whatever I want with, either open them in the real IDE, or chat more with the gpt to enhance it some more heh...
r/Arduino_AI • u/gm310509 • Nov 01 '23
r/Arduino_AI • u/[deleted] • Jan 24 '25
There are any tutorials or repos can help me ?
r/Arduino_AI • u/_EHLO • Nov 22 '23
Yet so simple, but powerfull; an in depth, well documented, full of features & examples, easy and efficient, new version of a neural network library implementation for MCUs. Wondering what you can do with it? here's an edge-example and here's a scientific article that used it. Find more at GitHub :D
r/Arduino_AI • u/ripred3 • Feb 26 '25
NOTE: As mentioned in earlier posts; In order to create your own Custom GPT on openAI's chatGPT website you must be logged in with a Plus ($20/month) or Pro ($200/month) account.
Update: These prerequisite tools need to be installed on your host machine and their paths need to be included in your system's PATH environment variable:
uvicorn
ngrok
arduino-cli
Also: The video is a little cropped at the bottom so here are the command lines to start the server:
uvicorn server:app --host 127.0.0.1 --port 8000 &That starts the server.py running locally on your localhost on port 8000 as a background process.
Then execute:
ngrok http 8000to start the tunneling of the local socket to a publicly visible URL you can use as shown in the video.
Here is a complete video showing how to create your own Custom GPT on openAI's chatGPT UI (not in the openAI Playground that's different) from scratch.
Give it whatever name and logo you want to. ChatGPT can make up a logo using Dall-E for you right there in the Custom GPT dashboard, just tell it what you want it to look like. 🥳
r/Arduino_AI • u/Graphicsminer • Dec 19 '23
We need for suggestions in game mechanics for AR games with the D-I-Y cardboard toys The future of cardboard toys is here.
Previous post https://www.reddit.com/r/toys/comments/18hkko7/update_cardboard_quadrapod_robot_wireless_version/
Follow us more on Discord: https://discord.com/invite/2AYgjHKQH6 Follow us more on Website: https://scabotoy.com/