Ibrahim M. Abdelsalam
Published © LGPL

Basic Andon System using Arduino Uno R3 and Python

Your First step to learn Industrial visualizations!

AdvancedShowcase (no instructions)4 hours405
Basic Andon System using Arduino Uno R3 and Python

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Resistor 220 ohm
Resistor 220 ohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
LED (generic)
LED (generic)
×3
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
Buzzer
Buzzer
×1
6-pin Header & Gender Changer (5-pack)
Digilent 6-pin Header & Gender Changer (5-pack)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Microsoft Visual Studio Code

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Solder Flux, Soldering
Solder Flux, Soldering

Story

Read more

Schematics

Diagram

Schematics

Code

GUI

Python
import tkinter as tk
from tkinter import messagebox
import serial
import threading

# Serial communication setup
ser = serial.Serial('COM5', 9600)  # Update with your COM port
ser.flushInput()

# GUI setup
root = tk.Tk()
root.title("Andon System")

# Colors
NORMAL_COLOR = "green"
ATTENTION_COLOR = "blue"
CRITICAL_COLOR = "red"

# Create labels for status display
status_label = tk.Label(root, text="System Status", font=("Arial", 100))
status_label.pack(pady=20)

status_message = tk.Label(root, text="Normal", font=("Arial", 70), fg=NORMAL_COLOR)
status_message.pack(pady=20)

# Function to update the GUI based on serial data
def update_gui():
    while True:
        if ser.in_waiting > 0:
            line = ser.readline().decode('utf-8').strip()
            if line == "ATTENTION":
                status_message.config(text="Attention Needed", fg=ATTENTION_COLOR)
            elif line == "CRITICAL":
                status_message.config(text="Critical Error", fg=CRITICAL_COLOR)
            elif line == "NORMAL":
                status_message.config(text="Normal", fg=NORMAL_COLOR)
            else:
                status_message.config(text="Unknown Status", fg="gray")
        root.update_idletasks()
        root.update()

# Run the update_gui function in a separate thread
thread = threading.Thread(target=update_gui, daemon=True)
thread.start()

# Start the GUI loop
root.mainloop()

Arduino System

C/C++
#include <LiquidCrystal.h>

// Initialize the LCD with the pin numbers
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);  // RS, E, D4, D5, D6, D7

const int buttonAttentionPin = 2;  // Button for Attention Needed
const int buttonCriticalPin = 3;   // Button for Critical Error
const int buzzerPin = 4;           // Buzzer connected to digital pin 4

const int ledNormalPin = 13;       // LED for Normal status
const int ledAttentionPin = 5;     // LED for Attention Needed status
const int ledCriticalPin = 6;      // LED for Critical Error status

// State variables
bool attentionState = false;
bool criticalState = false;
unsigned long lastBeepTime = 0;
bool beepOn = false;

void setup() {
  Serial.begin(9600); // Start serial communication at 9600 baud
  pinMode(buttonAttentionPin, INPUT_PULLUP);
  pinMode(buttonCriticalPin, INPUT_PULLUP);
  pinMode(buzzerPin, OUTPUT);
  
  pinMode(ledNormalPin, OUTPUT);
  pinMode(ledAttentionPin, OUTPUT);
  pinMode(ledCriticalPin, OUTPUT);

  lcd.begin(16, 2);  // Initialize the LCD with 16 columns and 2 rows
  lcd.setCursor(0, 0);
  lcd.print("  System Status  ");
  lcd.setCursor(0, 1);
  lcd.print("     Normal     ");

  noTone(buzzerPin); // Ensure buzzer is off initially
  digitalWrite(ledNormalPin, HIGH); // Turn on Normal LED
  digitalWrite(ledAttentionPin, LOW); // Turn off Attention LED
  digitalWrite(ledCriticalPin, LOW); // Turn off Critical LED
}

void loop() {
  static bool lastAttentionButtonState = HIGH;
  static bool lastCriticalButtonState = HIGH;

  bool currentAttentionButtonState = digitalRead(buttonAttentionPin);
  bool currentCriticalButtonState = digitalRead(buttonCriticalPin);

  // Handle Attention Needed Button
  if (currentAttentionButtonState == LOW && lastAttentionButtonState == HIGH) {
    // Button was pressed
    if (!attentionState) {
      attentionState = true;
      criticalState = false;
      lcd.setCursor(0, 0);
      lcd.print("Attention Needed");
      lcd.setCursor(0, 1);
      lcd.print(" Press button 2 ");

      Serial.println("ATTENTION");
      digitalWrite(ledNormalPin, LOW); // Turn off Normal LED
      digitalWrite(ledAttentionPin, HIGH); // Turn on Attention LED
      digitalWrite(ledCriticalPin, LOW); // Turn off Critical LED
    } else {
      attentionState = false;
      lcd.setCursor(0, 0);
      lcd.clear();
      lcd.print("  System Status  ");
      lcd.setCursor(0, 1);
      lcd.print("     Normal     ");

      Serial.println("NORMAL");
      noTone(buzzerPin); // Turn off buzzer
      digitalWrite(ledNormalPin, HIGH); // Turn on Normal LED
      digitalWrite(ledAttentionPin, LOW); // Turn off Attention LED
      digitalWrite(ledCriticalPin, LOW); // Turn off Critical LED
    }
    delay(500); // Debounce delay
  }

  // Handle Critical Error Button
  if (currentCriticalButtonState == LOW && lastCriticalButtonState == HIGH) {
    // Button was pressed
    if (!criticalState) {
      criticalState = true;
      attentionState = false;
      lcd.setCursor(0, 0);
      lcd.clear();
      lcd.print(" Critical Error ");
      lcd.setCursor(0, 1);
      lcd.print(" Press Button 1 ");

      Serial.println("CRITICAL");
      digitalWrite(ledNormalPin, LOW); // Turn off Normal LED
      digitalWrite(ledAttentionPin, LOW); // Turn off Attention LED
      digitalWrite(ledCriticalPin, HIGH); // Turn on Critical LED
    } else {
      criticalState = false;
      lcd.setCursor(0, 0);
      lcd.clear();
      lcd.print("  System Status  ");
      lcd.setCursor(0, 1);
      lcd.print("     Normal     ");

      Serial.println("NORMAL");
      noTone(buzzerPin); // Turn off buzzer
      digitalWrite(ledNormalPin, HIGH); // Turn on Normal LED
      digitalWrite(ledAttentionPin, LOW); // Turn off Attention LED
      digitalWrite(ledCriticalPin, LOW); // Turn off Critical LED
    }
    delay(500); // Debounce delay
  }

  lastAttentionButtonState = currentAttentionButtonState;
  lastCriticalButtonState = currentCriticalButtonState;

  // Handle Buzzer for Attention and Critical States
  if (attentionState || criticalState) {
    unsigned long currentTime = millis();
    if (currentTime - lastBeepTime >= 1000) { // Change interval for beep
      lastBeepTime = currentTime;
      beepOn = !beepOn;
      if (beepOn) {
        tone(buzzerPin, attentionState ? 1000 : 2000); // Lower frequency for Attention, higher for Critical
      } else {
        noTone(buzzerPin);
      }
    }
  } else {
    noTone(buzzerPin);
  }
}

Credits

Ibrahim M. Abdelsalam
1 project • 0 followers
Using my knowledge and experience to guide the new generations in making meaningful changes in the world.
Contact

Comments

Please log in or sign up to comment.