Arduino 101-Based Smart Coffee Sorting System with Ultrasonic Sensors and Motor Control
View and Edit Project In Cirkit Designer
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
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
DC Motor
- Description: Standard DC motor.
- Pins: pin 1, pin 2
Micro Servo 9G
- Description: Small servo motor.
- Pins: GND, +5V, PWM
Ultrasonic Sensor
- Description: Sensor for measuring distance using ultrasonic waves.
- Pins: +VCC, Trigger, Echo, GND
9V Battery
- Description: Standard 9V battery for power supply.
- Pins: -, +
LED: Two Pin (red)
- Description: Red LED for indicating system status.
- Pins: cathode, anode
LED: Two Pin (green)
- Description: Green LED for indicating system status.
- Pins: cathode, anode
Resistor (200 Ohms)
- Description: Resistor with 200 Ohms resistance.
- Pins: pin1, pin2
Resistor (220 Ohms)
- Description: Resistor with 220 Ohms resistance.
- Pins: pin1, pin2
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
- GND: Connected to GND of Ultrasonic Sensor, Micro Servo 9G, and another Ultrasonic Sensor.
- D1/TX: Connected to anode of red LED.
- D13/SCK: Connected to anode of green LED.
- 5V: Connected to +VCC of Ultrasonic Sensor, +5V of Micro Servo 9G, and +VCC of another Ultrasonic Sensor.
- D12/MISO: Connected to PWM of Micro Servo 9G.
- D10 PWM/SS: Connected to IN4 of L298N DC motor driver.
- D9 PWM: Connected to IN3 of L298N DC motor driver.
- D8: Connected to Echo of Ultrasonic Sensor.
- D7: Connected to Trigger of Ultrasonic Sensor.
- D6 PWM: Connected to IN2 of L298N DC motor driver.
- D5 PWM: Connected to IN1 of L298N DC motor driver.
- D4: Connected to Trigger of another Ultrasonic Sensor.
- D2: Connected to Echo of another Ultrasonic Sensor.
DC Motor
- pin 1: Connected to OUT2 of L298N DC motor driver.
- pin 2: Connected to OUT1 of L298N DC motor driver.
Micro Servo 9G
- GND: Connected to GND of Arduino 101.
- +5V: Connected to 5V of Arduino 101.
- PWM: Connected to D12/MISO of Arduino 101.
Ultrasonic Sensor
- +VCC: Connected to 5V of Arduino 101.
- Trigger: Connected to D7 of Arduino 101.
- Echo: Connected to D8 of Arduino 101.
- GND: Connected to GND of Arduino 101.
Another Ultrasonic Sensor
- +VCC: Connected to 5V of Arduino 101.
- Trigger: Connected to D4 of Arduino 101.
- Echo: Connected to D2 of Arduino 101.
- GND: Connected to GND of Arduino 101.
9V Battery
- +: Connected to 12V of L298N DC motor driver.
- -: Connected to GND of L298N DC motor driver.
LED: Two Pin (red)
- anode: Connected to D1/TX of Arduino 101.
- cathode: Connected to pin1 of 200 Ohms resistor.
LED: Two Pin (green)
- anode: Connected to D13/SCK of Arduino 101.
- cathode: Connected to pin1 of 220 Ohms resistor.
Resistor (200 Ohms)
- pin1: Connected to cathode of red LED.
- pin2: Connected to pin2 of 220 Ohms resistor.
Resistor (220 Ohms)
- pin1: Connected to cathode of green LED.
- pin2: Connected to pin2 of 200 Ohms resistor.
L298N DC Motor Driver
- IN1: Connected to D5 PWM of Arduino 101.
- IN2: Connected to D6 PWM of Arduino 101.
- IN3: Connected to D9 PWM of Arduino 101.
- IN4: Connected to D10 PWM/SS of Arduino 101.
- OUT1: Connected to pin 2 of DC Motor.
- OUT2: Connected to pin 1 of DC Motor.
- OUT3: Connected to pin 2 of another DC Motor.
- OUT4: Connected to pin 1 of another DC Motor.
- 12V: Connected to + of 9V Battery.
- GND: Connected to - of 9V Battery.
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