Why do I keep on frying my uno board?

I have fried about 3 boards already, can anyone help me sort out my situation.
Is there something Im missing in my connection? TIA

#include <Servo.h>
#include <Arduino.h>
#include <EEPROM.h>
#include <LiquidCrystal_I2C.h>

// Servo for dispensing cigars for the single brand
Servo brand0Servo;

// Pin assignments and declarations
const int brand0ButtonPin = 4; // Button for Brand 0
const int coinPin = 2;         // Pin connected to the coin mechanism

volatile int impulsCount = 0;  // Counter for coin mechanism impulses
float totalAmount = 0.0;       // Total amount inserted
int coinType = 0;              // Coin type based on impulses
float coinValue;               // Value of the detected coin

// Customizable brand name
const char *brand0Name = "Chesterfield"; // Set your brand name here

// Price for the cigar brand
const int brand0Price = 8;

// Coin pulse and value mapping
const int coinPulses[] = {1, 2, 5, 10};
const float coinValues[] = {1.0, 2.0, 5.0, 10.0};

// LCD object for displaying information
LiquidCrystal_I2C lcd(0x27, 16, 2);

unsigned long previousMillis = 0;    // Timer variable
const unsigned long interval = 3000; // 3-second interval
bool showExactAmount = true;         // Flag to toggle message

// Lookup function to get coin value based on the number of impulses
float lookup(int pulses) {
  for (int i = 0; i < sizeof(coinPulses) / sizeof(coinPulses[0]); i++) {
    if (pulses == coinPulses[i]) {
      return coinValues[i];
    }
  }
  return -1; // Return -1 if no match found
}

// Setup function initializes the hardware and displays the welcome message
void setup() {
  pinMode(brand0ButtonPin, INPUT_PULLUP);
  pinMode(coinPin, INPUT);

  attachInterrupt(digitalPinToInterrupt(coinPin), coinInterrupt, FALLING);

  brand0Servo.attach(9);  // Attach Brand 0 servo to pin 9
  brand0Servo.write(0);   // Set initial position for Brand 0

  lcd.init();
  lcd.clear();
  lcd.backlight();
  resetDisplay();

  Serial.begin(9600);
}

// Interrupt handler for the coin mechanism
void coinInterrupt() {
  impulsCount++;
}

// Main loop for handling user input and dispensing cigars
void loop() {
  unsigned long currentMillis = millis();

  // Toggle between messages every 3 seconds
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    showExactAmount = !showExactAmount;
    resetDisplay();
  }

  // Handle coin insertion and update total amount
  if (impulsCount > 0) {
    coinValue = lookup(impulsCount);
    if (coinValue > 0) {
      totalAmount += coinValue;
    }

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Total Balance:");
    lcd.setCursor(0, 1);
    lcd.print(totalAmount, 2);

    impulsCount = 0;
  }

  // Check button presses and provide feedback for zero or insufficient balance
  if (digitalRead(brand0ButtonPin) == LOW) {
    if (totalAmount == 0) {
      displayMessage("Insert Coin", 2000);
    } else if (totalAmount < brand0Price) {
      displayMessage("Add More Coins", 2000);
    }
  }

  // Dispense Brand 0 cigar if button is pressed and sufficient balance exists
  if (digitalRead(brand0ButtonPin) == LOW && totalAmount >= brand0Price) {
    dispenseCigar(brand0Servo, brand0Name, brand0Price);
  }
}

// Function to display a temporary message and revert to the original
void displayMessage(const char *message, int duration) {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(message);
  delay(duration);
  resetDisplay();
}

// Function to dispense cigars for a specific brand
void dispenseCigar(Servo &servo, const char *brandName, int price) {
  int cigars = totalAmount / price; // Calculate number of cigars to dispense

  for (int i = cigars; i > 0; i--) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Dispensing ");
    lcd.setCursor(0, 1);
    lcd.print(String(brandName) + " " + String(i));
   
    servo.write(80); // Rotate servo to dispense position
    delay(500);
    servo.write(0);  // Return servo to initial position
    delay(500);
    
  }

  // Reset total amount after dispensing
  totalAmount = 0.0;

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("   THANK YOU!");
  delay(2000);
  resetDisplay();
}

// Function to reset the LCD display to toggle messages
void resetDisplay() {
  lcd.clear();
  lcd.setCursor(0, 0);
  if (showExactAmount) {
    lcd.print("  Exact Amount");
    lcd.setCursor(0, 1);
    lcd.print("      ONLY!");
  } else {
    lcd.print("  Cigar Vendo");
    lcd.setCursor(0, 1);
    lcd.print("   NO MINORS!");
  }
}
1 Like

Are you powering your board with too much voltage? Because one resistor may not be enough and you'll have to use some formulas to figure out the right amount

Just the lcd and servo, could it be the servo is drawing too much voltage?

It does not draw voltage, it draws current :wink: You will need to check the specs of the servo.

How do you power the setup? From USB or from the barrel/Vin? For the latter, the current drawn by the servo might be too much for the onboard 5V regulator.

1 Like

I see an Uno, I see an LCD, a see a servo (being powered by the Uno, bad, bad, bad mistake) and a see a Thing in the upper right. An unlabeled Thing. An unlabeled Thing that runs on who know what voltage and is delivering a signal with who knows what voltage levels into the Uno.

What conclusions can we draw from this?

1 Like

I used 12v for the uno and another 12v for the coin slot.

the unlabeled thing is a 12v supply for the coin slot, is it preferable to run the servo from another supply? it's a mg90s servo

You might want to look up the stall (i.e. starting) current of an MG90S servo and ponder if asking the Uno to supply that much current is a wise idea.

You might also want to investigate the nature of the signal being sent from the 12V supply for the coin slot. Is it open collector or open drain, or is it sending 12V right into an unprotected input of the Uno?

that's what keeps on frying, it's the onboard 5v regulator.

that im not sure, just started using arduino for a beginner's project and have watched some tuts in yt, what's open drain and open collector?

You're putting 12V into a linear 5V regulator.

That's a 7V drop.

For every 100mA of current demand, the regulator must dissipate 700mW of heat.

The Uno by itself is going to take about 45mA.

The servo will take much, much, more each time it starts moving. More than an order of magnitude more.

There's no heatsink on that regulator.

Draw your own conclusions.

1 Like

Basic electronic concepts that you really should have mastered before just hooking things up and assuming that they'd work, I'm afraid.

Google is your friend. Look 'em up. And then check the datasheet for that coin thingy.

What ever this is, it is not a beginners project.

2 Likes

that make sense, it works fine when using the usb supply and excutes all commands accordingly and becomes weird like some commands are not executed properly and gets fried when using the 12v.

Welcome to the forum. Generally speaking, Arduino outputs give 5v output max, and they are not supposed to carry the load of a project. I could say, any project that can be connected to Arduino output pins and work, should be also able to work with a 220Ω in series with those output wires. The black wire that comes out of coin machine and connects to pin 4 via push button? What is that and what is the voltage output and resistance of that ? Also the blue wire. I do not know what it is but from one end it is seried witha 10kΩ which is fine but the other end of it directly connects to pin 2??

but it is, I assumed it's easy, turns out there's too much technical terms and skills I still need to get my project working.


Hello, I used this specific thread and image as reference

An image is not enough. Provide some part number for the coin machine and if you seen any wiring diagram anywhere, share the link

But as you found out it is not.

You can't even seem to finish your physical layout diagram, like the voltages on the top right hand thing and where they come from. Also that thing should have a label on it saying what it is.

To communicate a circuit in electronics you need to use a schematic. This might get you started.

Colin's Lab video on reading a schematic