IR sensors not working when connected via batteries - Page 1
Forum section: electronics / beginners

author: BialaStrzala
author_rank: Newbie
timestamp: May 24, 2025, 05:38:26 pm
content: Hello! Thank you so much in advance. I'm making a scuffed line-follower robot and have encountered an issue where the IR sensors (Cytron Maker Reflect) work correctly when the STM32 is powered by a cable to my laptop, but break and read '4095' all over when powered by the batteries (7.4V). Both times they should be powered with 5V (either by L298N's 5V output or the step-down's 5V out; when connected by cable, both the step-down and L298N are powered still).I have already tried: connecting both sensors to be powered from the step-down (no change), powering one sensor from the STM 3V pin (sensor read values ~3000 but did not register changes no matter what), messing around with how GND is connected (L298N--STM GND connection doesn't seem to do anything; connecting sensors' GND to either STM or L298N or the step-down yields no changes)I'm stumped by the behaviour (and how to fix it) and was wondering if anyone has any ideas!

author: Buriedcode
author_rank: Super Contributor
timestamp: May 24, 2025, 07:50:56 pm
content: If you're constantly reading max value (4095 for 12-bit) then it sounds like there is no ground connnection to the sensors.I noticed you're using those "dupont" cables (they're not really dupont, but thats for another thread!) -sometimes these are poorly made and don't make a great connection, and can be a bugger to debug because its intermittent. Any "loose" fitting sockets over pins, ditch them.If the IR sensors are the standard type with an IR LED and a phototransistor with a pullup, these often have the LED connected across the supply, so it's always "on" when the module is powered. Use the camera on your phone to see if the IR LED is on - phone cameras have an IR filter, but it doesn't block IR 100%, and is usually enough to see if an IR LED is emitting - but it'll be very dim, compared to say, a TV remote that is driven with very high current.If the LED is always on when you wiggle the cables, then I guess that module is getting enough power.Second thing to check - your step-down module. I never trust these as they tend to be very noisy, and often have a under valued output cap. (edit: I dont' mean all step-down converters, just the one you're using!)So I would run the above test with either the step down powering it, or, powered from the 5V (or 3.3V?) out of the STM32 with nothing else ocnnected to the module - just power source and module.

author: ledtester
author_rank: Super Contributor
timestamp: May 24, 2025, 08:05:56 pm
content: I would find the simplest circuit which doesn't work for you.I.e. - initially just use the battery, the microcontroller board and the sensors -- get rid of everything else.If that works, then start adding in the other components -- one at a time.Knowing what component breaks things - or what configuration change breaks things - will be very helpful in tracking down the problem.

author: kjr18
author_rank: Regular Contributor
timestamp: May 27, 2025, 06:44:39 am
content: Try cleaning your ground wires. Connect sensor ground and bluetooth to stm, and battery ground to dcdc and motor driver. And those cables can be very loose fitting, so only those that are tight fitting. You could also try testing those cables before using them, some of them are poorly crimped, some even use steel instead copper.

author: ahsrabrifat
author_rank: Regular Contributor
timestamp: May 28, 2025, 07:37:29 am
content: To me, it looks like the 7.4 V battery pack is not being able to supply sufficient current to your whole setup. Try to power up your STM32 and other components with two different power sources, keeping the grounds shorted. Also, check the continuity of all the jumper wires that you are using. If you have an arduino, you can test all of the components separately in that platform. Here is a code and circuit of a line follower robot with Arduino:https://www.theengineeringprojects.com/2016/09/line-following-robot-using-arduino.htmlYou can use this to cross-check your IR sensors and Motors.Here is also another STM32-based line follower robot tutorial that you may get some idea from:https://github.com/sametoguten/STM32-Line-Follower-with-PID