// // machine.ino - voltage rectifier and integrator circuit // for the DT009/1 EEPP build-a-machine project // Written by Ted Burke, 11-2-2019 // unsigned long t_start, t1, t2; int n; void setup() { pinMode(2, OUTPUT); pinMode(3, OUTPUT); Serial.begin(9600); for(n=0 ; n<3 ; ++n) { digitalWrite(3, HIGH); delay(200); digitalWrite(3, LOW); delay(800); } for(n=0 ; n<25 ; ++n) { digitalWrite(3, HIGH); delay(20); digitalWrite(3, LOW); delay(20); } digitalWrite(2, HIGH); digitalWrite(3, LOW); t_start = micros(); t1 = t_start; t2 = t_start; } void loop() { int v1, v2, v_rect; double Vs = 0; while(1) { v1 = analogRead(6); v2 = analogRead(7); v_rect = v1 > v2 ? v1 : v2; t2 = micros(); Vs += (t2 - t1) * 1e-6 * v_rect * (5.0 / 1023.0); t1 = t2; //Serial.print("0 1024 "); Serial.print(v1); Serial.print(" "); Serial.print(v2); Serial.print(" "); Serial.print(v_rect); Serial.print(" "); Serial.println(Vs); if (t2 - t_start > 10000000L) break; } digitalWrite(2, LOW); for(n=0 ; n<75 ; ++n) { digitalWrite(3, HIGH); delay(20); digitalWrite(3, LOW); delay(20); } while(1) { Serial.print("Integrated output voltage = "); Serial.print(Vs); Serial.println(" Vs"); digitalWrite(3, HIGH); delay(200); digitalWrite(3, LOW); delay(800); } }
Author: batchloaf
Coil Gun Competition Final Scoreboard
Review week: MOSFETs, flyback diodes, capacitors, oscilloscope, optical sensors – whiteboard snapshots
Introduction to op-amps – whiteboard snapshots
Design choices in coil gun project – whiteboard snapshots
Example Arduino circuit and program to pulse coil periodically
Controlling electrical loads with Arduino and MOSFET – whiteboard snapshots
Smuggler’s Challenge Final Scoreboard
Voltage divider fundamentals – whiteboard snapshots from lecture in KEG-036
Random voltage generation and current measurement for Smuggler’s Challenge
// // smugglers.cpp // Arduino Nano random voltage generator and 1 mA // current tester for EEPP Smugglers' Challenge. // // Written by Ted Burke, last updated 2-10-2018 // #include <Servo.h> Servo myservo; #define LEDPIN 2 #define PWMPIN 3 #define SERVOPIN 9 void setup() { // Generate random output voltage between (approximately) 0.5 and 2.0 V on pin D3 int vout; randomSeed(analogRead(0)); vout = random(25, 100); pinMode(PWMPIN, OUTPUT); analogWrite(PWMPIN, vout); // Red and green LEDs are both on pin D8 (set D8 high for green, low for red) pinMode(LEDPIN, OUTPUT); // Use internal 1.1 V voltage reference for analog input analogReference(INTERNAL); // The measured current is printed in mA Serial.begin(9600); // Initialise servo motor on pin D9 myservo.attach(SERVOPIN); } void loop() { float I_mA; // Calculate current from current sensing voltage on pin A7 I_mA = (2.0*1.1/1023.0)*analogRead(A7); // Print measured current Serial.print(I_mA); Serial.println(" mA"); // Check if measured current is within tolerance of target (1 mA) if (I_mA > 0.95 && I_mA<1.05) { // Light green LED and move servo to open position digitalWrite(LEDPIN, HIGH); myservo.write(45); } else { // Light red LED and move servo to closed position digitalWrite(LEDPIN, LOW); myservo.write(135); } // Update once every second delay(1000); }