Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino 101-Based Smart Coffee Sorting System with Ultrasonic Sensors and Motor Control

View and Edit Project In Cirkit DesignerImage of Arduino 101-Based Smart Coffee Sorting System with Ultrasonic Sensors and Motor Control

Circuit Documentation

Summary

This circuit is designed to control a coffee sorting system using an Arduino 101 microcontroller. The system includes ultrasonic sensors for detecting coffee beans, a servo motor for controlling a hopper door, DC motors for moving the coffee beans, and LEDs for indicating system status. The L298N motor driver is used to control the DC motors, and a 9V battery powers the motor driver.

Component List

  1. Arduino 101

    • Description: Microcontroller board based on the Intel Curie module.
    • Pins: A5/SCL, A4/SDA, AREF, GND, D13/SCK, D12/MISO, D11 PWM/MOSI, D10 PWM/SS, D9 PWM, D8, D7, D6 PWM, D5 PWM, D4, D3 PWM, D2, D1/TX, D0/RX, AIN, ioref, RESET, 3V3, 5V, VIN, A0, A1, A2, A3, ICSP MISO, ICSP SCK, ICSP MOSI
  2. DC Motor

    • Description: Standard DC motor.
    • Pins: pin 1, pin 2
  3. Micro Servo 9G

    • Description: Small servo motor.
    • Pins: GND, +5V, PWM
  4. Ultrasonic Sensor

    • Description: Sensor for measuring distance using ultrasonic waves.
    • Pins: +VCC, Trigger, Echo, GND
  5. 9V Battery

    • Description: Standard 9V battery for power supply.
    • Pins: -, +
  6. LED: Two Pin (red)

    • Description: Red LED for indicating system status.
    • Pins: cathode, anode
  7. LED: Two Pin (green)

    • Description: Green LED for indicating system status.
    • Pins: cathode, anode
  8. Resistor (200 Ohms)

    • Description: Resistor with 200 Ohms resistance.
    • Pins: pin1, pin2
  9. Resistor (220 Ohms)

    • Description: Resistor with 220 Ohms resistance.
    • Pins: pin1, pin2
  10. L298N DC Motor Driver

    • Description: Motor driver for controlling DC motors.
    • Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB

Wiring Details

Arduino 101

DC Motor

Micro Servo 9G

Ultrasonic Sensor

Another Ultrasonic Sensor

9V Battery

LED: Two Pin (red)

LED: Two Pin (green)

Resistor (200 Ohms)

Resistor (220 Ohms)

L298N DC Motor Driver

Code Documentation

#include <Servo.h>

// Pin definitions
const int hopperUltrasonicTrigPin = 4; // Updated to match circuit
const int hopperUltrasonicEchoPin = 2; // Updated to match circuit
const int sortingUltrasonicTrigPin = 7; // Updated to match circuit
const int sortingUltrasonicEchoPin = 8; // Updated to match circuit
const int motor1Pin = 9; // Updated to match circuit
const int motor2Pin = 10; // Updated to match circuit
const int hopperServoPin = 12; // Updated to match circuit
const int ledIndicatorPin = 13; // Updated to match circuit
const int idleSwitchPin = 10; // Ensure this is connected in the circuit

// Constants
const long noCoffeeShutdownTime = 300000; // 5 minutes in milliseconds
const long noSortingTimeout = 120000;    // 2 minutes in milliseconds
const int minDetectionDistance = 10;    // Minimum distance to detect coffee (in cm)

// Objects
Servo hopperServo;

// Variables
unsigned long lastCoffeeDetectedTime = 0;
unsigned long lastSortingDetectedTime = 0;
bool isMotorRunning = false;
bool isSystemRunning = true;

void setup() {
  pinMode(hopperUltrasonicTrigPin, OUTPUT);
  pinMode(hopperUltrasonicEchoPin, INPUT);
  pinMode(sortingUltrasonicTrigPin, OUTPUT);
  pinMode(sortingUltrasonicEchoPin, INPUT);
  pinMode(motor1Pin, OUTPUT);
  pinMode(motor2Pin, OUTPUT);
  pinMode(ledIndicatorPin, OUTPUT);
  pinMode(idleSwitchPin, INPUT_PULLUP); // Idle switch with pull-up resistor

  hopperServo.attach(hopperServoPin);
  hopperServo.write(0); // Initial position: Hopper door closed

  digitalWrite(motor1Pin, LOW);
  digitalWrite(motor2Pin, LOW);
  digitalWrite(ledIndicatorPin, HIGH); // LED on during system initialization
}

void loop() {
  if (digitalRead(idleSwitchPin) == HIGH) {
    stopMotors();
    closeHopperDoor();
    return; // System is idle
  }

  if (!isSystemRunning) return; // Halt all operations if the system is off

  bool hopperHasCoffee = detectCoffee(hopperUltrasonicTrigPin, hopperUltrasonicEchoPin);
  bool sortingHasCoffee = detectCoffee(sortingUltrasonicTrigPin, sortingUltrasonicEchoPin);

  if (hopperHasCoffee) {
    lastCoffeeDetectedTime = millis();
    openHopperDoor();
    start