Custom Train Control Using RF-Transmitted PWM
Developed custom train control using RF-transmitted PWM values for variable speed. Integrated colour and distance sensors boolean logic into motor functions, employing H-bridge connections for motor control.
Key Contributions
- Created logic for motor control from colour and ultrasonic sensors.
- Effectively used Arduino IDE to write, debug, and deploy code.
Responsibilities
- Wrote code logic, including variable speed control.
- Annotated the code with comprehensive comments.
- Presented a full code overview.
Key Skills Developed
- Optimised responsiveness by employing a bottom-level delay approach.
- Fixed a bug where the code would stop updating components.
- Handled exceptions in Arduino.
Annotated 3D Circuit
Each component or feature has its own void
function to optimise code readability. The definitions for these functions are shown in the annotation below. The full train and controller code calls these functions.
Annotated Train Code (Arduino Mega 2560)
void loop() {
if (radio.available()) {
radio.read(&xMap, sizeof(xMap));
radio.read(&yMap, sizeof(yMap));
radio.read(&button, sizeof(button));
float x = xMap;
float y = yMap;
if (x < -50) { // Dead zone buffer of 50
motorsbackward(x * -1); // Reverses speed if negative
} else if (x > 50) {
motorsforward(x); // x is the analog speed input
} else {
motorstop(); // Turns off motor if in buffer zone
}
switch (button) { // Button controls
case 1: // Short click
electro(); // Toggles electromagnet
break;
case 2: // Long click
smoker(); // Toggles atomiser
servo(); // Toggles servo
break;
default:
break;
} // Switch-case handles all edge conditions
}
delay(10); // Compromises reactiveness for power usage
}