Participating in undergraduate research can be one of the best ways to explore possible majors, so no! You are definitely not restricted to a project within a declared major. We have many successful collaborations between students and faculty who are not in their major field. Sometimes the fields are related (like Psychology and Educational Psychology) and sometimes not. Students can bring some of their expertise from one area (like a language or technical ability) to a project in another field where that skill is an asset (for example, an Engineering student working with a faculty member in Art and Design on a 3D printing project). Or, some projects in another field may allow students to put into practice skills and theories they are learning (i.e. Psychology majors working on a Social Work project in a nursing home). Think broadly about getting involved, but the best case scenario is a project where you will gain valuable experience in reaching your long term educational and career goals.