Devices & Components
Arduino Uno Rev3
9V Battery Clip
Ultrasonic Sensor - HC-SR04 (Generic)
9V battery (generic)
Male/Female Jumper Wires
Jumper wires (generic)
Qunqi L298N Motor Drive Controller Board Module Dual H Bridge DC Stepper For Arduino
Hardware & Tools
Soldering iron (generic)
Hot glue gun (generic)
Software & Tools
Arduino IDE
Project description
Code
Code
arduino
Here is the code, put this in your Arduino software and upload it and the project should work!
1//made by milespeterson101 2//published on 6/17/2022 3//heres the code (: 4 5byte TP = 0b10101010; // Every other port receives the inverted signal 6void setup() { 7 DDRC = 0b11111111; // Set all analog ports to be outputs 8 9 // Initialize Timer1 10 noInterrupts(); // Disable interrupts 11 12 TCCR1A = 0; 13 TCCR1B = 0; 14 TCNT1 = 0; 15 OCR1A = 200; // Set compare register (16MHz / 200 = 80kHz square wave -> 40kHz full wave) 16 17 TCCR1B |= (1 << WGM12); // CTC mode 18 TCCR1B |= (1 << CS10); // Set prescaler to 1 ==> no prescaling 19 TIMSK1 |= (1 << OCIE1A); // Enable compare timer interrupt 20 21 interrupts(); // Enable interrupts 22} 23ISR(TIMER1_COMPA_vect) { 24 PORTC = TP; // Send the value of TP to the outputs 25 TP = ~TP; // Invert TP for the next run 26} 27void loop() { 28 // Code ends here (: 29}
Code
arduino
Here is the code, put this in your Arduino software and upload it and the project should work!
1//made by milespeterson101 2//published on 6/17/2022 3//heres the 4 code (: 5 6byte TP = 0b10101010; // Every other port receives the inverted signal 7void 8 setup() { 9 DDRC = 0b11111111; // Set all analog ports to be outputs 10 11 12 // Initialize Timer1 13 noInterrupts(); // Disable interrupts 14 15 TCCR1A 16 = 0; 17 TCCR1B = 0; 18 TCNT1 = 0; 19 OCR1A = 200; // Set compare register 20 (16MHz / 200 = 80kHz square wave -> 40kHz full wave) 21 22 TCCR1B |= (1 << 23 WGM12); // CTC mode 24 TCCR1B |= (1 << CS10); // Set prescaler to 1 ==> no prescaling 25 26 TIMSK1 |= (1 << OCIE1A); // Enable compare timer interrupt 27 28 interrupts(); 29 // Enable interrupts 30} 31ISR(TIMER1_COMPA_vect) { 32 PORTC = TP; // Send the 33 value of TP to the outputs 34 TP = ~TP; // Invert TP for the next run 35} 36void 37 loop() { 38 // Code ends here (: 39}
Downloadable files
Schematic
Here is the schematic for the project. This will help a lot!
Schematic

Comments
Only logged in users can leave comments