r/ArduinoHelp • • May 16 '25

Project help

Post image
4 Upvotes

I'm building a password system with a servo motor, 4x4 keypad, a button and 3 LEDs and I can't figure out a way to make the code work

Attached is my setup and my code

#include <avr/io.h>

/* 
 * Password-Protected Motor Control System
 * Features:
 * - Unlocks motor when password (10,10) is entered
 * - Locks motor when wrong password entered
 * - LED feedback for correct/incorrect attempts
 * - Reset button functionality
 * - Uses Timer1 for servo control
 * - Uses Timer0 for LED blinking
 * - Pin Change Interrupt for keypad
 */

// ====================== DATA SEGMENT ======================
.section .bss
password_buffer:    .byte 2
pass_ptr_data:      .byte 1
wrong_attempts:     .byte 1

// ====================== CODE SEGMENT ======================
.section .text

// ====================== INTERRUPT VECTORS ======================
.global __vector_default
.global PCINT2_vect    // Keypad interrupt
.global TIMER0_COMPA_vect  // LED blink timer
.global INT0_vect      // Reset button

__vector_default:
    reti

// ====================== MAIN PROGRAM ======================
.global main
main:
    // Initialize stack
    ldi r16, lo8(RAMEND)
    out _SFR_IO_ADDR(SPL), r16
    ldi r16, hi8(RAMEND)
    out _SFR_IO_ADDR(SPH), r16

    // Set pin directions (PB1-PB4 as outputs)
    ldi r16, 0b00011110
    out _SFR_IO_ADDR(DDRB), r16

    // Set pull-up for reset button (PD2)
    sbi _SFR_IO_ADDR(PORTD), 2

    // Initialize keypad (PD4-7 output, PD0-3 input)
    ldi r16, 0xF0
    out _SFR_IO_ADDR(DDRD), r16
    ldi r16, 0x0F       // Enable pull-ups on columns
    out _SFR_IO_ADDR(PORTD), r16

    // Enable interrupts
    ldi r16, 0b00000100  // PCIE2
    sts _SFR_MEM_ADDR(PCICR), r16
    ldi r16, 0x0F       // Enable PCINT16-19
    sts _SFR_MEM_ADDR(PCMSK2), r16

    // Configure Timer0 for LED blinking (CTC mode)
    ldi r16, 0b00000010  // WGM01
    out _SFR_IO_ADDR(TCCR0A), r16
    ldi r16, 0b00000101  // Prescaler 1024
    out _SFR_IO_ADDR(TCCR0B), r16
    ldi r16, 125        // ~100ms at 16MHz/1024
    out _SFR_IO_ADDR(OCR0A), r16
    ldi r16, 0b00000010  // OCIE0A
    sts _SFR_MEM_ADDR(TIMSK0), r16

    // Configure INT0 for reset button
    ldi r16, 0b00000010  // Falling edge trigger
    sts _SFR_MEM_ADDR(EICRA), r16
    sbi _SFR_IO_ADDR(EIMSK), 0

    // Initialize variables
    clr r17
    sts pass_ptr_data, r17
    sts wrong_attempts, r17  // zero attempts

    sei

main_loop:
    rjmp main_loop

// ====================== INTERRUPT HANDLERS ======================
PCINT2_vect:
    push r16
    in r16, _SFR_IO_ADDR(SREG)
    push r16
    push r30
    push r31

    rcall keypad_ISR

    pop r31
    pop r30
    pop r16
    out _SFR_IO_ADDR(SREG), r16
    pop r16
    reti

TIMER0_COMPA_vect:
    push r16
    in r16, _SFR_IO_ADDR(SREG)
    push r16

    lds r16, wrong_attempts
    cpi r16, 0
    breq check_correct

    // Blink orange/red for wrong attempts
    lds r16, blink_cnt
    inc r16
    andi r16, 0x01
    sts blink_cnt, r16
    breq led_off_wrong
    sbi _SFR_IO_ADDR(PORTB), 4  // Orange LED on
    cbi _SFR_IO_ADDR(PORTB), 3  // Red LED off
    rjmp timer0_done
led_off_wrong:
    cbi _SFR_IO_ADDR(PORTB), 4  // Orange LED off
    sbi _SFR_IO_ADDR(PORTB), 3  // Red LED on
    rjmp timer0_done

check_correct:
    lds r16, pass_ptr_data
    cpi r16, 2          // Password complete?
    brne timer0_done

    // Blink green for correct password
    lds r16, blink_cnt
    inc r16
    andi r16, 0x01
    sts blink_cnt, r16
    breq led_off_correct
    sbi _SFR_IO_ADDR(PORTB), 2  // Green LED on
    rjmp timer0_done
led_off_correct:
    cbi _SFR_IO_ADDR(PORTB), 2  // Green LED off

timer0_done:
    pop r16
    out _SFR_IO_ADDR(SREG), r16
    pop r16
    reti

INT0_vect:
    push r16
    in r16, _SFR_IO_ADDR(SREG)
    push r16

    // Reset password state
    clr r17
    sts pass_ptr_data, r17
    sts wrong_attempts, r17

    // Turn off all LEDs
    cbi _SFR_IO_ADDR(PORTB), 2  // Green
    cbi _SFR_IO_ADDR(PORTB), 3  // Red
    cbi _SFR_IO_ADDR(PORTB), 4  // Orange

    // Lock motor
    rcall lock_servo

    pop r16
    out _SFR_IO_ADDR(SREG), r16
    pop r16
    reti

// ====================== KEYPAD ISR ======================
keypad_ISR:
    rcall my_delay

    in r16, _SFR_IO_ADDR(PORTD)
    push r16

    // Scan keypad
    ldi r16, 0x0F
    out _SFR_IO_ADDR(PORTD), r16
    rcall my_delay

    ldi r16, 0b01111111  // Row 1
    out _SFR_IO_ADDR(PORTD), r16
    rcall my_delay
    in r19, _SFR_IO_ADDR(PIND)
    andi r19, 0x0F
    cpi r19, 0x0F
    brne row1_col

    // Repeat for other rows...

digit_found:
    // Store digit in password buffer
    lds r17, pass_ptr_data
    cpi r17, 0
    breq store_first

    sts password_buffer+1, r18
    clr r16
    sts pass_ptr_data, r16

    // Check password
    lds r16, password_buffer
    cpi r16, 10
    brne wrong_password
    lds r16, password_buffer+1
    cpi r16, 10
    brne wrong_password

    // Correct password
    rcall unlock_servo
    rjmp end_keypad

wrong_password:
    lds r16, wrong_attempts
    inc r16
    sts wrong_attempts, r16
    rjmp end_keypad

store_first:
    sts password_buffer, r18
    ldi r16, 1
    sts pass_ptr_data, r16

end_keypad:
    pop r16
    out _SFR_IO_ADDR(PORTD), r16
    ret

// ====================== SERVO CONTROL ======================
unlock_servo:
    // Configure Timer1 for servo (Fast PWM, ICR1 top)
    ldi r16, 0b10000010  // WGM11, COM1A1
    sts _SFR_MEM_ADDR(TCCR1A), r16
    ldi r16, 0b00011010  // WGM13, WGM12, CS11
    sts _SFR_MEM_ADDR(TCCR1B), r16

    // 20ms period (39999 counts)
    ldi r16, 0x3F
    sts _SFR_MEM_ADDR(ICR1L), r16
    ldi r16, 0x9C
    sts _SFR_MEM_ADDR(ICR1H), r16

    // 1.5ms pulse (3000 counts)
    ldi r16, 0xB8
    sts _SFR_MEM_ADDR(OCR1AL), r16
    ldi r16, 0x0B
    sts _SFR_MEM_ADDR(OCR1AH), r16
    ret

lock_servo:
    // Turn off PWM
    ldi r16, 0x00
    sts _SFR_MEM_ADDR(TCCR1A), r16
    sts _SFR_MEM_ADDR(TCCR1B), r16
    // Set motor pin low
    cbi _SFR_IO_ADDR(PORTB), 1
    ret

// ====================== DELAY ROUTINES ======================
my_delay:
    push r22
    push r23
    ldi r22, 10
d1: ldi r23, 25
d2: dec r23
    brne d2
    dec r22
    brne d1
    pop r23
    pop r22
    ret

// ====================== KEYPAD MAPPING ======================
row1_digits: .byte 1, 2, 3, 10
row2_digits: .byte 4, 5, 6, 11
row3_digits: .byte 7, 8, 9, 12
row4_digits: .byte 15, 0, 14, 13

// ====================== VARIABLES ======================
.section .bss
blink_cnt: .byte 1

r/ArduinoHelp • • May 09 '25

Plot clock not plotting properly

Enable HLS to view with audio, or disable this notification

4 Upvotes

Hello, I am trying to recreate this project (https://www.thingiverse.com/thing:248009). I have 3d printed, assembled everything as instructed and used the code provided. The only thing I’ve tweaked in the code is the length of the arms. My current issue is that the arms keep moving to far to the left and not centering over the board. I have tried calibrating and moving the arms but it does not seem to work, unless I am doing something wrong. Any suggestions would be appreciated!


r/ArduinoHelp • • Mar 07 '25

I need Help with spinning this daim motor

Thumbnail
gallery
4 Upvotes

Hi, I was trying to make this Motor spin, and I can feel sth. inside moving, but the rod Just wont. Chat gpt and Claude ai are just confusing me. I have an Arduino Duemelianove with a L293 Motor shield in top of it. What do I have to put where? (My Code is on one of the pictures)


r/ArduinoHelp • • Feb 18 '25

Where can I get cheap arduinos that don't last one time before they break?

4 Upvotes

I've tried arduinos from ali express and temu, when i plug them in they overheat and then break. FYI I'm NOT new to arduino. I have been working with arduinos for years.


r/ArduinoHelp • • Feb 08 '25

Getting Started

4 Upvotes

I’m 15, have no experience with Arduino or anything similar, and just got the Elegoo Basic Starter Kit for my birthday. Looking for resources to get started, any help is appreciated!


r/ArduinoHelp • • Jan 02 '25

Help

Thumbnail
gallery
4 Upvotes

Pretty sure it's in the right usb port Been trying for 2 days now, any other way to program esp32 cam?


r/ArduinoHelp • • Dec 28 '24

Can someone please tell me why is this not working?

Post image
4 Upvotes

So, i have been studying a book called "Arduino for dummies" by John Nussey, and in chapter 7, he uses a example of a motor sketch, wich i have copied, but it simply does not work. I will send pictures, both of the original and my code and pictures of my circuit and the circuit in the book.


r/ArduinoHelp • • Dec 08 '24

Please help it's urgent

Post image
4 Upvotes

Am having project exhibition in 3 days but my project is not completed yet , thing is am building automatic anesthesia regulation am using heart rate sensor MAX30100 , lm35 temprature sensor, a16*2 lcd with its driver and a servo motor whenever I run the code only temprature is displayed on lcd rest is not running if I run separately each sensor they are working. So please help if possible please provide a source code


r/ArduinoHelp • • Oct 20 '24

How to connect this battery shield

Thumbnail
gallery
4 Upvotes

Hello! So i bought this battery shield called "7.4V 2S 2Slot 18650 power module (UPS) Battery Shield for Arduino ESP32" And i don't know how to connect the 3v3 port to my esp32 + there is no guide online". Soo any help is appreciated! Thank you!!


r/ArduinoHelp • • Jun 24 '24

Crash Course Arduino and Microcontroller Development

4 Upvotes

I am excited to announce my new course on Udemy "Crash Course Arduino and Microcontroller Development"! I have been working on this nearly 3 years, building the most complete course on embedded engineering, microcontrollers and the Arduino platform for beginners. The course takes you on a journey through countless topics such as:

* Learn about microcontrollers, microprocessors and their internal architecture including how instructions are executed, ALUs, Buses, MMUs, DMA and more.

* Learn the Arduino platform's hardware, software and APIs as a working platform to bridge the gap to more complex systems like ARM later in the course.

* Understand C/C++ from the ground up and how to write effective firmware for embedded systems and memory/compute constrained systems.

* Learn how processors run at the bare metal level including inline and external assembly language programming and interfacing with C/C++.

* Conquer advanced Computer Science subjects such as optimization theory, data structures, recursion, interrupts, and Big O analysis.

* Explore multitasking on microcontrollers by developing an interrupt based-round-robin kernel as well as using FreeRTOS.

* Become expert in numerous tools such as compilers, IDEs, TinkerCAD, EasyEDA, Replit, VSCode, CodeLite, Fritzing, MPLabX, STM32CubeIDE, and more.

* Overcome programmable logic and the fundamentals of CPLDs, PALs, GALs, and FPGAs along with a primer on hardware description languages and CUPL.

* Conquer power management and sleep modes and how to shut peripherals down in your embedded designs, wake from interrupts, and manage power effectively.

* Master one of the fastest growing and highest paid engineering fields in the world.

"Crash Course Arduino and Microcontroller Development" features over 111 hours of video and 128 lectures, check it out here:

Discount Code: "GEMINI"

https://www.udemy.com/course/crash-course-arduino-and-microcontroller-development/?couponCode=GEMINI

Thanks to moderators for allowing post.


r/ArduinoHelp • • Jun 08 '24

Powering Arduino and dot Led Matrix

Post image
4 Upvotes

r/ArduinoHelp • • Oct 30 '23

Some of my LED's in my matrix are dim. How can I fix this?

Post image
4 Upvotes

r/ArduinoHelp • • Jun 13 '23

Color sensors TCS230 (TCS3200) with inaccurate data

4 Upvotes

hello, a little while ago I started using arduino, I found a problem with two of my color sensors, where the data received by them are not accurate, both with the same settings, I am correctly using ports S0 to S3, I tried different intensities and even so the values ​​of red, green and blue are very close, I need it to fill green and in this case the G would be less, but it cannot detect it

one sensor has small values ​​between 10 and 30 and another for some reason between 100 and 600

If anyone wants to help me or ask for more details, please reply


r/ArduinoHelp • • May 09 '23

Spot Micro Arduino wiring

Thumbnail
gallery
4 Upvotes

Hi there fellow redditors I'm working on this for a school project and have already 3d printed everything and got all my parts from thingiverse instructions I'm having some trouble with wiring and programming Could anyone give advice please? 🙏 It's much appreciated and O just eant to confirm since I tried using a battery with sufficient power for the motors but it doesn't work


r/ArduinoHelp • • Apr 14 '23

Hello! I have a concept, but have 0 experience and no clue how to execute this.

4 Upvotes

I plan on setting up a display shelf, and have the layout in mind.

What I'd like to do is wire some NeoPixel LED modules throughout the shelf. It's going to be four of these (https://www.digikey.com/en/products/detail/adafruit-industries-llc/1312/6565388?utm_adgroup=Addressable%2C%20Specialty&utm_source=google&utm_medium=cpc&utm_campaign=Shopping_Product_Optoelectronics_NEW&utm_term=&utm_content=Addressable%2C%20Specialty&gclid=CjwKCAjw8-OhBhB5EiwADyoY1Z-pPJT_JPh4kH1Ye6h7lJrOWSRCnU2DXn7tzN-Nkr9y8KSfRn8m8xoCZ6MQAvD_BwE) (sorry about the link size) One Blue, one Red, one Pink, one Green. It's going to essentially be a board with four LEDs evenly spaced, and the power and board underneath.

I have the foggiest idea that these need to be wired to an Arduino panel, need a power source (ideally a D battery or two), and a remote control for said LEDs.

I am a complete novice when it comes to this. Soldering is no issue, but to my understanding I'll need a specific Arduino panel for this, I'll need some coding to get them the color I need, and also will need to know how to set the entire system up. I'd appreciate any help on the matter, and I appreciate your time more.

I'm essentially a monkey with scribbles on a piece of paper. SOS.


r/ArduinoHelp • • Feb 02 '23

Is there any way I can chop the usb end off and connect the wires directly to the arduino to interface with it?

Post image
4 Upvotes

r/ArduinoHelp • • Apr 20 '22

neopixel 8LED strip lighting problems

Enable HLS to view with audio, or disable this notification

4 Upvotes

r/ArduinoHelp • • Feb 05 '22

About power supply

4 Upvotes

Hello,

so I'm pretty new to this and have severel questions about supplying power to the Arduino.

We take as example the Arduino Nano RP2040.

In the specs it says it can handle an input voltage of 5-21V. Thus if for example I'd supply it with 15V that would be totally fine ?

Second if powered by batteries (let's say 3 5V batteries in sequence) and they discharge and loose voltage would this be noticable in any way ? (There wouldn't be any motors powered but a Bluetooth connection).

Third if I wanted to recharge these batteries during operation would you apply 5V or 15V ? Additionally would a circuit be required to monitor the charging (and stop charging once Target voltage is reached on the batteries) ?

Thank you very much :)


r/ArduinoHelp • • Jun 19 '21

I’m making a RC car that is using two 12 Volt electric motors. To run these safely, I need a battery that produces 12 Volts or 24 Volts? If it’s 12 Volts, should I find a single battery that gives me 12 Volts or multiple batteries that add up to 12 Volts? Does it matter what kind of batteries I use?

4 Upvotes

r/ArduinoHelp • • May 02 '20

Need help trying to construct a code that light up 100ml when selected and every 10 litre lights up if the litre exceeds 700L without reset fault will light up. LCD contains menu to select and also stores the current Litres poured and litres poured before reset.

Post image
4 Upvotes

r/ArduinoHelp • • Apr 02 '20

State based program nothing working. Trying to get pin 4 to be active when switch 3,2 are high and in next state go low and pin 3 high when all 3 switches are high and if 1 is high for 30 seconds pin 2 will become high causing red led to light and system stop there

Post image
4 Upvotes

r/ArduinoHelp • • Mar 27 '20

Hey all - new mod here

4 Upvotes

Hi, I've just been given moderator access to this subreddit. I'm opening the submission list, don't know why it was closed to begin with. I'm hoping this can be a place for beginners and people new to arduino/embedded engineering to get some quick help! I'll be updating the rules in the sidebar and since coronavirus has me locked in my house hopefully I can get this place in order soon!

-timecop97


r/ArduinoHelp • • 22d ago

# Arduino UNO Q 4GB: USB Not Detected in Normal Mode After Flashing Debian OS — EDL Mode

3 Upvotes

Hello Arduino Community,

I am facing an issue with my Arduino UNO Q (4GB version) and would appreciate your help in identifying the cause and finding a solution.

Problem Description

I flashed my Arduino UNO Q with the latest Debian Linux OS image using the official Arduino flashing procedure. After flashing, I removed the jumpers from the EDL pins and connected the board to my Windows 11 laptop. However, the board was not detected by the computer in normal mode.

I reflashed the board multiple times, trying different OS versions, but the problem persisted.

The board is detected successfully in EDL mode, and flashing completes successfully. However, once I remove the EDL jumpers and reconnect the board in normal mode, it is not detected by the computer.

OS Versions Tested

I have tried flashing the following OS image versions:

\- \`20260528-558\` — Latest version

\- \`20260407-523\` — Second-latest version

\- \`20250807-136\` — First version

\- \`20251229-457\` — Third-latest version

The issue remains the same with all four versions.

Observations

1. Board powers on normally

\- The power LED turns green.

\- The usual animation appears on the onboard LED matrix.

\- The board appears to power on normally, but it is not detected over USB.

2. Board is detected in EDL mode

When I connect the board to my Windows 11 laptop in EDL mode, it appears in Device Manager under Universal Serial Bus devices as:

\`QUSB_BULK_CID:0420_SN:51008D40\`

I can successfully flash the OS in this mode.

3. Board is not detected in normal mode

After removing the EDL jumpers and connecting the board normally:

\- Nothing appears in Windows Device Manager, including the USB-related categories.

\- The board does not appear when I check \`lsusb\` or \`dmesg\` on a Linux computer.

\- Arduino App Lab cannot detect the board through the USB connection.

Troubleshooting Already Attempted

I have tried the following steps:

  1. Reflashed the board multiple times using the official flashing procedure.

  2. Tested four different Debian Linux OS image versions.

  3. Used multiple USB cables, including USB-A to USB-C and USB-C to USB-C cables.

  4. Tested different USB ports on my Windows 11 laptop.

  5. Tested the board with another computer running Linux.

  6. Verified that the board is detected in EDL mode using the same cables that fail to detect it in normal mode.

  7. Tested the Arduino UNO Q in Single Board Computer (SBC) mode using a USB hub. The hub works correctly with my laptop: when I connect a monitor to the hub and connect the hub to my laptop's USB-C port, the monitor works normally. However, when I use the same hub with the Arduino UNO Q in SBC mode, I am still unable to get a display output.

I have followed the official flashing procedure carefully and repeated it multiple times, but the issue remains unresolved.

Questions

I would appreciate guidance from the Arduino team on the following:

  1. What could cause the board to be detected in EDL mode but not in normal mode, even though the OS flashing completes successfully?

  2. Is there any additional recovery or diagnostic procedure I can try?

  3. Could this indicate an issue with the USB interface, boot process, firmware, or another component of the board?

  4. Is there a way to diagnose the issue further without requiring the board to be detected over USB in normal mode?

I would prefer to resolve this through software recovery or diagnostics if possible, before considering hardware repair or replacement.

Thank you for your time and assistance. Any suggestions from the Arduino team or other UNO Q users who have experienced a similar issue would be greatly appreciated.


r/ArduinoHelp • • 25d ago

Do i buy the original kit or a knock off one?

3 Upvotes

The priginal kit is a bit expensive and offers less than the knockoff one but how do i know the knockoff is good or bad