This CPU scheduling control panel simulates six different process scheduling algorithms on an ESP32 microcontroller. The project demonstrates FCFS, SJF, SRTF, priority-based, and round-robin scheduling with real-time visualization of process execution states.
The guide provides a complete wiring diagram, parts list, and step-by-step assembly instructions for connecting the OLED display, potentiometer for mode selection, push buttons for control, and five indicator LEDs representing active processes. Builders will also receive the complete firmware to load onto the ESP32, enabling interactive exploration of how different scheduling algorithms handle process queues and execution timing.
Wiring diagram

Gather all the parts
Assemble it in 4 steps
1. Lay out the four panel sections
With USB unplugged, put the OLED at top left and the algorithm knob at top right. Leave a separate horizontal row for P1–P5 and a bottom row for START, PAUSE, STEP and RESET. Print those labels on the faceplate. Leave clearance behind the controls and keep the ESP32 USB port accessible.
2. Wire the display and knob
Connect both VCC pins to 3V3 and both GND pins to GND. Connect OLED SDA to GPIO21 (data), SCL to GPIO22 (clock), and knob WIPER to GPIO32 (position). Mark the six positions in order: FCFS, SJF, SRTF, Priority Non-preemptive, Priority Preemptive, Round Robin. Confirm the marks against the OLED before fixing them in place.
3. Wire the process lights
Route GPIO18, 19, 23, 25 and 26 through R1–R5 respectively to the long legs of P1–P5. Join the short legs to GND. Keep one 330-ohm resistor per light.
4. Wire the control buttons
Connect one contact from each button to GND. Connect the other contact of START, PAUSE, STEP and RESET to GPIO13, 14, 27 and 33 respectively. Run the ground wires along the edge and keep signal runs separated and labelled.
Review all connections
1. Connections between "STATUS" and "ESP32"
2. Connections between "R1" and "ESP32"
3. Connections between "P1" and "ESP32"
4. Connections between "R2" and "ESP32"
5. Connections between "P2" and "ESP32"
6. Connections between "R3" and "ESP32"
7. Connections between "P3" and "ESP32"
8. Connections between "R4" and "ESP32"
9. Connections between "P4" and "ESP32"
10. Connections between "R5" and "ESP32"
11. Connections between "P5" and "ESP32"
12. Connections between "ALGORITHM" and "ESP32"
13. Connections between "START" and "ESP32"
14. Connections between "PAUSE" and "ESP32"
15. Connections between "STEP" and "ESP32"
16. Connections between "RESET" and "ESP32"
Deploy the firmware
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
constexpr int N=5, Q=2;
constexpr int arrival[N]={1,2,3,7,10}, burst[N]={7,4,1,5,2}, priority[N]={4,2,1,3,2};
constexpr int led[N]={18,19,23,25,26};
const char* names[]={"FCFS","SJF","SRTF","PRIORITY NON-PREEMPT","PRIORITY PREEMPTIVE","ROUND ROBIN (Q=2)"};
Adafruit_SSD1306 screen(128,64,&Wire,-1);
struct Button {
int pin;
bool raw=false, stable=false;
uint32_t changed=0;
bool pressed(uint32_t now){
bool sample=digitalRead(pin)==LOW;
if(sample!=raw){raw=sample;changed=now;}
if(stable!=raw && now-changed>=25){stable=raw;return stable;}
return false;
}
};
Button keys[]={{13},{14},{27},{33}};
enum State {Ready,Running,Paused,Done};
State state=Ready;
int mode=0, candidate=0, t=0, left[N], active=-1, shown=-1;
int fifo[N], head=0, count=0, slice=0;
uint32_t selectionSince=0, lastTick=0;
bool dirty=true, displayOK=false;
void resetRun(){
for(int i=0;i<N;i++)left[i]=burst[i];
t=0; active=shown=-1; head=count=slice=0; state=Ready; dirty=true;
}
void enqueue(int i){fifo[(head+count)%N]=i; ++count;}
int rankOf(int i){
if(mode==1)return burst[i];
if(mode==2)return left[i];
if(mode==3 || mode==4)return priority[i];
return arrival[i];
}
void tick(){
if(mode==5){
// Arrivals at this boundary enter before a process whose quantum expired.
for(int i=0;i<N;i++)if(arrival[i]==t)enqueue(i);
if(active>=0 && slice==Q){enqueue(active);active=-1;}
if(active<0 && count){active=fifo[head];head=(head+1)%N;--count;slice=0;}
} else if(active<0 || mode==2 || mode==4){
// A preemptive policy keeps the current process on equal rank.
for(int i=0;i<N;i++)if(left[i] && arrival[i]<=t){
if(active<0 || rankOf(i)<rankOf(active))active=i;
}
}
shown=active;
if(active>=0){
++slice;
if(--left[active]==0)active=-1;
}
++t;
bool done=true;
for(int n:left)if(n)done=false;
if(done){state=Done;shown=-1;}
dirty=true;
}
void render(){
dirty=false;
for(int i=0;i<N;i++)digitalWrite(led[i],i==shown && (state==Paused || state==Running));
if(!displayOK)return;
const char* states[]={"READY","RUNNING","PAUSED","COMPLETE"};
screen.clearDisplay();screen.setTextColor(SSD1306_WHITE);screen.setTextWrap(false);
screen.setTextSize(1);screen.setCursor(0,0);screen.print(names[mode]);
screen.drawFastHLine(0,10,128,SSD1306_WHITE);
screen.setCursor(0,16);screen.setTextSize(2);
screen.print("T=");screen.print(t);screen.print(" ");
if(shown<0)screen.print("--");else {screen.print('P');screen.print(shown+1);}
screen.setTextSize(1);screen.setCursor(0,38);
screen.print("CPU: ");screen.print(state==Paused ? "HELD" : shown<0 ? "IDLE" : "BUSY");
screen.setCursor(0,53);screen.print("STATE: ");screen.print(states[state]);screen.display();
}
int selector(int previous){
int sum=0;for(int i=0;i<8;i++)sum+=analogRead(32);
int raw=sum/8;
if(previous>=0 && raw>=previous*4096/6-50 && raw<(previous+1)*4096/6+50)return previous;
return raw*6/4096;
}
void setup(){
for(int p:led){pinMode(p,OUTPUT);digitalWrite(p,LOW);}
for(auto &key:keys)pinMode(key.pin,INPUT_PULLUP);
analogReadResolution(12);
Wire.begin(21,22);
displayOK=screen.begin(SSD1306_SWITCHCAPVCC,0x3C,false,false);
mode=candidate=selector(-1);resetRun();
}
void loop(){
uint32_t now=millis();
int next=selector(candidate);
if(next!=candidate){candidate=next;selectionSince=now;}
if(candidate!=mode && now-selectionSince>=120){mode=candidate;resetRun();}
bool start=keys[0].pressed(now), pause=keys[1].pressed(now);
bool step=keys[2].pressed(now), reset=keys[3].pressed(now);
if(reset)resetRun();
else if(pause && state==Running){state=Paused;dirty=true;}
else if(step && (state==Ready || state==Paused)){state=Paused;tick();}
else if(start && state!=Running){if(state==Done)resetRun();state=Running;lastTick=now;dirty=true;}
if(state==Running && now-lastTick>=700){lastTick=now;tick();}
if(dirty)render();
delay(3);
}Remix this project
Make it yours in one click
Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.




