Basic Andon System using Arduino Uno R3 and Python
Your First step to learn Industrial visualizations!
Components and supplies
1
LCD Display 2*16
3
3mm LED
1
10kOhm potentiometer
1
Arduino Uno R3
3
Resistor 220 ohm
1
Push Button
1
Piezo Buzzer
1
Breadboard and Wire Kit
Tools and machines
1
Soldering paste
1
Soldering Wire
1
Soldering Iron
Apps and platforms
1
Arduino IDE
1
Visual Studio Code 2024
Project description
Code
GUI
python
To be run on your PC
1import tkinter as tk 2from tkinter import messagebox 3import serial 4import threading 5 6# Serial communication setup 7ser = serial.Serial('COM5', 9600) # Update with your COM port 8ser.flushInput() 9 10# GUI setup 11root = tk.Tk() 12root.title("Andon System") 13 14# Colors 15NORMAL_COLOR = "green" 16ATTENTION_COLOR = "blue" 17CRITICAL_COLOR = "red" 18 19# Create labels for status display 20status_label = tk.Label(root, text="System Status", font=("Arial", 100)) 21status_label.pack(pady=20) 22 23status_message = tk.Label(root, text="Normal", font=("Arial", 70), fg=NORMAL_COLOR) 24status_message.pack(pady=20) 25 26# Function to update the GUI based on serial data 27def update_gui(): 28 while True: 29 if ser.in_waiting > 0: 30 line = ser.readline().decode('utf-8').strip() 31 if line == "ATTENTION": 32 status_message.config(text="Attention Needed", fg=ATTENTION_COLOR) 33 elif line == "CRITICAL": 34 status_message.config(text="Critical Error", fg=CRITICAL_COLOR) 35 elif line == "NORMAL": 36 status_message.config(text="Normal", fg=NORMAL_COLOR) 37 else: 38 status_message.config(text="Unknown Status", fg="gray") 39 root.update_idletasks() 40 root.update() 41 42# Run the update_gui function in a separate thread 43thread = threading.Thread(target=update_gui, daemon=True) 44thread.start() 45 46# Start the GUI loop 47root.mainloop()
Arduino System
cpp
To be uploaded to the Arduino Uno R3
1#include <LiquidCrystal.h> 2 3// Initialize the LCD with the pin numbers 4LiquidCrystal lcd(12, 11, 10, 9, 8, 7); // RS, E, D4, D5, D6, D7 5 6const int buttonAttentionPin = 2; // Button for Attention Needed 7const int buttonCriticalPin = 3; // Button for Critical Error 8const int buzzerPin = 4; // Buzzer connected to digital pin 4 9 10const int ledNormalPin = 13; // LED for Normal status 11const int ledAttentionPin = 5; // LED for Attention Needed status 12const int ledCriticalPin = 6; // LED for Critical Error status 13 14// State variables 15bool attentionState = false; 16bool criticalState = false; 17unsigned long lastBeepTime = 0; 18bool beepOn = false; 19 20void setup() { 21 Serial.begin(9600); // Start serial communication at 9600 baud 22 pinMode(buttonAttentionPin, INPUT_PULLUP); 23 pinMode(buttonCriticalPin, INPUT_PULLUP); 24 pinMode(buzzerPin, OUTPUT); 25 26 pinMode(ledNormalPin, OUTPUT); 27 pinMode(ledAttentionPin, OUTPUT); 28 pinMode(ledCriticalPin, OUTPUT); 29 30 lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows 31 lcd.setCursor(0, 0); 32 lcd.print(" System Status "); 33 lcd.setCursor(0, 1); 34 lcd.print(" Normal "); 35 36 noTone(buzzerPin); // Ensure buzzer is off initially 37 digitalWrite(ledNormalPin, HIGH); // Turn on Normal LED 38 digitalWrite(ledAttentionPin, LOW); // Turn off Attention LED 39 digitalWrite(ledCriticalPin, LOW); // Turn off Critical LED 40} 41 42void loop() { 43 static bool lastAttentionButtonState = HIGH; 44 static bool lastCriticalButtonState = HIGH; 45 46 bool currentAttentionButtonState = digitalRead(buttonAttentionPin); 47 bool currentCriticalButtonState = digitalRead(buttonCriticalPin); 48 49 // Handle Attention Needed Button 50 if (currentAttentionButtonState == LOW && lastAttentionButtonState == HIGH) { 51 // Button was pressed 52 if (!attentionState) { 53 attentionState = true; 54 criticalState = false; 55 lcd.setCursor(0, 0); 56 lcd.print("Attention Needed"); 57 lcd.setCursor(0, 1); 58 lcd.print(" Press button 2 "); 59 60 Serial.println("ATTENTION"); 61 digitalWrite(ledNormalPin, LOW); // Turn off Normal LED 62 digitalWrite(ledAttentionPin, HIGH); // Turn on Attention LED 63 digitalWrite(ledCriticalPin, LOW); // Turn off Critical LED 64 } else { 65 attentionState = false; 66 lcd.setCursor(0, 0); 67 lcd.clear(); 68 lcd.print(" System Status "); 69 lcd.setCursor(0, 1); 70 lcd.print(" Normal "); 71 72 Serial.println("NORMAL"); 73 noTone(buzzerPin); // Turn off buzzer 74 digitalWrite(ledNormalPin, HIGH); // Turn on Normal LED 75 digitalWrite(ledAttentionPin, LOW); // Turn off Attention LED 76 digitalWrite(ledCriticalPin, LOW); // Turn off Critical LED 77 } 78 delay(500); // Debounce delay 79 } 80 81 // Handle Critical Error Button 82 if (currentCriticalButtonState == LOW && lastCriticalButtonState == HIGH) { 83 // Button was pressed 84 if (!criticalState) { 85 criticalState = true; 86 attentionState = false; 87 lcd.setCursor(0, 0); 88 lcd.clear(); 89 lcd.print(" Critical Error "); 90 lcd.setCursor(0, 1); 91 lcd.print(" Press Button 1 "); 92 93 Serial.println("CRITICAL"); 94 digitalWrite(ledNormalPin, LOW); // Turn off Normal LED 95 digitalWrite(ledAttentionPin, LOW); // Turn off Attention LED 96 digitalWrite(ledCriticalPin, HIGH); // Turn on Critical LED 97 } else { 98 criticalState = false; 99 lcd.setCursor(0, 0); 100 lcd.clear(); 101 lcd.print(" System Status "); 102 lcd.setCursor(0, 1); 103 lcd.print(" Normal "); 104 105 Serial.println("NORMAL"); 106 noTone(buzzerPin); // Turn off buzzer 107 digitalWrite(ledNormalPin, HIGH); // Turn on Normal LED 108 digitalWrite(ledAttentionPin, LOW); // Turn off Attention LED 109 digitalWrite(ledCriticalPin, LOW); // Turn off Critical LED 110 } 111 delay(500); // Debounce delay 112 } 113 114 lastAttentionButtonState = currentAttentionButtonState; 115 lastCriticalButtonState = currentCriticalButtonState; 116 117 // Handle Buzzer for Attention and Critical States 118 if (attentionState || criticalState) { 119 unsigned long currentTime = millis(); 120 if (currentTime - lastBeepTime >= 1000) { // Change interval for beep 121 lastBeepTime = currentTime; 122 beepOn = !beepOn; 123 if (beepOn) { 124 tone(buzzerPin, attentionState ? 1000 : 2000); // Lower frequency for Attention, higher for Critical 125 } else { 126 noTone(buzzerPin); 127 } 128 } 129 } else { 130 noTone(buzzerPin); 131 } 132}
Downloadable files
System Connection
System Connection Visualization
Basic Andon System.png

Detailed Connection
Detailed Connection Visualization
photo_2024-08-03_05-29-04.jpg

Comments
Only logged in users can leave comments