Jose Romaní
Published © GPL3+

Qubits Simulator with Joystick

QUSIJOY allows to visualize the behavior of quantum bits with its superposition and entanglement once they collapase. It varies percentages.

AdvancedFull instructions provided340
Qubits Simulator with Joystick

Things used in this project

Hardware components

ELK-COGITI Material Para Curso COGITI
This is material for a course of collegiated engineers in Galicia (Spain) mainly. The kit cotaines a lot of components, not all necessary. In case someone prefers to buy components separately, I suggest the ones bellow
×1
LED (generic)
LED (generic)
×3
ELEGOO UNO R3 Board ATmega328P ATMEGA16U2 with USB Cable
ELEGOO UNO R3 Board ATmega328P ATMEGA16U2 with USB Cable
×1
ELEGOO 120pcs Multicolored Dupont Wire
ELEGOO 120pcs Multicolored Dupont Wire
×1
Resistor 221 ohm
Resistor 221 ohm
×3
Breadboard (generic)
Breadboard (generic)
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
One for stop/resume the software and one for entangled/not entagled qubits. This last can come with the joystick.
×2
Analog joystick (Generic)
Mine comes with a button but you can use a button separately for entangled/not entangled function
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

qubits_joystick - copy.fzz

Code

qubits_two_joystick_nov2020.ino

Arduino
/*qbits are in superposition and can be entangled
 * We substitute superposition by biased randomness and entanglement by a depending equation
 * Use joystick with pins pointing to South
 * When both qubits are entangled, collapse the first one for simplicity
 * Author: Jose Romaní from Vigo (Spain). 11/25/2020
*/
int aPercentOne, bPercentOne;
int aQubit, bQubit; //qubits
bool aCollapse = true, bCollapse; //select one qubit to collapse first in case of entanglement


#define doNothing 2

//#define LEDq2 6
#define LEDq1 7 //LEDs represent the state of qubits
#define LEDq0 8

#define X analogRead(A2)
#define Y analogRead(A1)

//switch under the joystick mushroom or alocated near
#define BUTTON_ENTANGLEMENT 3 //Interruption button. Entanglement/not entanglement
volatile bool entangled;

#define BUTTON 2  //stop/resume firmware
volatile bool state;

void setup() {
  randomSeed(analogRead(A0));
  Serial.begin(115200);
  
  attachInterrupt(digitalPinToInterrupt(BUTTON_ENTANGLEMENT), changeEntangled, RISING);
  entangled = false;

  attachInterrupt(digitalPinToInterrupt(BUTTON), changeState, RISING);
  state = false;
  
  pinMode(LEDq1, OUTPUT);
  pinMode(LEDq0, OUTPUT);
//  pinMode(LEDq2, OUTPUT);
  pinMode(BUTTON_ENTANGLEMENT, INPUT_PULLUP);
  pinMode(BUTTON, INPUT_PULLUP);
}  

void loop() {
  //stop/resume
  if (state){
    //switch off LEDs
    digitalWrite(LEDq0, LOW);
    digitalWrite(LEDq1, LOW);
//    digitalWrite(LEDq2, LOW); 
    delay(100);
    return;
  } 

  //joystick
  aPercentOne = map(Y, 0, 1023, 0, 100);
  bPercentOne = map(X, 0, 1023, 0, 100);
  
  //Serial Monitor
  Serial.println();
  Serial.print("aQubit:");
  printQubit(aPercentOne);
  Serial.print("bQubit:");
  printQubit(bPercentOne);
  
  //the following are the most interesting formulas of the present firmware
  //collapse qubits and show with LEDs
  //in case they are entangled, use the same formula for both
  entangled ? (bQubit = aQubit = (aCollapse ? collapse(aPercentOne) : collapse(bPercentOne))) : doNothing; //qubits entangled
  
  //not entangled, use different formulas
  !entangled ? (aQubit = collapse(aPercentOne)) : doNothing;
  !entangled ? (bQubit = collapse(bPercentOne)) : doNothing;
  
  //show by Serial Monitor
  Serial.print("ba = ");
  Serial.print(bQubit); digitalWrite(LEDq1, bQubit); //present the qubits by Serial Monitor and visually show by LEDs
  Serial.println(aQubit); digitalWrite(LEDq0, aQubit);
  delay(1000);
}
//Ex. percent of be a one: 25%
bool collapse(int percentOne) {
  return ((random(percentOne, 100 + percentOne) >= 100) ? 1 : 0);
}

void printQubit(int percentOne){
  
  Serial.println();
  //when qubits are |0> or |1>
  if (percentOne == 0 || percentOne == 100) {
    percentOne == 100 ? Serial.println("|1>") : doNothing;
    percentOne == 0 ? Serial.println("|0>") : doNothing;
  }
  else {
  Serial.print("((√");
  Serial.print(100-percentOne); //print percentages of first qubit
  Serial.print(")/10)|0> + ");
  Serial.print("((√");
  Serial.print(percentOne);
  Serial.print(")/10)|1>\n");
  }
}

void changeEntangled(){ //entangled/not entangled
  entangled = !entangled;
}

void changeState(){//stop/resume
  state = !state;
}

Credits

Jose Romaní
8 projects • 4 followers
Industrial Technical Engineer in Electronics and Automation
Contact

Comments

Please log in or sign up to comment.