State representatives invoked the memories of people killed in distracted driving crashes on Wednesday before voting 155-2 to pass a bill banning motorists from using handheld cellphones and electronic devices behind the wheel.

Parents of three victims — Katie Brannelly, Merritt Levitan and Jordan Cibley — were in the House chamber Wednesday afternoon while the bill was discussed.

Rep. John Rogers of Norwood said Brannelly studied child psychology and shortly before graduating college, "just three weeks prior to the promise of you going out and changing this world that needed your help," was struck by a distracted driver who didn't see her. That promise, Rogers said, was lost with Brannelly's life.

"Today, because of your memory, we have so much to gain," Rogers said.

Rep. John Barrett of North Adams said he wears a bracelet with the reminder to "text less, live more" in honor of Levitan, who was on a cross-country bike trip when she and other cyclists were hit by a driver who was texting.

Barrett said Levitan's parents forgave the driver and said their daughter would have forgiven him, too. "Those are the kind of people that are fighting to get this bill passed," he said.

Massachusetts in 2010 banned drivers from texting and emailing while driving, but stopped short of a full ban on hand-held use to make phone calls. Since 2010, many drivers have continued to text while driving or read emails or even surf the internet, leaving everyone vulnerable to preventable crashes.

In each of the last two sessions Senate has passed so-called hands-free device bills, and that branch plans to take up its own version of the bill on June 6. Senators have filed 28 amendments.

Rep. William Straus, a Mattapoisett Democrat who co-chairs the Transportation Committee, said that with widespread cellphone use, "a traffic hazard has exploded on the roads of the commonwealth and frankly around the country" over the last 10 to 15 years.

The bill prohibits the use of mobile electronic devices by drivers unless the device is being used in hands-free mode, with a single touch or swipe allowed to active hands-free operation. The restriction would not apply to public safety personnel or first responders performing their duties, and drivers could still use mobile electronic devices in certain emergency situations.

Violations would be punished by $100 for a first offense, $250 for a second offense, and $500 for third or later offenses.

The bill (H 3793) would take effect 90 days after becoming law, and Straus said between that date and the beginning of 2020, police officers would issue warnings instead of fines to anyone they pull over for violations.

The House bill would require annual analysis of racial and demographic identification of drivers issued citations during traffic stops. Such data is often already collected as part of a citation but not consistently studied, Straus said.

An amendment adopted by the House and sponsored by Rep. Chynah Tyler of Boston directs state public safety officials to investigate alternative methods for collection under a 2000 law, requiring officials to explore "the expansion of the data collection to include the race and gender of each individual subject to traffic stops, searches resulting from a traffic stop or frisks resulting from a traffic stop whether or not a Massachusetts Uniform Citation was issued." The amendment requires a report from the public safety secretary with investigation results and any recommended legislation, by Dec. 31, 2019.

Straus said some House lawmakers and members of the public have voiced concerns about the potential for racial profiling. He said the primary focus of the bill before the House Wednesday is making roads safer, but that the ways law enforcement officers interact with the public deserve a "wider conversation."

"There is, no doubt, a serious justice issue wider than just traffic stops, about the way in which uniformed officers or even plainclothes interact with the public," he said. "No one is ignoring that reality."

Rep. Norman Orrall of Lakeville said the bill's passage would save lives and mentioned concerns about the enforcement of seatbelts and child safety seat laws when those statutes were approved.

"Law enforcement doesn't want this bill to be abused," said Orrall, a former civil engineer who worked on traffic projects. "None of us want this bill to be abused. We must protect the freedoms and the safety of all of our citizens."

Reps. David DeCoste of Norwell and Peter Durant of Southwick voted against the bill.

Michael P. Norton contributed reporting.

Correction: An earlier version of this story incorrectly stated that Rep. Shawn Dooley voted against the bill. He voted for it.