Making Arduino Robot - Page 1
Forum section: electronics / beginners

author: Larsson55
author_rank: Regular Contributor
timestamp: March 16, 2025, 09:40:12 am
content: I got the attached schematic to make a small robot from a Facebook post. It's a nice project to continue learning Arduino and Electronics.The schematic is asking for a 12V battery which I don't have. Would a 9V battery be ok?I have all the parts except the 2 motors and I found them including the wheels but they only are available in 3-6V. Is this acceptable?Thanks

author: Ian.M
author_rank: Super Contributor
timestamp: March 16, 2025, 10:19:19 am
content: A L298 H-bridge uses bipolar technology so has quite high voltage drop. With a 9V supply a 6V motor will get fairly close to its nominal voltage. However the rest of the schematic has issues - the Arduino on-board 5V regulator isn't suitable for high current loads and needs over 6V at Vin (7V min. recommended) to stay in regulation with 5V out, so wiring the servo to Arduino 5V is not going to work well, and risks crashing the Arduino when it moves. The fix is to run the servo from the 5V output of the L298 board which has a beefier regulator, and also feed Arduino Vin from your +9V battery voltage, not the L298 board 5V output.

author: brucehoult
author_rank: Super Contributor
timestamp: March 16, 2025, 10:39:52 am
content: If you have a regulated 5V source (which you do, in the L298) then it's ok to power the Arduino from its 5V pin, not the Vin pin, bypassing the regulator and any voltage drop.

author: RoGeorge
author_rank: Super Contributor
timestamp: March 16, 2025, 10:40:26 am
content: If your 9V battery is a6F22, that might be too weak to drive all the motors, it will discharge in only a couple of minutes.Would be better to use something bigger, for example 6...8 AA batteries in series (preferably rechargeable) in a battery holder like these:https://duckduckgo.com/?t=ffab&q=8+AA+battery+holder&iax=images&ia=images

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 16, 2025, 11:11:38 am
content: Instead of the L298 motor driver one could also use the MX1508 motor driver. Has less voltage drop.https://electropeak.com/learn/interfacing-mx1508-motor-driver-module-with-arduino/Lots of other examples using this board can be found.I second both Ian.M and brucehoult on the supply of the Arduino board. But do make sure that the 5V regulator on the Arduino board you have can handle 5V on its output without any supply on the input. Not every regulator can deal with this.https://www.arduino.cc/en/uploads/Main/arduino-uno-schematic.pdfhttps://www.onsemi.com/download/data-sheet/pdf/mc33269-d.pdfBe aware that using Vin provides cutoff of the Vusb supply, where as using the +5V as input this is not the case, and when using the USB connection on a computer this might cause problems.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 16, 2025, 02:43:32 pm
content: Thank you to all for the help but I made a mistake, I don't have the L298N motor driver and instead I have what is shown in the attached. If the L298N is required I can buy it or any other suggestion.

author: Ian.M
author_rank: Super Contributor
timestamp: March 16, 2025, 02:48:45 pm
content: Personally I don't like BruceHolt's solution of powering the Arduino Uno via its 5V pin. In addition to it back feeding USB Vbus as Pcprogrammer mentioned (which can be bad for your PC), you also loose the opportunity to separate sensor +5V (which the Arduino on-board regulator can easily supply) from actuator +5V (i.e. servo power). Servos can draw very large current spikes when a sudden position change is commanded - I have had that dip the power rail of a MCU enough to cause it to reset till I separated their +5V feeds - so it makes more sense to power that from the regulator on the H-bridge board. As it is a 'dumb' H-bridge (i.e. no internal sequence logic), glitches on its 5V rail wont bother it. The Arduino regulator is rated for 7V-12V Vin, and that's easy enough to provide with a 9V battery pack - in the case of the Arduino buggy robot on my shelf, a 6x Alkaline AA battery holder.RoGeorge has a good point, a PP3 aka 6F22 9V battery cant sensibly power a buggy robot. It cant provide enough current and its output voltage will probably collapse if you try to move the servo fast or accelerate the motors hard or ever run for more than a few minutes. Either use six alkaline AAs, eight NiMH or a 3S LIPO pack!Unfortunately a ULN2003 isn't suitable for the application as it can only drive its outputs low, so is only suitable for driving relays, small lights, unipolar stepper motors and non-reversing small DC motors. Even if you had stepper motors as wheel motors, using it would vastly complicate the code. You need a H-bridge to be able to drive one output high and the other low for reversible DC motors.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 16, 2025, 07:34:57 pm
content: Thank you Ian for your time,Unfortunately my knowledge in electronics is very limited and after I finished working on the Elegoo super starter kit I thought this robot project will also be easy to put it together however it looks like I was wrong.Is it possible / easy to tell me what I need to buy to do the robot project or better I should forget about it?Many thanks

author: Ian.M
author_rank: Super Contributor
timestamp: March 16, 2025, 08:35:43 pm
content: So you've got the Arduino Uno, the ultrasonic sensor and the servo, but don't yet have the L298N motor driver, the geared motors and wheels, or a suitable battery. Do you have all the chassis parts you need, the caster for the tailwheel and a whole bunch of M3 nuts, screws and standoffs?If so, the bare minimum is the geared motors and wheels, a L298N module to drive them, a 6xAA battery holder (+12 Alkaline AA cells - two sets - from a dollar store), a 3A SPST rocker switch + enough good quality real copper DuPont jumper wires to wire everything together. If you need to buy the motors and mechanical parts anyway, you may get a better deal by buying a complete kit even though you already have an arduino, servo motor and ultrasonic sensor. Be careful to choose a kit with a 6 cell (9V) or 8 cell (12V) battery holder as the common 4 cell (6V) holder kits under voltage the Arduino and die with the batteries only a little bit used, so are very expensive to run. Better kits come with a breakout shield for the Arduino which makes them much easier to connect. The kit I bought came with this shield:https://protosupplies.com/product/sensor-shield-v5-0/This kit is basically what you are looking for:https://www.amazon.com/Chassis-Ultrasonic-Tutorial-Building-Electronic/dp/B0D32KF3H7Note that I had to buy two encoder sensors to measure the wheel speeds so I could make it drive straight. The kit has the encoder wheels to go on the inside ends of the motor shafts and the slots and holes in the chassis to mount the encoder sensors but doesn't come with them.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 16, 2025, 09:31:09 pm
content: The kit sound good Ian and I will buy it but how about the two encoder sensors? How do i order them. Perhaps another similar kit may include them?

author: Ian.M
author_rank: Super Contributor
timestamp: March 16, 2025, 09:46:31 pm
content: This is the type of optosensor I used:https://www.amazon.com/SHUATI-Measuring-Counter-Optocoupler-Testing/dp/B0CQ2F17ZTSearch keywords:LM393 opto speed sensorShop around for the best deal including shipping. You only need two, but no one seems to sell them in pairs!Also note that actually using the sensors for motor speed control will get you into some quite heavy programming. Seehttps://www.arrow.com/en/research-and-events/articles/pid-controller-basics-and-tutorial-pid-implementation-in-arduinoYou'll need to run two PID control loops + an overall control loop that compares the pulse count from each sensor and tweaks the PID speed targets to keep it running straight. Doing controlled angle turns adds another layer of complexity.IMHO, get the basic buggy running with manual control (maybe by an analog joystick on a long cable) before worrying about adding the speed sensors.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 16, 2025, 09:57:33 pm
content: Thanks, I will search for (2) LM393 opto speed sensors from Amazon.CA, shipping cost is less

author: Larsson55
author_rank: Regular Contributor
timestamp: March 16, 2025, 10:06:25 pm
content: Sorry Ian, is speed encoder and speed sensor the same? Perhaps speed encoder includes the sensors?

author: Ian.M
author_rank: Super Contributor
timestamp: March 16, 2025, 10:41:35 pm
content: Lets refer to the definition of 'encoder'https://en.wikipedia.org/wiki/Encoder_(position)Note that these rotary speed encoders are incremental encoders with a single pulse output. That means they don't sense the direction of movement, but you can get that from the direction the H-bridge is commanded to drive the motor.The complete encoder has two main parts:A slotted disc on the motor shaftAn opto-interrupter sensor consisting of a LED illuminating a photosensor the other side of the slot + signal conditioning circuitIt also needs the sensor to be mounted with the edge of the disk deep in its slot.If they are selling a complete speed encoder then yes it should include the sensor, e.g. like this:https://www.amazon.com/DAOKI-Measuring-Optocoupler-Arduino-Encoders/dp/B081W2TY6Qbut most 2WD buggy robot kits come with the slotted discs as they are a very cheap plastic part, but not with the sensors at they add significant extra cost.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 16, 2025, 11:04:18 pm
content: Now I understand and I knew when they say encoder it was not a complete set since its missing the sensor.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 16, 2025, 11:53:18 pm
content: Going thru Amazon.com it will cost me CAD$30 more due to shipping cost. So I selected as per attached from Amazon.ca.I know I only need to sensors but can only find them in qty 5. If you think my selection as per attached is acceptable I will place the order. Many thanks Ian

author: Ian.M
author_rank: Super Contributor
timestamp: March 17, 2025, 12:08:46 am
content: Look at the fourth photo down in the listing (chassis and motors), and I bet you'll find it includes the encoder discs, freeing you to look for a better deal on just the speed sensors. Like you, I couldn't find individual sensors or pairs at a price that made sense, but a friend was building the same kit so we shared a pack of five.Also that kit only has a 6V four cell battery holder but six cell holders are cheap enough that may not be a deal-breaker.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 17, 2025, 03:14:31 am
content: Nany thanks Ian, I know about the battery pack and I will change it. Order placed (the kit + 5 sensors) with delivery March-20. It will take me some time to study etc. and post questions as needed

author: JustMeHere
author_rank: Frequent Contributor
timestamp: March 17, 2025, 09:11:01 am
content: 9V batteries are low current supplies. They are essentially several 1.5V batteries in series. They are great for things that draw in the 10s of mA, but for high current devices like motors, you will only get a few minutes of runtime.

author: Ian.M
author_rank: Super Contributor
timestamp: March 17, 2025, 09:25:23 am
content: Quote from: JustMeHere on March 17, 2025, 09:11:01 amIf you change that to read "Commonly available9V batteries(e.g. PP3 / 6F22)are low current supplies, They are essentially severaltiny1.5V batteries in series. ...", I'd agree 100%. However on its own your statement is somewhat misleading.Also seehttps://lygte-info.dk/info/BatteryDisassembly9VAlkaline%20UK.html

author: ahsrabrifat
author_rank: Regular Contributor
timestamp: March 17, 2025, 10:38:35 am
content: The motors in your schematic are expected to run at 12V. If you use 3-6V motors, they might burn out if powered directly from 12V.If you power them from a 9V battery, they will be overvolted (if you use full battery voltage) or underpowered (if driven via the L298N, which drops some voltage).If you must use 3-6V motors, power them directly within their range. Instead of L298N, a motor driver like the DRV8833 or L293D would be better, as they support lower voltages efficiently. If you can't /do not want to use anything other than the L298N, use a DC-DC Buck Converter like the LM2596.https://www.theengineeringprojects.com/2020/09/lm2596-buck-converter-datasheet-pinout-features-applications.html

author: Ian.M
author_rank: Super Contributor
timestamp: March 17, 2025, 12:59:38 pm
content: Most low voltage brushed DC motors are fine with a higher supply voltage up to double their nominal voltage provided you limit the PWM duty cycle to limit the max. average voltage to their rated voltage. If you sense the battery voltage via a potential divider to an ADC input, this gives you the option to maintain full motor performance over most of the battery discharrge curve. Efficiency is limited by the H-bridge but is unlikely to be worse than the same H-bridge fed by a switching buck regulator to run the motor at its nominal voltage and 100% duty cycleAs noted above the L298N is not particuarly efficient, but it is cheap and commonly found in these robot buggy kits. I would suggest getting the buggy running well with the supplied L298N module before deciding if its worth upgrading the H-bridge to a MOSFET one wih a buck regulator for the 5V rail. At that point I'd also be looking at fitting a 3S LiPo pack normally used for RC models, but that with a suitable charger is not cheap.For smaller robot buggies one or two 18650 cells in battery holders + a boost converter to get a 7V supply (8.2V max.) for the Arduino and motors may be the better option.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 21, 2025, 01:03:40 am
content: Got the Robo kit today and its kind of disappointing, there is no wiring schematic on how to wire the electronics and the assembly instructions of the mechanical part is very poor. I sent an email asking for the electronics wiring.The 2 motors have no wiring coming out neither any cable plug in so I have no idea how they will run.For the 4 cells battery pack I looked locally and found nothing. To order a 6 cells pack it will cost about $15.00. Perhaps if I glue 2 extra batteries to the 4 cells pack will be a good solution?

author: Ian.M
author_rank: Super Contributor
timestamp: March 21, 2025, 03:31:15 am
content: These instructions should be compatible with your kit:https://www1.cs.columbia.edu/~sedwards/presentations/robot-car-instructions.pdfbut beware of the power wiring on page 12 - it overvoltages the Arduino when fresh batteries are used! Firmware is here:https://www1.cs.columbia.edu/~sedwards/presentations/robot-car.zipHowever if you want a 6x AA flat battery holder, it needs to go top-side, as there isn't enough room between the motors to fit it on the bottom. That means the L298 board needs to go on the bottom, terminals toward the back, with the middle of its motor terminals inline with the rear end of the motors. Use single M3 hex nuts as spacers between the L298 board and the chassis as you want to keep the max. possible ground clearance. The L298 heatsink will only be a few mm below the motor mount brackets. To find a suitable battery holder, try Ebay!https://www.ebay.ca/sch/i.html?_nkw=9V+aa+holder&_sop=15I also preferred not to hack up the supplied black plastic pan/tilt mount but instead to fit the servo in the rectangular hole at the front of the chassis, and make a mounting bracket for the ultrasound sensor from rightangle PVC extrusion. Don't cut the cross servo arm, just screw the home made bracket on top of it using the tiny self-tapping screws supplied with the servo, using the holes at the end of its arms, and fasten the ultrasound sensor to the front of the bracket. You can use the pan/tilt mount later if you add a camera.If you follow my advice from earlier to power the Arduino from Vin or Dc in not from its 5V pin, you can use a 5.5mm DC jack plug in the Arduino's DC jack, fed from the battery negative and switched positive, but it needs to be a right angle one so the plug doesn't stick out over the edge of the baseplate. I found it easier to solder a two pin right-angle header into the extra holes the Arduino clone board has next to its headers, connecting VIN and the adjacent GND, on the underside with pins pointing inwards, so I could use a two pin female duPont connector to power the Arduino from underneath. Connect the battery negative and switched positive to the L298 board and the Arduino, *NOT* to the sensor shield screw terminals. You then need a single red wire from the L298 module +5V screw terminal to the Vcc screw terminal of the sensor shield. The jumper behind the three screw terminal on the L298 board should be fitted and the SEL jumper next to the screw terminals on the sensor shield removed. Wired like that, you can also plug in a 9V (regulated) power supply to the Arduino DC in and power the whole robot for bench testing, but keep the battery switch OFF!For the L298N H-bridge module, see:https://docs.sunfounder.com/projects/sf-components/en/latest/component_l298n_module.htmlI already gave you the sensor shield link above, but here it is again:https://protosupplies.com/product/sensor-shield-v5-0/If you run into any problems, *STOP* and ask here!Finally here are a couple of photos of my build of this robot in its test stand, to hopefully give you an idea of how it goes together. Ignore the extras - Sunfinder 5 sensor I2C line follower board (front underside) and an ESP8266 for a WiFi link to the robot's Arduino (left rear underside + level converter on sensor shield 'bluetooth' header).

author: Larsson55
author_rank: Regular Contributor
timestamp: March 21, 2025, 05:23:36 am
content: Gush Ian you know so much and I'm jealous, LOLMany thanks for your time ian, the link for the instructions unfortunately does not work, I get error finding the page, all other links work good. The pictures of your robot are really good and will be very helpful.The battery pack from the links you sent the delivery is May-June so I will order tomorrow a 6 pack 9V battery holder from Amazon.ca which will be here early next weekThere is a lot of useful information in your reply so I will print it and study it tomorrow and for sure I will have questions. Right now I try to get the wheel mounted into the chassis and I will be happy if I can finish that tonight.Much appreciated

author: Ian.M
author_rank: Super Contributor
timestamp: March 21, 2025, 07:38:24 am
content: You'll probably get a fair bit of practice mounting and removing the motors as you are likely to find you need to put screws through a pair of holes just under the side of the rears of the motors holes to put in mounting pillars for the battery holder to go on. On my kit, I needed to file those holes outwards a bit with a needle file as the battery holder's hole spacing didn't quite match.Try:https://www.stemworld.com.au/wp-content/uploads/2020/01/2WD-robot-car-instructions.pdfIts the same instruction PDF written byProfessor Steven A Edwardsof Columbia University hosted elsewhere. You can also see if it lets you access the robot car stuff if you go via his profile page. The matching unmodified Arduino sketch is much harder to find elsewhere, so I've attached a copy.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 21, 2025, 08:07:00 am
content: Too excited to sleep....so I'm back at it...Sorry don't know why but I got the 24 pages .PDF document now and I print it. A much needed document.You are right about the motors, they are mounted now but don't know how good they are. The problem is both sides are similar and don't know which side is the right one to face lets say the exterior of the chassis. Eventually I will get it

author: Picuino
author_rank: Super Contributor
timestamp: March 21, 2025, 08:37:06 am
content: As previously mentioned, the DRV8833 driver is a very interesting option, cheap and very versatile.https://www.ebay.com/itm/314750101280Features:Dual-H-bridge motor driver: can drive two DC motorsOperating voltage: 2.7‌‌ V to 10.8 V;Output current: 1.2 A continuous (2 A peak) per motor;Inputs are 3V- and 5V-compatible;Under-voltage lockout and protection against over-current and over-temperature;Reverse-voltage protection circuit;Current limiting can be enabled by adding sense resistors (not included).EDIT: TI integrated circuit and datasheethttps://www.ti.com/product/DRV8833https://www.ti.com/lit/ds/symlink/drv8833.pdf

author: Ian.M
author_rank: Super Contributor
timestamp: March 21, 2025, 08:43:26 am
content: The solder tags on both motors should face the inside of the chassis, and the gearbox axles should be immediately under the cross slots in the chassis. If the solder tags face the outside, it makes it harder to do the wiring neatly.@Picuino,I agree the DRV8833 is a *MUCH* better H-bridge, however its got fewer control pins than the L298N, so isn't a drop-in replacement if the Arduino sketch is doing PWM speed control. Also, this robot needs a 5V regulator to provide power to the servo, as the onboard regulator on the Arduino clone hasn't got enough copper area for high current 5V loads. The L298N module conveniently has one, but its hard to find a DRV8833 breakout with one so a separate one would be needed.

author: Picuino
author_rank: Super Contributor
timestamp: March 21, 2025, 08:47:03 am
content: But if you are looking for a higher level, try using motors with feedback to know their real speed.You can use encoders, back-emf measurement or current compensate.Back-emf measurement does not require the motor to have an encoder attached, but it complicates the electronic drive and control circuitry and it's a little less accurate.Another method you can use is to measure the motor current and compensate the voltage with that current measurement by knowing the series resistance of the motor armature. It is simpler than back-emf, but a little less accurate. You also do not need to attach an encoder to the motor shaft.Either method will allow you to control the position of the robot more accurately than simply controlling the voltage of the motors with PWM.

author: Ian.M
author_rank: Super Contributor
timestamp: March 21, 2025, 08:58:44 am
content: I already recommended buying the optical sensors to use with the slotted encoder discs on the axle shafts.One of my main criticisms of this kit is they didn't provide the gear motors with a fast encoder on the back of the motor, e.g.https://botland.store/dc-motors-with-gearbox-and-encoders/6287-dc-geared-motor-with-encoder-sj01-6v-160rpm-1201-6959420910205.htmlHaving more encoder pulses per wheel turn would make it considerably easier to do precise motor control.

author: Picuino
author_rank: Super Contributor
timestamp: March 21, 2025, 09:05:43 am
content: Quote from: Ian.M on March 21, 2025, 08:43:26 amIf you want to feed anyway from 12v battery, you can use a small and cheap step-down switched circuit that lowers the voltage to a more acceptable one for the driver.It will still be a better solution than using an L298N, which really has a lot of voltage drop and a lot of power losses.EDIT: DC-DC Step down converterhttps://www.ebay.com/itm/364734558814

author: Larsson55
author_rank: Regular Contributor
timestamp: March 21, 2025, 09:31:26 am
content: Reading the PDF guide it says to determine the top of the baseplate...., my UNO has 4 holes and non aligns with the baseplate pre drilled holes. Any ideas? I could drill new holes on the baseplate if needed

author: Ian.M
author_rank: Super Contributor
timestamp: March 21, 2025, 01:19:21 pm
content: Post a photo of your baseplate looking straight down, (preferably with the protective paper still on it on top of a white background) and a photo of your Arduino board and I may be able to suggest which holes to use. Mark the side of the baseplate that was up in the photo.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 21, 2025, 05:52:41 pm
content: Noticed in your build you didn't remove the paper from the baseplate, is there a reason?In my horrible instructions the first thing they say is to remove that paper and it was a heck of a job to do it. Anyway not able to get now a good picture, the attached I have 1 wheel under it to level the plate and in one picture you see the reflection from my desk light at the top right. Can't see very muchMy opinion is that it doesn't matter which side of the baseplate is up/dn, I would think holding the Arduino with just 2 screws it would be sufficient, jest use one of the existing holes and drill a new one, It will be nice to know the orientation, perhaps having the USB plug pointing to the left?

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 21, 2025, 06:46:51 pm
content: The paper is there to protect it during drilling and cutting, and would have been helpful in your case to mark out the location of the holes you need for the UNO.Bit of a shame that the kit is not properly created for easy assembly, because I think the holes for the swiveling wheel are also not correct. Based on your pictures of the kit it looks like there should be 4 holes in a square arrangement for it.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 21, 2025, 06:59:29 pm
content: Quote from: pcprogrammer on March 21, 2025, 06:46:51 pmYou are right but as a beginner I removed the paper as they were saying. The good part is the swivel wheel drilling is perfect. Bottom line I'm not happy with this kit I just hope the electronic parts will be good, the rest I can manage. Thanks for the help

author: Ian.M
author_rank: Super Contributor
timestamp: March 21, 2025, 07:07:38 pm
content: You have a slightly different baseplate to me (and Prof. Edwards). Mine has a rectangular hole at the front to mount the servo, and assymetric holes near the back for the Arduino to mount on top with the USB connector pointing left. Ypurs appears to be summetric, so (until you dril extra holes) doesn't have a 'right' way up. As it doesn't have the servo hole you may be forced to use the 'janky' modified Pan/tilt mount for the ultrasonic sensor.I left the paper on so I could mark the holes I was using for each part on it, and to protect the plastic from scratches while drilling extra holes and during assembly, then was too lazy to slacken all the screws again to rip the paper out from under them, as I didn't really care about the appearance. Mark the holes for the tail-wheel first, so you can avoid them with the other parts. Also mark the inside outline of the motors and mounts. As you have removed the paper, you will now need to either use a non-permanent marker that wipes off Perspex/Acrylic plastic or stick *BLUE* masking tape where you need to mark.Shuffle the parts around to see how they fit, keeping heavy parts (e.g. batteries) behind the axles so they dont tip it forward till you find a convenient layout that doesn't need too many extra holes, and doesn't have *any* parts sticking out past the baseplate edge except for the wheels and motor shafts. (When your code goes wrong and the car hits a wall or furniture leg, the impact can be brutal!)This build may give you some placement ideas:https://dronebotworkshop.com/robot-car-with-speed-sensors/

author: Larsson55
author_rank: Regular Contributor
timestamp: March 21, 2025, 10:01:34 pm
content: Ian, both documents you provided for me, Prof. Edwards + dronebotworkshop are more than enough to do my robot now, many thanks.So now I have tons of work to do and will post again if/when I stumbleOne item I found not mentioned in the above docs is how to mount the optical sensors into the motor shaft. Each sensor has a flat side and the other side has a protrusion where the shaft is to be inserted. Which side faces the motor? I would say it doesn't matter cause there is enough space on the motor shaft to move the sensor horizontally as needed.

author: Ian.M
author_rank: Super Contributor
timestamp: March 21, 2025, 10:31:32 pm
content: On my robot, the slotted discs were push-fit on the inside end of the motor shaft before fitting the motors, and were best centered in the chassis cross-slots (and thus in the opto sensors) when they were flush with the end of the shaft. The sensors need their rightangle pin headers desoldered (if you don't have good desoldering tools heat up one pin joint at a time and pull the individual pin out of the PCB and header with needle nose pliers), and wires soldered on from the back where the pins were, as they need to mount to the chassis top side, component side down with their protruding opto-sensor end in the cross slot straddling the top of the disc. The end with the wires goes towards the front of the chassis. Unless you find a hole in front of each cross-slot in exactly the right place (so you can use a machine screw and nyloc nut), secure them with a small self-tapping screw through their mounting hole into a drilled hole in the chassis. They will probably need a small thin O ring on the screw under the sensor PCB to help level the sensor PCB and protect the SMD components when you snug up the screw. Do *NOT* overtighten.N.B. *NEVER* use Loctite or any other normal thread locker on any fastener in or through Pespex/Acrylic plastic, as its chemically incompatible causing microcracking and accelerated brittle failure. You also need to be careful with some glues, paints and lubricants, and many solvents - check the technical datasheet of any such product you plan to use for compatibility.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 22, 2025, 03:17:58 am
content: I'm following Mr. Edwards PDF instructions and the attached indicate the progress up to step 3 of the instructions.Comments appreciated

author: Ian.M
author_rank: Super Contributor
timestamp: March 22, 2025, 03:52:48 am
content: That looks reasonable so far, but you will need to add standoffs (or a block of something) between the castor baseplate and the chassis so its sits level on its wheels, not tilted back, which if left as is prevents the castor swivelling properly.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 22, 2025, 04:50:40 am
content: The castor swivels properly as it is Ian and I noticed the baseplate is not level but I thought it was supposed to be like that. I will add tomorrow what's needed to make it level

author: Larsson55
author_rank: Regular Contributor
timestamp: March 22, 2025, 10:20:25 am
content: Trying to install my 4 cells battery holder in front of the swivel wheel and I barely have enough space. When I get next week my 6 cells battery holder any suggestions where to install it? Thanks

author: Ian.M
author_rank: Super Contributor
timestamp: March 22, 2025, 10:55:08 am
content: It depends which six cell holder you got. I'm assuming side by side like the one in my robot kit. I found the only practical location was top side, cross ways immediately in front of the Arduino, on two short standoffs to clear the motor mounts. The H-bridge board was mounted bottom side, with topside standoffs on two of its screws pushing against the underside of the battery holder to stop it rocking. See photos I posted earlier

author: Larsson55
author_rank: Regular Contributor
timestamp: March 22, 2025, 11:25:47 am
content: Sorry, I forgot these pictures which will be very helpful,Yes my new battery holder is side by side. I have the ON/OFF switch in that location but I can relocate the switchBTW I noticed you have your swivel wheel mounted on spacers, why? are your 2 wheels larger diameter?

author: Ian.M
author_rank: Super Contributor
timestamp: March 22, 2025, 12:33:13 pm
content: Quote from: Larsson55 on March 22, 2025, 11:25:47 amSee reply #41!If the whole robot chassis is 'nose in the air', the tilted castor base degrades steering by applying side force to the tail whenever the castor wheel is slightly off-center. It also somewhat degrades ultrasonic ranging as when using the servo to scan for obstructions, the beam sweep is not parallel to the floor, so the detectable object size and max. range varies with the servo angle. Additionally it reduces ground clearance behind the wheels, which may affect where you can put under-mounted parts, and makes it harder to mount sensors that need to look straight down e.g. line following sensors. None of the above are show-stoppers.However it also looks uncool. A 'Carolina Squat' is silly enough on a full size vehicle, with connotations of rednecks driving overloaded pickups. On a toy or model it just screams of stupid!On the design side of things, there is a strong need to keep the rear castor small so it swings in a small circle to avoid instability when cornering or turning on the spot. That makes it impractical to fit a large enough caster to match the drive wheel height without spacers.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 22, 2025, 03:10:57 pm
content: Thanks Ian for the explanation on the swivel wheel,Since I will mount the 6 battery pack at the top of the board, I will have to mount I guess the L298N motor driver under the board in between the 2 motors like you did. Before I do that I should know where the two LM393 speed measuring sensors will be installed. Also I noticed in your picture you don't have an Ultrasonic Sensor like mine which also needs some space.

author: Ian.M
author_rank: Super Contributor
timestamp: March 22, 2025, 03:59:55 pm
content: Hope these help.Your chassis doesn't have the front rectangular hole to mount the servo, but the base of the supplied pan/tilt mount will fit between the encoder sensor PCBs, or you could mount the servo on standoffs or small blocks so its base is against the top of the chassis, or maybe enlarge the front large round hole sideways with a file to mount the servo same as mine.I preferred to keep the pan/tilt mount to use with a Raspberry Pi camera. Adding a Pi + a camera to the robot has been on my to-do list for *far* too long!

author: Larsson55
author_rank: Regular Contributor
timestamp: March 22, 2025, 04:30:10 pm
content: Thanks for your time Ian, will post pictures when done

author: Larsson55
author_rank: Regular Contributor
timestamp: March 22, 2025, 08:01:15 pm
content: Is there a reason to use a 6 pack AA batteries holder versus 1 single 9V?Thinking for space saving only

author: Ian.M
author_rank: Super Contributor
timestamp: March 22, 2025, 08:28:42 pm
content: Quote from: Larsson55 on March 22, 2025, 08:01:15 pmSee reply #3 and my comments in reply#6.N.B. Show us your proposed power connections *before* powering it up the first time, so we can check them!

author: Larsson55
author_rank: Regular Contributor
timestamp: March 22, 2025, 08:50:39 pm
content: I don't really understand volts etc. so I better stick to my 6 batteries holder.Ian I wouldn't dare to power up anything before I post hereMany thanks again

author: Larsson55
author_rank: Regular Contributor
timestamp: March 22, 2025, 09:00:04 pm
content: Sorry, I forgotAs per attached, it says to trim the white pc so I have only 3 holes in the white pcWhat I have to make it fit inside the black round pc I have to trim enough so only 2 holes will be availableWhat is my option?

author: brucehoult
author_rank: Super Contributor
timestamp: March 22, 2025, 09:07:10 pm
content: Quote from: Larsson55 on March 22, 2025, 08:01:15 pmMotors use a lot of electricity. The bigger the physical volume of batteries the better. A small 9V "transistor" battery will last a couple of minutes maybe.

author: Ian.M
author_rank: Super Contributor
timestamp: March 22, 2025, 09:38:38 pm
content: Quote from: Larsson55 on March 22, 2025, 09:00:04 pmNo good ones - I did say earlier it was 'janky' putting the ultrasonic sensor on a hacked pan/tilt mount!I found the holes in my servo arm didn't even line up properly with the holes in my pan/tilt base, and the tiny screws wouldn't hold. In the end I enlarged the holes in the arm a bit so I could force tiny machine screws through them (M1.6) and put nuts on top of the arm to clamp it into the recess in the base. However because I decided not to use the pan/tilt mount for the ultrasound sensor, I encountered this issue when I wanted to put a camera on it long after I had finished the robot build.When I was building the robot, I used a 50 mm length of right angle white uPVC extrusion (18mm x 18mm, 1.5mm thick), to make a right angle mounting bracket for the ultrasonic sensor to go on the servo shaft. I transferred the hole pattern of the large cross shape servo arm to the bottom of the bracket by pricking through the holes, then drilled out the four end holes of the cross just big enough for the tiny screws and the center hole just big enough to get a screwdriver to the servo arm fixing hole. The top of the front of the bracket was notched to clear the sensor header base, and tiny holes were drilled in the corners so I could tie the sensor PCB to the bracket with loops of 24 AWG insulated solid wire, threaded through two holes in the PCB and the bracket, pulled tight and twisted together behind the bracket.Then you've got to mount the servo to your chassis shaft up, which as you don't have a hole it will slot straight in, will be harder for you than for me. I made some suggestions earlier.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 22, 2025, 09:54:43 pm
content: I re read your post #48 and I guess I'm now stuck....Will have to see a clear picture of how these parts fit and then I can modify as needed. Will search to find a similar assembly and then I will be good to goThanks

author: Ian.M
author_rank: Super Contributor
timestamp: March 22, 2025, 10:58:34 pm
content: Hope these help.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 22, 2025, 11:35:17 pm
content: They help a lot, thanks. I also found some and it helped to assemble half of it. I noticed others say similar to what you said "needs a lot of work / modifications".

author: Larsson55
author_rank: Regular Contributor
timestamp: March 23, 2025, 12:21:13 am
content: Try to understand how it functions, the white part in the center of the attached is secured with 2 screws which it means it does NOT rotate (the white part). Then the shaft of the servo motor is screwed into the center of this white part. This means the servo motor shaft is not rotating?

author: Ian.M
author_rank: Super Contributor
timestamp: March 23, 2025, 12:58:34 am
content: Yes, the shaft is fixed and the whole servo body + anything attached to it (middle part of pan/tilt mount) rotates around the shaft.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 23, 2025, 01:20:12 am
content: Now the mystery is solved, I couldn't think why the motor shaft is fixed and I was trying to find a solution! Many thanks. I should finish this assembly soon and post a picture tomorrow

author: Larsson55
author_rank: Regular Contributor
timestamp: March 23, 2025, 01:37:30 am
content: Left with this part as per attached and don't know what's for. Do you?

author: Larsson55
author_rank: Regular Contributor
timestamp: March 23, 2025, 02:03:39 am
content: Here it is the sensor complete but not mounted to the base. Next step will be to mount all to the base but have to wait for the 6 pack battery holder (Tuesday or Wednesday). And next is the wiring.Mr. Edwards also has a step to connect the sensor to the power to adjust the motor to 0 or 90 degrees. I didn't do this step, prefer to do it when all wiring is done unless you recommend to do it now

author: Ian.M
author_rank: Super Contributor
timestamp: March 23, 2025, 03:42:09 am
content: The extra black plastic part is used to mount a camera when the mount is assembled with two servos as a full pan and tilt.You must center the servo (1.5ms pulse) before fitting the head to the base or the ultrasonic sensor wont face straight forward when you fit the base to the chassis. However as the sensor isn't needed for basic operation of the robot under manual control or simple programmed sequences, you can put off that step till you have the other parts assembled wired and even tested.If you want to do it before assembly, use this code:Code:#include <Servo.h>Servo myservo;void setup(){myservo.attach(11);myservo.write(90); // set servo to mid-point}void loop() {}with the Arduino powered by USB from your PC.Start by removing the jumper on the sensor shield so it doesn't back-power the Arduino and PC USB, and temporarily power the servo by connecting the6V four cellbattery pack to the screw terminals on the sensor shield. Connect *ONLY* the servo to the sensor shield at D11, as on page 8 of Prof. Edwards' instructions. Connect the Arduino by USB to the PC and compile and upload the sketch. It will center the servo as soon as you upload the sketch, or as soon as you power the Arduino and sensor shield if its already uploaded. Once centered, unplug the USB, disconnect the battery pack and disconnect the servo in that order.Ask before doing all the sensor shield wiring as there are some choices to be made depending on who's robot car sketches you want to use, and ATmega238P & Arduino Library hardware constraints. e.g. the H-bridge enable signals need to be on pins that can do fast PWM without using Timer 1 and the opto speed sensors need to be on INT0, INT1.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 23, 2025, 06:19:46 am
content: I repost the servo support so you don't have to search for it because the two 3mm self tapping screws are very flimsy and the connection will fail. I think I know how to fix it with new material and no glues. 3mm self tapping on plastic is not good even to hold paper...it's not the weight but rather the sudden movements.What is the purpose of a camera on this robot? I do have a spare servo from my previous kit and perhaps I may use it if you agree. Pls let me know what other parts I needI also may follow your instructions now regarding centering the servo. Do I have to upload any libraries too? I will also ask before I start any wiringStarting tomorrow Sunday I will not be able to do very much work because I will go to pickup my Shih Tzu which I share with my ex wife on a weekly basis. She takes a lot of my time for walks etc. + the neighbors who come to play with her.

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 23, 2025, 07:16:28 am
content: Quote from: Larsson55 on March 23, 2025, 06:19:46 amTo make use of a camera you need either a way to stream the feed to a monitor and see what the robot is seeing, use a camera that records on a SD card so that you can view it later or add a much more powerful processing board to use the camera feed to do obstacle detection.

author: Ian.M
author_rank: Super Contributor
timestamp: March 23, 2025, 07:48:58 am
content: Yes, at a minimum you need to through-bolt the servo arm to the base plate. However it needs *VERY* small machine screws and nuts. The M1.6 ones I used were nearly impossible to fit.M1.2 or 00-96 screws and matching nuts would be a much better choice, but are not so easy to buy in small quantities, long enough and at a reasonable price. I'm not sure glue would be a better choice, and if you glue it, you mustn't get any glue in the splined hub that fits to the servo shaft. Maybe bedding the arm in epoxy putty, screwing it down with the supplied screws then back-filling with more epoxy putty could work if you were careful to avoid getting any in the hub.Additionally to pcprogrammer's comments, if you *do* fit a camera, you'll need a much better power system than 6x AA batteries feeding linear regulators due to the significantly higher current consumption and far greater sensitivity to voltage instability, and also due to the sheer cost of running it using primary cells

author: Larsson55
author_rank: Regular Contributor
timestamp: March 23, 2025, 08:10:46 pm
content: No camera, I have no need for it but perhaps in my next project ....thanks for the infoRegarding securing the arm to the base I have to take it apart and see what I can do. I definitely do not want to use any kind of glue but for sure I will find a good solution and post the results.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 24, 2025, 07:04:46 am
content: Hi Ian, after I do the repairs on the sensor to secure it properly I will do what you describe in your post #64 to center the servo.The wiring I will do as you describe + page 8 from Prof. EdwardThe code you described how do I get it into the Arduino directory? As far as I know it should have a .ino extension. Just copy the code to a text file and change the extension to .ino ?Thanks

author: Ian.M
author_rank: Super Contributor
timestamp: March 24, 2025, 07:50:41 am
content: Simply open the Arduino IDE, and paste the code into a new sketch, overwriting the template it gives you, then save it with an appropriate name.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 24, 2025, 09:45:50 am
content: That's fine with your last post however there is so much info here and kind of difficult to remember it all. At the beginning of this thread you posted a link for a Firmware from Columbia.edu which provides a zip file. What I should do with it?Thanks

author: Larsson55
author_rank: Regular Contributor
timestamp: March 24, 2025, 12:05:30 pm
content: Another question Ian, as per attached picture the wheels sensors they are not level at the top, should I put a spacer under so they are level? Is this the right way to install them?Thanks

author: Ian.M
author_rank: Super Contributor
timestamp: March 24, 2025, 12:11:26 pm
content: That depends - if you copy the duPont wiring in Prof. Edward's instructions exactly (but not the power wiring as you will be using a six cell battery so need different wiring), that sketch should run the robot if you simpply unzip it, open it and sebd it to the Arduino. If you wire it up differently you need to make some changes to get matching pin numbers in the sketch.Try powering *just* the sensor (you can use the four cell battery pack, connected + to Vcc, - to Gnd at the sensor PCB) and watching the LED nearest to its A0 pin. It will be on with nothing in the sensor slot and go off when the light path is obstructed. If you slowly turn the wheel by hand it should flash as the slots in the encoder wheel go past.I found I had to remove the right-angle headers on the wheel sensors to get th.em to sit flatter. This is a PITA, especially if youi want to be able to reuse tthe header

author: Larsson55
author_rank: Regular Contributor
timestamp: March 24, 2025, 02:44:54 pm
content: Quote from: Ian.M on March 24, 2025, 12:11:26 pmSorry Ian, the above paragraph is not clear to me. Can you please explain further?

author: Ian.M
author_rank: Super Contributor
timestamp: March 24, 2025, 02:58:34 pm
content: The pins in the sketch must exactly match the way the H-bridge, sensors etc. are wired to the Arduino pins. There are different ways of supplying eveything with the correct voltage range depending on the battery pack you use, so the sketch doesn't care about the possible variations in the power wiring.If the sketch doesn't match the wiring you have to change the pin numbers in the sketch till it does, however not all pins are capable of all functions, so some stuff shouldn't be moved/changed.

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 24, 2025, 06:06:20 pm
content: Not Ian, but I will give it a try.Your sensors are most likely 5V based, so you can't power them from a 6 cell battery pack. (6 * 1.5V = 9V) This means you have to power the sensors from either the Arduino 5V output or the motor driver 5V output. It is best to use the 5V from the Arduino UNO to power the sensors and the 5V from the motor driver board to power the servo.In an Arduino sketch you assign the IO pins to functions. Say for the motor drive you connect the module inputs to pins D4 and D5 on the Arduino UNO, while in the code pins D0 and D1 are used your motor won't be controlled. So you have to make sure that you connect the modules to the correct IO pins as used in the software.Edit: I did not see Ian's reply as it was on the next page. Now you have two answers.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 24, 2025, 07:53:55 pm
content: I used two 2mm bolts/nuts and the servo arm is now secured to the base tight. The only weak link now is the "self taping" screw which holds the servo arm to the motor's plastic shaft and there is nothing I can do there unless I get a motor with metal shaft.My next step is to follow Dr. Edwards instructions starting on step 5 for the Firmware.Next steps 6 & 7 are related to the sensor mount which are completeThen is step 8 to connect the power & motor wires which for now I plan to use my 4 pack batteries. If I must use a 6 pack batteries I will do this step (and the ones below) on WednesdayFinally is step 9 to connect all above to the sensor shieldI haven't noticed anywhere where/how to connect the speed sensors for the two big wheelsPlease let me know if all above are correct or of any changesMany thankspcprogrammer obviously I will let Ian handle your last post, thanks

author: Larsson55
author_rank: Regular Contributor
timestamp: March 25, 2025, 08:39:20 pm
content: Have a problem with uploading Robot-car.ino, If I go to libraries there are many, where do I put the robot-car.ino? Arduino says "Upload error"Attached picture of what I have

author: Larsson55
author_rank: Regular Contributor
timestamp: March 25, 2025, 08:54:20 pm
content: Looks like my Arduino is stuck to what I was doing before when I had the Elegoo kit and when I open Arduino it still says Lesson 24 which was the last lesson I did with that kit. I don't know how to start Arduino without Elegoo

author: Ian.M
author_rank: Super Contributor
timestamp: March 26, 2025, 12:11:55 am
content: File => New, then on the old 1.8x IDE, close the previous sketch window.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 26, 2025, 01:56:17 am
content: Was able to get robot-car.ino and when ask to upload it says "compilation error: use of enum "Motor" without previous declarationWhat is Arduino BT? before I had Arduino UNO

author: Ian.M
author_rank: Super Contributor
timestamp: March 26, 2025, 03:48:07 am
content: Quote from: Larsson55 on March 26, 2025, 01:56:17 amThat's strange. Prof. Edwards' robot-car.ino that I attached to reply #25, compiles here with no issues. I'm using Arduino IDE v1.8.13.Quote from: Larsson55 on March 26, 2025, 01:56:17 amArduino BT is the wrong board (i.e. wrong model Arduino). DoTools=>Board: "...."=>Arduino AVR Boards=>Arduino Uno(very near top of list). If you compile for the wrong board it generally wont work (exception: some pairs of boards are interchangeable as only the form factor differs e.g Uno/Nano).

author: Larsson55
author_rank: Regular Contributor
timestamp: March 26, 2025, 07:26:21 am
content: I have Arduino 2.3.4 still says Arduino BT, somehow I think the lessons I did before screw up something in Arduino. I use the code you said on #25. Also do I need any extra libraries ?

author: Larsson55
author_rank: Regular Contributor
timestamp: March 26, 2025, 08:19:32 am
content: Re installed Arduino and now it says Arduino AVR and the robot-car.ino is in the sketch window. Then it says upload error exit status1. Output says: avrdude: ser-open(): "\\.\COM5. My Device mgr says COM5 works. Don't know what to do now.

author: Ian.M
author_rank: Super Contributor
timestamp: March 26, 2025, 09:00:33 am
content: The clone Arduino Uno that usually comes with those robot kits uses a CH340 USB serial interface IC. If your computer doesn't have the right drivers, the port may be non-functional. Try updating the drivers for that device - see:https://learn.sparkfun.com/tutorials/how-to-install-ch340-drivers

author: Larsson55
author_rank: Regular Contributor
timestamp: March 26, 2025, 09:35:14 am
content: Thanks for the link Ian, I suspected something similar may happen so I connected the other Uno I had from before and that shows on Arduino as COM3. I did this from my home office without the robot-car connected cause the robot is in my workshop which I cant access right now. Later on today when I can access the robot I will post back.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 26, 2025, 12:18:26 pm
content: BTW the link you sent me is for the motor controller?Anyway I replaced the UNO with the one I had from Elegoo and now all was fine and the sensor moved. The wiring is now disconnected following the order you specified.I got the 6 pack battery holder and ready now for the final step. Do I follow Pro. Edwards wiring to finish or wait for you?

author: Larsson55
author_rank: Regular Contributor
timestamp: March 26, 2025, 12:29:02 pm
content: Forgot, where do I connect the two LM393 speed sensors for the 2 motor wheels? Pro. Edwards does not show any

author: Ian.M
author_rank: Super Contributor
timestamp: March 26, 2025, 12:54:54 pm
content: Connect the speed sensors later, after you have tested the car with the robot-car.ino sketch. IIRC they conflict with Prof. Edwards' pin allocation, so you'll need to move some wires and edit the sketch. They each need three wires, +5V, Gnd and DO back to the arduino sensor shield. Don't connect sensor AO. The DO pins need to go to Arduino INT0 (Digital pin 2) and INT1 (digital pin 3) as the Arduino needs a fast way to count the pulses.For the power wiring for the six cell holder, the easiest way to do it is with a rightangle DC plug that fits the Arduino DC in jack. Call the L298 blue three way screw terminal block T3, with pin 1 next to the mounting hole, (may be marked +12V on PCB underside).Code:POWER WIRING============6 cell Bat(+) --- Switch(1)Switch(2) ---- L298 T3(1) ---- Arduino DC In center (or VIN)6 cell Bat(-) ---- L298 T3(2) ---- Arduino DC In shell (or GND)L298 T3(3) ---- Sensor shield VCCMake sure the jumper next to the L298 three way screw terminal block is fitted and the one marked SEL next to the sensor shield two way screw terminal block is removed. Don't connect anything to sensor shield screw terminal GND, it gets GND via the Arduino (you can use this as a test point for your DMM's black lead).For the duPont wiring, and the L298 module to motor wiring, follow Prof. Edwards' tutorial.Post photos of the assembled power wiring for us to check before fitting the batteries!

author: Larsson55
author_rank: Regular Contributor
timestamp: March 26, 2025, 03:11:33 pm
content: Thanks Ian, I will follow your instructions and perhaps as I go along I may have questions to assure I understand . Will definitely post pictures before inserting the batteriesWhat is duPont wiring?

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 26, 2025, 03:18:03 pm
content: Quote from: Larsson55 on March 26, 2025, 03:11:33 pmduPont is a connector type. The small black end on the wires of the servo for instance is a three way duPont connector that fits on a 2.54mm male header.You might also have gotten wires with these connectors on both sides. There are male and female types of these connectors. See the aliexpress link for pictures.https://www.aliexpress.com/item/1005007072081464.html

author: Larsson55
author_rank: Regular Contributor
timestamp: March 26, 2025, 03:45:28 pm
content: Thanks pcprogrammer, now understand and its true I got a bunch of them which are very handy.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 26, 2025, 07:51:28 pm
content: 3 pictures where I mounted the batteries case for commentsBTW when the robot is ready and running it will not be connected to the PC. Out of curiosity where it saves the instructions to do what it does?

author: Larsson55
author_rank: Regular Contributor
timestamp: March 27, 2025, 12:54:06 am
content: Apologies Ian but I don't understand your wiring instruction, I can guess but guessing will only lead to mistakes.What is IIRC ?"They each need three wires, +5V. Gnd and DO.." Which ones are "they" ? And what is DO ?"Call the L298 blue three way screw terminal block T3....." I don't understand this paragraph at allIf I may suggest, the UNO, Sensor Shield and L298H all have pins ID so perhaps you can say from UNO pin... to L298H pin..., something like that. Then there is no room for mistakes. An alternative perhaps is to refer to Pro. Edwards schematic and change the pins ID he is using?Many thanks

author: Andy Chee
author_rank: Super Contributor
timestamp: March 27, 2025, 04:16:27 am
content: Quote from: Larsson55 on March 27, 2025, 12:54:06 amIIRC is internet shorthand for, "If I Recall Correctly"LOL is internet shorthand for, "Laughing Out Loud"IMHO is internet shorthand for, "In My Humble Opinion"https://www.ruf.rice.edu/~kemmer/Words04/usage/slang_internet.html

author: Larsson55
author_rank: Regular Contributor
timestamp: March 27, 2025, 04:25:16 am
content: Thanks Andy, I knew the rest but not IIRC

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 27, 2025, 07:11:42 am
content: Quote from: Larsson55 on March 26, 2025, 07:51:28 pmThe ATmega328 used on the Arduino UNO contains so called FLASH memory. This is electrically erasable read only memory and the code for driving the robot is stored in that. With the Arduino IDE download command the AVRDude program connects to the ATmega328 and tells it to load the code into the FLASH memory. This is so called non volatile memory, thus once loaded it stays in there almost for ever. Data retention times are mentioned in the datasheets.Mechanically wise, considering the weight of the batteries and with it raising the center of gravity, you might want to consider making some brackets to place the battery plate flat above the motor driver board.

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 27, 2025, 07:30:47 am
content: Quote from: Larsson55 on March 27, 2025, 12:54:06 amThey are the two speed sensors. DO means digital out in this case.The sensor, for what I found on the internet, has four connections.VCC where the 5V needs to be connected.GND where the ground needs to be connected.DO which needs to be connected to a digital input of the Arduino UNO. D2 or D3 according to Ian.AO the analog output pin which is not used.To use these sensors the code needs to be changed and my advice is to leave this for later when the robot is actually working with the basic setup.Quote from: Larsson55 on March 27, 2025, 12:54:06 amSee the attached picture. The connector with the red ellipse around it, is the one Ian is referring to. This is where the supply from the battery pack needs to be connected.Here is some information on this:https://components101.com/modules/l293n-motor-driver-moduleThe motors are connected to the two smaller 2 way screw terminal blocks on the sides of the board.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 27, 2025, 03:09:54 pm
content: Thanks a lot for your time pcprogrammer,It's true having the battery holder horizontally mounted will provide better stability but it was easier to do it vertically. I will take your suggestion and change it.The wiring explanation is sufficient and much appreciated. My knowledge in electronics is less then zero and I prefer to understand what I'm doing to avoid mistakes.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 28, 2025, 12:57:22 am
content: Got the battery case re located, hope it's acceptable unless I miss something again

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 28, 2025, 07:03:08 am
content: Looks much better so.

author: Ian.M
author_rank: Super Contributor
timestamp: March 28, 2025, 07:27:35 am
content: Maybe. However its still pretty high up. Lateral stability is likely to be a bit better as the weight is further forward, closer to the fixed base of the triangle formed by the wheels and the swinging caster, but as the battery pack is mounted above the H-bridge, and the top of the heatsink is nearly 30mm above the chassis (3/5 the length of an AA cell), I think fore and aft stability will be worse as the center of mass is actually higher up and further forward so there is a risk it will nose-dive if it stops suddenly.I mounted my H-bridge underneath for a reason . . .

author: Larsson55
author_rank: Regular Contributor
timestamp: March 28, 2025, 01:08:43 pm
content: Good idea Ian, I can mount the H-bridge under the chassis and then get the battery pack right on top of the chassis. However having the H-bridge underneath, the heat sink will almost touch the ground.In any case I'm anxious to finish the wiring now which for me is an important and difficult task. After the wiring is done I will relocate the H-bridge and battery pack

author: Ian.M
author_rank: Super Contributor
timestamp: March 28, 2025, 02:27:53 pm
content: Check how far the tyres are below the chassis. Subtract 29mm for the H-bridge mounted with single M3 nuts as spacers. That's your ground clearance with under-mounted H-bridge module. I found it was adequate like that*- this isn't a rough terrain robot, so don't expect to climb obstacles. It runs best on a smooth floor and reasonably on firm short-pile carpet.You still have to have the battery pack up a little as the motor mounting plates stick up approx 10mm above the chassis, but it will be *much* lower and more stable.* I have 15mm, same as the clearance under the line following sensor I added. The tail wheel is only 25mm dia so it cant even handle 10mm obstacles.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 28, 2025, 02:54:16 pm
content: Thanks, will do soThe ultrasonic sensor has 4 pins sticking out and the sensor shield has also similar pins sticking out (male). So I need cables with both ends female to make the connections unless I do something wrong. I don't have any female to female cables.I got 20 cables with the 5 sensors for the wheels which have one end male the other female. Perhaps I can modify 4 to have both ends female?

author: Ian.M
author_rank: Super Contributor
timestamp: March 28, 2025, 05:39:15 pm
content: I bought a 'duPont' crimper kit off Amazon, so I could make all my robot signal wires the right length. It came with a SN-28B ratchet crimper and a box of male and female terminals and assorted sizes of shells. However *BEWARE* - SN-28B isn't actually the right crimper for duPont style terminals as it doesn't do the insulation part of the crimp properly so it can be difficult to fit the crimpled contact in the shell, and some suppliers have SN-28B crimpers with really crappy dies that have too much slop to make good crimps. If you are using an appropriate size wire, stripped to the correct length, inserted correctly, and it repeatedly fails a 'pull' test after assembly, even after setting the crimper for max. pressure, return it!Before buying a crimper, see:https://www.eevblog.com/forum/reviews/affordable-crimp-tools-for-small-connectors-(dupont-etc-)/It may well be simpler to get a 20 pack of long-enough female to female duPont wires from a reputable supplier.Beware of fake CCA or CCS wires! You don't *know* its not CCA (copper clad aluminium) or CCS (.. .. steel) until you do the flame test for CCA and magnet test for CCS (i.e. a small powerful magnet is attracted to the middle of the wire).

author: Larsson55
author_rank: Regular Contributor
timestamp: March 28, 2025, 06:43:46 pm
content: Thank you Ian for the info on crimper kit, for now I will manage with what I have and later I will get one for my next project.I attach here 2 screenshots, one shows the robot with the battery on the side so you can see the L298 better. The ultrasonic is not wired yet but it is explained in my next screenshot how I will do the wiring which is basically as per Pro. Edwards wiring. Please let me know your comments

author: Ian.M
author_rank: Super Contributor
timestamp: March 28, 2025, 07:29:56 pm
content: Your power wiring is *WRONG* for six cell (9V) battery pack and will probably burn the Arduino! If you've switched on the switch at all it may be too late. Please confirm the Arduino still works OK (e.g. you can upload and run the 'blink' example if you remove the sensor shield and power it by USB from your PC).This is the power wiring I used before I modded my Arduino.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 28, 2025, 09:12:38 pm
content: I have not turn the power ON Ian, as we discussed I will do so when you say my wiring is Ok. I have similar jack to connect the Arduino. How about the rest of wiring

author: Ian.M
author_rank: Super Contributor
timestamp: March 28, 2025, 09:41:08 pm
content: As I said earlier, all Prof. Edwards' 'duPont' (i.e. signal) wiring is OK. His power wiring although not optimal is only unsuitable because of the change from four cell 6V battery to six cell 9V battery, (which was to get a much better run-time as unless you used 3V motors, they'd loose power badly as the battery voltage starts dropping down the discharge curve, long before the cells were used up, and the ultrasonic rangefinder would also loose range and possibly accuracy).

author: Larsson55
author_rank: Regular Contributor
timestamp: March 28, 2025, 09:53:45 pm
content: Thanks Ian, I will revise my schematic to include your comments later on tonight and post back. After you approve the new schematic I will turn the power ON.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 28, 2025, 10:45:01 pm
content: Here is the Revised Schematic, hopefully all is ok. If yes can I power ON the robot?Thanks

author: Ian.M
author_rank: Super Contributor
timestamp: March 28, 2025, 11:13:20 pm
content: Yes, but let's do it in stages. Start with the Arduino DC jack unplugged and no duPont wires plugged into the sensor shield. Switch on and confirm that there is +5V coming out of the H-bridge board to the Vcc screw terminal of the sensor shield , (measured with the DMM's black lead on battery (-)), and that the DC jack plug has 9V with the correct polarity (Center +). You can then switch off, plug the DC jack in, and switch back on.Using the pinout athttps://protosupplies.com/product/sensor-shield-v5-0/confirm there is 5V between VCC and GND at both the digital (D0-D13) and analog (A0-A5) three pin I/O headers.If all is OK, you are now ready to upload Prof. Edwards' robot-car.ino sketch to the robot, switch off and fit all the duPont wires, then balance it cross-ways on a open empty shoe-box so the wheels are off the ground so you can switch it on and observe its behaviour without it running away!

author: Larsson55
author_rank: Regular Contributor
timestamp: March 29, 2025, 12:24:06 am
content: Finally we are close to start up and I was thinking how to hold the car so it doesn't run away but you gave me the answer "... on a open empty shoe-box so the wheels are off the ground....".Will do what you are saying Ian some times tomorrow, have to relocate the battery case etc, and print the pin out from the link you provided. Must do it step by step and will post back when done.Many thanks for you time and patience

author: anvoice
author_rank: Frequent Contributor
timestamp: March 29, 2025, 02:38:28 am
content: Quote from: Larsson55 on March 28, 2025, 06:43:46 pmI second the warning for the crimper kit for when you get it: I have different sets of SN-28B, and the one with a shiny metal die works quite well, while the one with a black die is terrible. Even with the "good" one, I have to use a small pair of pliers to adjust the insulation crimp properly.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 29, 2025, 03:10:47 am
content: Thank you for the tip on the crimper kit, I will keep it in mind when I start a new similar project

author: Larsson55
author_rank: Regular Contributor
timestamp: March 29, 2025, 05:00:26 am
content: Hi Ian, Pro. Edwards code comes in 7 sectionsinclude servoenum motorvoid testMotorsunsigned intdefine num_anglesvoid setupvoid loopDo I copy all together into a new Sketch and name it robot-car.ino or into separate Sketches each one and if separate what should I name each new Sketch?Thanks

author: Larsson55
author_rank: Regular Contributor
timestamp: March 29, 2025, 08:20:42 am
content: Did all the testing Ian as per your instructions and have the right voltage in all the points you asked. In the attached screenshot you can see the red LED in both boards. The only problem I noticed is the camera faces to the left and moves from approx position 12 o'clock and 9 o'clock only and I think it happened when I finished what you had told me on how to set the camera after I finished that procedure I moved the camera by mistake and perhaps I must do the same code to set it back to the correct position?Also as per my previous post I will like to know what to do with the code from Pro Edwards (pls read my post above)Thanks, so far we got it right!

author: Ian.M
author_rank: Super Contributor
timestamp: March 29, 2025, 11:17:14 am
content: Open the complete robot-car.ino in the Arduino IDE and upload it! *ALL* the parts are needed for full functionality. However you should still try to understand it line by line, looking up anything you don't understand online (starting in the Arduino Reference documentation), working through the sections Prof E. presents it in in his tutorial (robot-car-instructions.pdf).You probably need to remove the servo from the pan mount baseplate, re-run the servo centering sketch (updated to whatever pin you finally have the servo on), and refit the servo taking care this time to point the sensor straight forward *without* turning the shaft as you refit it in the baseplate splines. Once centered, check it at angles 0 and 180 which should be looking to either side. Once its in the splines you don't have to worry if you turn it a bit while refitting the screws. You may find its limits aren't symmetrical - get it as well centered as you can then if necessary tweak the angles in the code (line 56 of robot-car.ino)Note that when you start rewiring the car to add the speed sensors, (e.g. followinghttps://dronebotworkshop.com/robot-car-with-speed-sensors/), if you want Prof.E's robot-car.ino sketch to still work with your rewired car, you'll need to keep the pin definitions (lines 13 to 26) up to date with your wiring changes.You may wish to move the ultrasonic sensor pins to the analog pin group (which can also work as digital pins) as the 5V on that group is from the Arduino, not the H-bridge so is likely to be less noisy which may improve detection range and small object sensitivity. I use pin A2, A3. Try not to use A4, A5 as they conflict with any I2C bus sensors. I kept A0, A1 free to plug in a wiredjoystickon several meters of cable so I could write a sketch that let me drive the car manually. It had the joystick switch connected to D13 and used that input to toggle the motors on/off.Later I added an ESP8266 runningESP-linkas a serial to WiFi bridge, which gave me a remote serial link that functioned for monitoring, control and even uploading new sketches from the Arduino IDE without plugging in the USB cable. It needed some software shenanigans at the Windows PC end to make the link appear as an ordinary COM port!

author: Larsson55
author_rank: Regular Contributor
timestamp: March 29, 2025, 05:51:29 pm
content: Out of curiosity I opened Arduino IDE and all sections I posted earlier are there. So this is done and I do look line by line to understand what it does. Right now it's confusing but eventually I will get to know more.The servo is a "can of worms" for me, somehow I believe when I remove the servo from the white splines I will not be able to re install as the screw hole in the plastic shaft will no be able to hold tight anything. Anyway I will do what you describeThe link for the speed sensors is quite interesting, I will take care of the pin numbering and relocate to analog groupThe additions to your project sound interesting although I don't understand the benefits of adding a WiFi bridge. I was thinking, for later, to add a remote control since from my previous experience the Elegoo kit came with a remote control + a small board and perhaps I may be able to add these items to my car and have the benefit of remote control if possible.BTW I plan not to relocate the battery pack as I mentioned earlier, too much work for not a real reason, after all the car is far away from been a "racing" car...Many thanks Ian for your outstanding help

author: Ian.M
author_rank: Super Contributor
timestamp: March 29, 2025, 06:20:37 pm
content: Certainly try the high mounted battery pack. Worst that happens is it takes a non-damaging nose-dive when it detects something in front and tries to quickly reverse, or if you try to climb the edge of a rug or carpet. If it becomes a problem, its easy enough to move - two wires out + two mounting screws.The plastic gear SG90 servos can generally have their arms removed and replaced tens of times, so long as you *always* use the same screw (I've seen them come with different thread pitch screws), and after the first time, turn the screw slowly back up to a turn as you start to insert it trying to feel where it drops into the existing thread it initially cut in the shaft before tightening it down. They also aren't very expensive - a couple of bucks each in quantity.The WiFi bridge lets me watch serial.print() status data from the robot as it roams around. If I put more time into it I could e.g. write an app to control it from a phone or tablet, or build a WiFi enabled remote for it. I had the ESP8266 board 'on the shelf' so the only real cost was the level shifter and a switch to change from USB to WiFi serial link.I also fitted an I2C interface line following sensor array under the nose of the robot, but didn't get very far coding that (I had good line detection but problems tracking) before life in general caused me to put the robot on the shelf . . .

author: Larsson55
author_rank: Regular Contributor
timestamp: March 29, 2025, 08:37:34 pm
content: Regarding the battery pack in my robot car this project is my first dive to learn Arduino as a hobby and after this project is completed most likely I will never use the robot car except perhaps for parts, so the battery pack location is not important.Also now I remember that I do have another servo motor from my Elegoo kit which I may be able to use assuming it's the right model. I'm aware about threading a screw into plastics to follow the existing threads on the shaft.Now I understand about the WiFi bridge, very interesting and complex for my current knowledge but who knows how fast I will progress in this field....and discover later on that I may need one too.It is true that whatever we are doing today the only unknown fact is "life in general" which we have no control and only hopping for the best

author: Larsson55
author_rank: Regular Contributor
timestamp: March 30, 2025, 08:10:12 am
content: I did not have to removed the servo from its brackets cause it looked solid. But I removed the assembly from the chassis (see picture attached) and holding it in my hand I follow your instructions and run the robot-car.ino. It only moves from about 1 o'clock and 10 o'clock in 3 jerky steps (not smooth at all). Perhaps when it is at 12 o'clock I should stop? I don't know what else I can do, please let me know. Thanks

author: Ian.M
author_rank: Super Contributor
timestamp: March 30, 2025, 03:17:16 pm
content: I've just checked the SG90 servo that came with my Elegoo Mega 2560 kit using the examples => Servo =>Sweep sketch. It moves through approx. 160°, slightly asymmetric about its nominal center position (myservo.write(90);). The servo on my robot car is the same.However Prof. Edwards' robot-car.ino uses a smaller range (60° to 120°) in 10° steps. You should see it move 30° either side of the centerline, with six steps end to end (seven positions).If you aren't getting that, either your servo is fouling on the mount base or maybe the cable is pulling tight and stopping it, or the servo is bad.Try this test code, that initially centers (90°) for two seconds then goes (nominally) from 0° to 180° in four 45° steps waiting one second at each step and two at the end, then goes back from 180° to 0° in eighteen 10° steps waiting half a second at each step and again two at the end.If you don't get the expected 160° movement or the correct number of steps, remove the mount base from the servo shaft and push-fit (no screw) one of the spare servo arms as a pointer and check it again to determine whether it was fouling or if you've got a bad servo.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 30, 2025, 05:26:27 pm
content: Sorry for the delay Ian, the new sketch you provided makes the servo work very good, swipe 180 deg. So is the code I had wrong? What should I do?

author: Larsson55
author_rank: Regular Contributor
timestamp: March 30, 2025, 09:21:49 pm
content: Another question I have is when all wiring is done in the robot and I disconnect the USB cable how the robot knows the code to run? does it have an internal memory or something?

author: brucehoult
author_rank: Super Contributor
timestamp: March 30, 2025, 11:14:41 pm
content: Quote from: Larsson55 on March 30, 2025, 09:21:49 pmAs has been told to you many times, microcontrollers have internal flash memory that stores the program they run, every time. Once the program has been sent to it, it doesn't matter whether the USB cable is connected or not (unless it is also supplying the electricity to run it).The normal use of microcontrollers is to load a program into them, then build them into some consumer device such as a toothbrush or microwave oven or washing machine and then they run the same program forever.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 31, 2025, 12:09:07 am
content: Thank you brucehoult, I know it was mentioned before but it was not clear to me. Now with your clear answer I understand it

author: Ian.M
author_rank: Super Contributor
timestamp: March 31, 2025, 02:26:48 am
content: Quote from: Larsson55 on March 30, 2025, 05:26:27 pmProf. E. chose to use a smaller servo sweep in his robot code. If the sweep limits are symmetric about the centerline its probably working correctly. It only stops at each angle long enough to do an ultrasound ping to check for obstacles. In the main loop, you can see what it does with the results:Code:// Main loop:// Get the next sensor reading// If anything appears to be too close, back up// Otherwise, go forwardvoid loop() {readNextDistance();// See if something is too close at any angleunsigned char clear = 1;for (unsigned char i = 0 ; i < NUM_ANGLES ; i++)if (distance < 300)clear = 0;if (clear) {// Nothing in our way: go forwardgo(LEFT, 255);go(RIGHT, 255);} else {// Something's nearby: back up leftgo(LEFT, -180);go(RIGHT, -80);}// Check the next direction in 50 msdelay(50);}That checks for any obstacle within 300 mm in the forward arc the sensor sweeps, and if anything is that close, backs up and turns, always in the same direction. It does *NOT* attempt to map the surroundings, or even decide which way to turn.Its up to you to improve this object detection and collision avoidance mechanism. One of the enhancements I was considering was to widen the sweep and 'map' nearby objects, scrolling the map as the car moved, and dropping objects that scrolled off the map. By keeping track of objects to the sides, and using the map to decide the action when an object close ahead is detected, it would be possible to avoid slamming the rear of the car into an adjacent wall when backing up and turning.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 31, 2025, 04:02:02 am
content: Sorry Ian but I have no clue how to do what you are asking me to do. Yes i can read a little and understand but to change the code is impossible for me. In addition. I dont even know how to patch the revised code to the existing robot-car.ino. Eventually I hope I can learn a bit of coding but for now it's too esrly for me to even attempt to change the code.Many thanks

author: Ian.M
author_rank: Super Contributor
timestamp: March 31, 2025, 07:40:54 am
content: Unfortunately robotics is very coding heavy. If you cant code, you cant create your own behaviour patterns for the robot or even successfully customise other people's robot code. All I can suggest is persevering with learning how to design algorithms to solve a problem and express them in code. This is not something you can get good at quickly without putting in the hours of study and practice on a regular basis.You may need to take a step back from the robot project and just do some projects with your Arduino kit to fill in the basics, whenever possible trying to write your own sketch from scratch, rather than starting with someone else's code and tweaking it. Exception: when using libraries to handle the low-level 'grunt work' of interfacing to ICs, sensors and other devices, the documentation is often a bit lacking and you will probably need to start from supplied example code and customise it to meet your needs.Once you get good at coding, you will be able to understand other people's code easily, and then it can be a time-saver to customise existing well-written code rather than starting from scratch.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 31, 2025, 07:59:39 am
content: I completely understand Ian what you are saying but this is my first attempt to make an Arduino project as a hobby and never thought I will have to do coding at the very beginning. Yes eventually as I go along I will learn coding but it's too early for my to do it now. Anyway I intent to continue and try to change the code to the best I can, it doesn't have to be perfect but if the wheels are spinning it's enough for me. I enjoyed to make this car and learned a lot but I know there is much more to learnMany thanks again.

author: Ian.M
author_rank: Super Contributor
timestamp: March 31, 2025, 03:47:29 pm
content: Sometimes what appears to be very simple stuff is harder than it looks. e.g. if you want to flash two LEDs at different speeds.Flashing *ONE* LED at a fixed speed is *simple*, so simple its one of the introductory 01.Basics Arduino examples, called Blink.ino:Code:// the setup function runs once when you press reset or power the boardvoid setup() {// initialize digital pin LED_BUILTIN as an output.pinMode(LED_BUILTIN, OUTPUT);}// the loop function runs over and over again forevervoid loop() {digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)delay(1000); // wait for a seconddigitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOWdelay(1000); // wait for a second}To make the delay variable, controlled by a potentiometer (1K tro 10K is suitable) between +5V and Gnd, wiper to A0 is also fairly simple. Again its supplied as an example sketch, this time under 03.Analog, called AnalogInput.ino:Code:int sensorPin = A0; // select the input pin for the potentiometerint ledPin = 13; // select the pin for the LEDint sensorValue = 0; // variable to store the value coming from the sensorvoid setup() {// declare the ledPin as an OUTPUT:pinMode(ledPin, OUTPUT);}void loop() {// read the value from the sensor:sensorValue = analogRead(sensorPin);// turn the ledPin ondigitalWrite(ledPin, HIGH);// stop the program for <sensorValue> milliseconds:delay(sensorValue);// turn the ledPin off:digitalWrite(ledPin, LOW);// stop the program for for <sensorValue> milliseconds:delay(sensorValue);}I'm sure you can see how similar that is to the Blink sketch, and the analog input stuff is fairly obvious.The difficulty comes when you want to flash two LEDs with variable speed independently. Adding a second potentiometer controlling the A1 pin voltage, and modifying the code to add another sensor pin and LED pin is simple enough. However, the problem is delay() blocks the main loop from executing any further while its timing so with two LEDs, so not knowing which will be the next to switch on or off, you have to throw away the above concept of an on delay and an off delay in a simple loop. Instead you need to master the concept of non-blocking timing using the Arduinomillis()function.More to follow when you've had a chance to bang your head against this problem yourself!You may wonder where I am going with this, but you'll find performing different actions effectively concurrently in a loop without any loop-blocking delays is a key skill you will need to code more advanced behaviour for the robot.

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 31, 2025, 03:48:43 pm
content: Quote from: Ian.M on March 31, 2025, 07:40:54 am"Well written code" there in lies the problem. There is a lot of crappy written code, especially in the Arduino world.To Larsson55, don't let that discourage you. My advice is to, when the robot is done, take a look at coding in C.https://www.w3schools.com/c/index.phpprovides a basic start with C coding, but there are plenty other sites that can be found.Keep in mind that basic C means only the syntax and basic commands like if, for, while, etc, Functions like printf, although commonly used are not part of basic C. These kind of functions are extensions provided via libraries. It is possible to write fully functional code without any library at all, just using the basic parts of C.What is used in the Arduino world is basic C with a splash of C++, but you can get very far with just C when working with Arduino boards.

author: Larsson55
author_rank: Regular Contributor
timestamp: March 31, 2025, 05:32:09 pm
content: Thank you both for your time and education, the link for learning C looks very interesting and will try to learn from it at least the basics,

author: Larsson55
author_rank: Regular Contributor
timestamp: April 01, 2025, 05:36:13 pm
content: I have done the wiring except the two wheels speed sensors, I open the .ino file and only the camera runs but not the wheels. In the attached pictures the car sits on top of a pc of wood. What's wrong?Thanks

author: pcprogrammer
author_rank: Super Contributor
timestamp: April 01, 2025, 06:41:41 pm
content: You can test the working of the motors by disconnecting the control wires to the L298N from the Arduino and connect them to either ground or 5V to control the H bridges. See the attached datasheet.Make the enable signal high and control the motor with the two in signals. Set one high and the other low to make the motor run.

author: Larsson55
author_rank: Regular Contributor
timestamp: April 01, 2025, 08:10:10 pm
content: Thanks pcprogrammer, I removed the wiring from the bridge and only left the +5V. The when I start Arduino the ultrasonic sensor was going from 0 to 1180 deg but then it changed to 80 and about 110 deg beck and forth. No motors runningSorry but I don't understand the following:Which is the enable signal and how I can make it high?I also want to mention that where I connected all wiring at the L298 bridge I had to jumpers on either end of the pins and had to remove both jumpers to complete the wiring. Both jumper are still removed

author: Larsson55
author_rank: Regular Contributor
timestamp: April 02, 2025, 05:32:09 am
content: Well, now it's working folks, I don't know what I did but most likely some of the wiring from the bridge to the shield were not sitting properly. The only problem is the ultrasonic only turn rapidly left/right from about 80 to 110 deg. and the wheels are spinning forward. When I put my hand in front of the ultrasonic the wheels are reversing. Any idea how I can implement the code Ian send me where the ultrasonic turns 90 to 180 deg?Thanks

author: pcprogrammer
author_rank: Super Contributor
timestamp: April 02, 2025, 06:09:43 am
content: On the right image shown on this pagehttps://components101.com/modules/l293n-motor-driver-moduleyou can see the 2.54mm single row male header with the names of the signals beside it.ENA, IN1, IN2 control the motor on OUT1, OUT2. ENB, IN3, IN4 control the motor on OUT3, OUT4.The ENx signals are the enable signals and can be held, I assume, high with the jumpers I see installed on the image. When the jumpers are removed and the enable signals are connected to the Arduino UNO, it is possible to control the motor speed with PWM. (Pulse Width Modulation)The INx, INy signals control the direction of the movement. Depending on how the motor is connected to OUTx, OUTy, the motor goes forward when INx is high and INy is low, backwards when INx is low and INy is high, and stops when both IN signals have the same level.Edit: to make a signal high you connect it to the 5V supply. Be aware that other logic can work with other supply voltages, like for instance 3.3V, so don't assume that high is always 5V. To make it low you connect it to the ground.

author: pcprogrammer
author_rank: Super Contributor
timestamp: April 02, 2025, 06:36:43 am
content: About the servo control. The code shown below is the section of Stephen A. Edwards his sketch that handles the servo positioning and reading of the distance. In the Arduino world the main source code is called a sketch.Code:#define NUM_ANGLES 7unsigned char sensorAngle = { 60, 70, 80, 90, 100, 110, 120 };unsigned int distance;// Scan the area ahead by sweeping the ultrasonic sensor left and right// and recording the distance observed. This takes a reading, then// sends the servo to the next angle. Call repeatedly once every 100 ms or so.void readNextDistance(){static unsigned char angleIndex = 0;static signed char step = 1;distance = readDistance();angleIndex += step;if (angleIndex == NUM_ANGLES - 1) step = -1;else if (angleIndex == 0) step = 1;servo.write( sensorAngle );}In the above code the line shown below sets the positions the servo is moved to.Code:unsigned char sensorAngle = { 60, 70, 80, 90, 100, 110, 120 };There are seven steps, which is indicated with the line shown below.Code:#define NUM_ANGLES 7The function "void readNextDistance()" shown in the code above is called from the setup function and the loop function to move the servo to the next position and scan a new distance.The call shown below is used to move the servo to the next position.Code:servo.write( sensorAngle );The positions are stepped through with the code shown below.Code:angleIndex += step;if (angleIndex == NUM_ANGLES - 1) step = -1;else if (angleIndex == 0) step = 1;In the setup function the code below is executed to initialize the seven distances, by scanning the seven servo positions.Code:// Scan the surroundings before starting offservo.write( sensorAngle );delay(200);for (unsigned char i = 0 ; i < NUM_ANGLES ; i ++)readNextDistance(), delay(200);In the main loop, that is constantly executed the servo is moved to a new position at every iteration.Code:void loop() {readNextDistance();// See if something is too close at any angleunsigned char clear = 1;for (unsigned char i = 0 ; i < NUM_ANGLES ; i++)if (distance < 300)clear = 0;if (clear) {// Nothing in our way: go forwardgo(LEFT, 255);go(RIGHT, 255);} else {// Something's nearby: back up leftgo(LEFT, -180);go(RIGHT, -80);}// Check the next direction in 50 msdelay(50);}The function to do this is called right at the top of the loop function. After that the distances are checked to see if there are objects to close. As long as there is nothing in the way the variable "clear" will remain 1, and the motors will be steered forward again. As soon as there is something in the way, the variable "clear" is set to 0 and the motors will be steered backward with different speeds to make the robot turn.At the end of the loop it waits 50ms and then reads the next distance again, and so on.

author: Larsson55
author_rank: Regular Contributor
timestamp: April 02, 2025, 07:42:31 am
content: Many thanks for your time pcprogrammer,On the L298N I have removed the jumpers from the ENA & ENB otherwise I wouldn't have been able to make my connections.If I want to revise the code in my sketch, just delete what I want, write my new lines and verify/compile?

author: Larsson55
author_rank: Regular Contributor
timestamp: April 02, 2025, 08:54:14 am
content: It works good except the range of angles is too small. Can I revise the code and have angles from 10 to 150 in 15 steps?

author: pcprogrammer
author_rank: Super Contributor
timestamp: April 02, 2025, 09:51:26 am
content: Yes, you can modify the code as you want and then verify/compile/upload the result.Post your changes to the sketch here for us to check if you made the right changes to extend the number of angles to 15 with a range from 10 to 150 degrees. With my explanation of the code, you should be able to figure out what to change.

author: Ian.M
author_rank: Super Contributor
timestamp: April 02, 2025, 01:46:48 pm
content: Just increasing the angle range and number of steps in that range probably wont do what you want. As I said earlier, Prof.E's code scans nominally 30° either side of the centerline, looking for an obstruction within 300 mm of the sensor. The HC-SR04 sensor's beam width is specified as a max. angle from centerline of 15° (though this isn't particularly trustworthy), so Prof.E's code should detect objects in a 90° forward arc, 45° either side of the centerline.If you do the math (simple trig.) you'll find that's approx 200mm either side of the centerline or a 400mm wide clear path, plenty for a 165mm wide robot. The 400 mm path width allows enough room for tail-swing when turning as the total length of the robot is 210mm, with approx 140mm behind the axles.Increasing the arc to 125° (nom. 140° - scanning 10° to 150°) would result in object detection up to about 77° off the centerline, i.e. without changing the algorithm, it would require a nearly 600mm wide clear path. As the algorithm has no state memory, it will be vulnerable to getting between two obstacles or into a corner then repeatedly reversing in a small circle, bashing into stuff backwards as it tries to find enough space in the arc ahead of it.If you want the increased scan arc to be useful, then you need to separate it into sectors. Only use the center sector for obstacle avoidance when going straight forward. When an obstruction is detected in the center sector, use the left and right sectors to determine which way to back up and turn. i.e. don't turn towards a detected obstruction, and if there are obstructions to both sides, its probably best to do a 180° on the spot turn, swinging the tail to whichever side has the greater distance to obstruction.Note that to do accurate on-the-spot turns, you really need to get the motor encoders working - seehttps://dronebotworkshop.com/robot-car-with-speed-sensors/They are (of course!) using different pins to connect to the H-bridge:Code:const byte MOTOR_A = 3; // Motor 2 Interrupt Pin - INT 1 - Right Motorconst byte MOTOR_B = 2; // Motor 1 Interrupt Pin - INT 0 - Left Motor// {some stuff snipped}// Motor Aint enA = 10;int in1 = 9;int in2 = 8;// Motor Bint enB = 5;int in3 = 7;int in4 = 6;vs. Prof.E's wiring:Code:// Ultrasonic Module pinsconst int trigPin = 13; // 10 microsecond high pulse causes chirp, wait 50 usconst int echoPin = 12; // Width of high pulse indicates distance// Servo motor that aims ultrasonic sensor.const int servoPin = 11; // PWM output for hobby servo// Motor control pins: L298N H bridgeconst int enAPin = 6; // Left motor PWM speed controlconst int in1Pin = 7; // Left motor Direction 1const int in2Pin = 5; // Left motor Direction 2const int in3Pin = 4; // Right motor Direction 1const int in4Pin = 2; // Right motor Direction 2const int enBPin = 3; // Right motor PWM speed controlso yiu'll need to do some rewiring and also modify robot-car.ini if you want to be able to go back to it for comparison.N.B. the motor enables need to be on PWM capable pins, and the speed sensors on interrupt (INTn) capable pins (not just PCINT). See:https://www.circuito.io/blog/arduino-uno-pinout/

author: Langdon
author_rank: Frequent Contributor
timestamp: April 02, 2025, 02:10:16 pm
content: Just use a 12v power supply for now.A "wall wart" will be fine.If you have a desktop Mac with a FireWire port, you can use that to provide 12V.Or you can steal power off the 12V rail of your PC.(may break computer, do so at your own risk)Make sure you filter the power from the computer to avoid introducing harmful noise and current and voltage spikes into your PC/Mac.

author: Ian.M
author_rank: Super Contributor
timestamp: April 02, 2025, 02:18:52 pm
content: Quote from: Langdon on April 02, 2025, 02:10:16 pmHuh?Are you in the wrong topic?N.B. The CH340G interface Arduino Uno clone supplied in most robot car kits uses a Chinese '1117' regulator for its 5V rail, which depending on the supplier may have an abs. max. input voltage as low as 12V, and there isn't a lot of copper area round the regulator to heatsink it. Powering it with 12V from your computer would be unwise . . . I use a 9V regulated wallwart when bench-testing my robot.

author: Larsson55
author_rank: Regular Contributor
timestamp: April 02, 2025, 05:15:18 pm
content: I'm going into an unchartered territory here folks but I printed my robot-car.ino and will try to do the changes I "think" I need regarding the servo range based on the info from pcprogrammer and Ian. Will post back the results BEFORE using the revised code.I'm only a beginner but perhaps I will get the lucky! Otherwise I will give up!

author: Larsson55
author_rank: Regular Contributor
timestamp: April 02, 2025, 05:41:52 pm
content: Another gray are is the L298N wiring and I include a screenshot from the link provided in post #149 from pcprogrammer.There are 7 wires to be connected to the Sensor Shield but there are only 6 pins available. Pins ENA and ENB have jumpers so I have removed both jumpers and this provides 2 extra pins. Looking at Pro. Edwards step 9 document it's not clear which pins he is using to connect the last wire. Any help here?

author: Larsson55
author_rank: Regular Contributor
timestamp: April 02, 2025, 05:43:44 pm
content: Sorry. I forgot to include in my last post the screenshot of the L298

author: Ian.M
author_rank: Super Contributor
timestamp: April 02, 2025, 06:46:40 pm
content: Prof.E's wiring has a 5V wire from one of the extra end pins on the L298N H-bridge board, where the jumpers go if you aren't using ENA and ENB.You don't need it as you have already wired 5V from the H-bridge to the Sensor Shield via their screw terminals*so you only need to fit six wires from the header pins nearest the H-bridge board edge to the numbered sensor shield pins next to the silkscreen marking 'Sensor Shield'.The H-bridge and the Arduino + sensor shield already share a common ground via the Arduino DC jack, but if you were going to add an extra wire, a black ground wire between the H-bridge GND and the Sensor Shield GNDscrew terminalswould help.Here's the power wiring diagram you posted in reply #112For the avoidance of doubt, the extra ground wire would go from the middle screw of the three way terminal block on the H-bridge (which already has two other wires) to the screw nearest the reset switch on the Sensor Shield's two way screw terminal block, which doesn't currently have any wire.* We know the 5V is there because the servo works!

author: Larsson55
author_rank: Regular Contributor
timestamp: April 02, 2025, 08:24:47 pm
content: If I remove the wire from pin +5V only one wheel is turning. I attach a picture of the pins between L298 and the sensor shield showing the 7 wires where are connectedRegarding the code for the servo I include a revised text file of the .ino code which I think it may help. Since the code "sweep" which Ian posted before is working I thought the same code may do the job. If you scroll down the txt file you will see what I propose. This is a beginners attempt revising a code and most likely is incorrect but that's the best I can do

author: pcprogrammer
author_rank: Super Contributor
timestamp: April 03, 2025, 05:40:26 am
content: Sorry, but I have to say that you clearly do not understand a single word we post.The change you made to the code shows this quite clear. Having two setup and two loop functions is not going to work.Also Ian did not tell you to remove the +5V from the screw terminal on the L298N module. He indicated that there are only 6 wires needed from the 2.54mm header on the L298N module because the seventh wire is already connected, and this is the one to the +5V of the screw terminal.Based on this thread, I'm not so sure that microcontroller electronics is the hobby for you.Reread my post explaining the code and rethink what would need to be changed to make the servo sweep wider, and hopefully you see the light. Otherwise best to give up and look for something else to spend your free time on.

author: Larsson55
author_rank: Regular Contributor
timestamp: April 03, 2025, 08:16:13 am
content: No problem pcprogrammer, I understand how you feel and I don't blame you however there is a misundertanding here on the people who try to help me and which I appreciate very much for all the help provided.My first post on this thread was posted in the "BEGINNERS" section. Please let me ask you how you expect a beginner to write and understand code? Regardless of all the help you provided a beginner as far as I know knows nothing about code and all the problems here is about code, nothing major about building the robot wiring which I have successfully completed.Despite all the code problems, the robot is now working very well except the problem with the HC-SR04 which is working too fast left/right but still functions as it should.No hard feeling here mate, I have been on various forums for at least 20 years when I started learning cnc machines and I have built now I am on my 14th machine. These are table mill machines which I make them all out of 3/8" thick aluminum plate/flatbar and have lots of controls, limit switches, stepper motors and VFD driven high speed water cooled spindles.In the 80's I took and finish a course on MS Basic out of my interest in PC's and later I study myself programming in MS Access and Excel and have made for my work many programs for my work. I can't say I'm an expert in programming but I can manage. Now on this robot car I managed to reduce the speed of the 2 wheels cause was running too fast for me so I did something besides that I'm only a beginner. On my next project I will know more.....What I don't understand is why no one gave me the few code lines I needed instead of spending your time to give to a beginner all these code sample which I don't understand. As I said no hard feelings here, I appreciate very much all the time you all spent to help me.

author: RoGeorge
author_rank: Super Contributor
timestamp: April 03, 2025, 08:28:45 am
content: Quote from: pcprogrammer on April 03, 2025, 05:40:26 amPlease don't do that, don't be judgemental. Nobody want's to know your opinion regarding other forum members. Some are beginners, others are advanced. They may be of any age and of all professions, from kids to lifetime EEs retired.We gather on this forum to talk about projects. Please keep the talk about projects, not about people. It is OK to say "this wiring has a mistake", or "this idea is wrong". It is NOT ok to say "you mistake wiring", or "your are wrong".If you think your advice is not understood, then just don't follow the topic any more. Don't be a downer.

author: SteveThackery
author_rank: Super Contributor
timestamp: April 03, 2025, 12:27:44 pm
content: Quote from: RoGeorge on April 03, 2025, 08:28:45 amActually I don't entirely agree,@RoGeorge. I am not referring to the OP here, but we've all come across individuals who really don't want to make the effort to understand and embrace the advice they've been given, and just want someone to deliver them a step-by-step set of instructions.Then there are those who are willing to make the effort but just skim-read the advice they are given instead of sitting down, reading it over and over and really thinking hard about it.The first type come back to the forum every five minutes with "I've added that resistor, now what should I do?" type questions. The second type come back with questions that have already been answered, if only they would take the time to readand thinkabout them.@pcprogrammerhas been pretty heroic throughout this thread, patiently contributing a lot. And he is right: maybe the OP's expectations are way off base. For example, the OP has repeatedly said that he didn't expect or want to get involved with coding on his first Arduino project! That is a remarkable and naive expectation which suggests to me that he should have started his hobby with something other than Arduino.So, let's cut@pcprogrammersome slack, eh? And maybe the OP does need a sharp word to make them stop and think for a moment.

author: SteveThackery
author_rank: Super Contributor
timestamp: April 03, 2025, 12:31:11 pm
content: Quote from: Larsson55 on April 03, 2025, 08:16:13 amBecause nobody comes here to do the work for you. They expectyouto do the work, while they advise and guide you. They do this because they want you tolearn. You don't learn by cutting and pasting someone else's code into your project.

author: Langdon
author_rank: Frequent Contributor
timestamp: April 03, 2025, 12:56:46 pm
content: Quote from: SteveThackery on April 03, 2025, 12:31:11 pmHmm...Not always.Sometimes reading someone else's working code shows you a new way to do something you didn't even know was possible.For example:Code:(x == 5) ? 5 : 9It depends.It can be nice to have a scaffold of working code to build and improve upon.Much less intimidating than just coing something from scratch.Plus, sometimes you're not in the mood to learn, you just want the stupid thing to work!

author: Ian.M
author_rank: Super Contributor
timestamp: April 03, 2025, 03:10:41 pm
content: Quote from: Ian.M on March 31, 2025, 03:47:29 pmAs promised back in reply #133, here's a solution to the 'concurrent' timing for independent LEDs problem. Its not the most elegant way to handle this, but it does show how you can do stuff independently with more than one thing at consistent intervals even though your main loop() is 'spinning' far far faster.I do hope you've at least tried to solve this problem for yourself. If so, try the attached sketch (which includes wiring details) on a spare Arduino, study it, and feel free to ask how it works. If not, please have a go at the problem *before* downloading this sketch!On the subject of not giving you the code you want:Apart from our desire to teach you rather than give you a 'black box' solution you cant understand, there's also the problem of our ability to test the code we propose. Few of us have a potentially compatible 2WD robot, and those of us who do aren't that likely to have it wired the same as your one, and probably don't have an opportunity to get it out, set it up the same and test run any code we offer you, as we have our own work and projects competing for our time. A few snatched minutes on a coffee break to quickly reply here with hints and suggestions for you to develop yourself is a lot easier to fit in, and is less likely to turn into an ongoing uncompensated time sink!

author: Picuino
author_rank: Super Contributor
timestamp: April 03, 2025, 03:22:00 pm
content: To run concurrent tasks with Arduino I recommend the SCoop library.It is old and does not receive updates, but it works quite well and is much simpler than FreeRTOS.https://code.google.com/archive/p/arduino-scoop-cooperative-scheduler-arm-avr/https://github.com/fabriceo/SCoopDownload:https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/arduino-scoop-cooperative-scheduler-arm-avr/SCoop%20V1.2%20New%20Year%20Pack.zipEDIT: Code exampleCode:/*Multiple BlinksDemonstrates the use of the SCoop library in the same way than with original Scheduler.hHardware required :* LEDs connected to pins 11, 12, and 13created 8 Oct 2012by Cristian MaglieModified byScott Fitzgerald 19 Oct 2012This example code is in the public domainhttp://arduino.cc/en/Tutorial/MultipleBlinks*/// Include Scheduler since we want to manage multiple tasks.#include <SCoop.h>int led1 = LED_BUILTIN;int led2 = 12;int led3 = 11;void setup() {Serial.begin(9600);// Setup the 3 pins as OUTPUTpinMode(led1, OUTPUT);pinMode(led2, OUTPUT);pinMode(led3, OUTPUT);// Add "loop2" and "loop3" to scheduling.// "loop" is always started by default.Scheduler.startLoop(loop2);Scheduler.startLoop(loop3);Scheduler.start(); // this is needed with SCoop, not with Android original Scheduler}// Task no.1: blink LED with 1 second delay.void loop() {uint32_t timer1=0;digitalWrite(led1, HIGH);// IMPORTANT:// When multiple tasks are running 'delay' passes control to// other tasks while waiting and guarantees they get executed.Scheduler.delay(1000);digitalWrite(led1, LOW);Scheduler.delay(1000);}// Task no.2: blink LED with 0.1 second delay.void loop2() {uint32_t timer1=0;digitalWrite(led2, HIGH);Scheduler.delay(100);digitalWrite(led2, LOW);Scheduler.delay(100);}// Task no.3: accept commands from Serial port// '0' turns off LED// '1' turns on LEDvoid loop3() {if (Serial.available()) {char c = Serial.read();if (c=='0') {digitalWrite(led3, LOW);Serial.println("Led turned off!");}if (c=='1') {digitalWrite(led3, HIGH);Serial.println("Led turned on!");}}// IMPORTANT:// We must call 'yield' at a regular basis to pass// control to other tasks.yield(); // not really needed with scoop as there is already one yield() call in the library}

author: Picuino
author_rank: Super Contributor
timestamp: April 03, 2025, 03:45:51 pm
content: Another more complicated solution is to use millis() to make timers of different frequencies.SIMULATION:https://wokwi.com/projects/427227339400457217Code:// Define constantsconst int led1 = 10;const int led2 = 11;const int led3 = 12;// Define global variablesunsigned long int time1, time2, time3;char led1_state, led2_state, led3_state;void setup() {// Setup the 3 pins as OUTPUTpinMode(led1, OUTPUT);pinMode(led2, OUTPUT);pinMode(led3, OUTPUT);// Setup times and led statestime1 = time2 = time3 = 0;led1_state = led2_state = led3_state = LOW;}void loop() {long int now;now = millis();if (time1 < now) {time1 = now + 230;led1_state = ! led1_state;digitalWrite(led1, led1_state);}if (time2 < now) {time2 = now + 510;led2_state = ! led2_state;digitalWrite(led2, led2_state);}if (time3 < now) {time3 = now + 1200;led3_state = ! led3_state;digitalWrite(led3, led3_state);}}Diagram:Code:{"version": 1,"author": "Anonymous maker","editor": "wokwi","parts": [{ "type": "wokwi-breadboard-mini", "id": "bb1", "top": -59, "left": 64.8, "attrs": {} },{ "type": "wokwi-arduino-uno", "id": "uno", "top": 96.6, "left": -0.6, "attrs": {} },{ "type": "wokwi-led", "id": "led1", "top": -80.4, "left": 71, "attrs": { "color": "red" } },{"type": "wokwi-led","id": "led2","top": -80.4,"left": 109.4,"attrs": { "color": "red" }},{"type": "wokwi-led","id": "led3","top": -80.4,"left": 147.8,"attrs": { "color": "red" }},{"type": "wokwi-resistor","id": "r1","top": 4.8,"left": 66.65,"rotate": 90,"attrs": { "value": "150" }},{"type": "wokwi-resistor","id": "r2","top": 4.8,"left": 105.05,"rotate": 90,"attrs": { "value": "150" }},{"type": "wokwi-resistor","id": "r3","top": 4.8,"left": 143.45,"rotate": 90,"attrs": { "value": "150" }}],"connections": [[ "led1:A", "bb1:3t.b", "", [ "$bb" ] ],[ "led1:C", "bb1:2t.b", "", [ "$bb" ] ],[ "led2:A", "bb1:7t.b", "", [ "$bb" ] ],[ "led2:C", "bb1:6t.b", "", [ "$bb" ] ],[ "led3:A", "bb1:11t.b", "", [ "$bb" ] ],[ "led3:C", "bb1:10t.b", "", [ "$bb" ] ],[ "r1:1", "bb1:3t.d", "", [ "$bb" ] ],[ "r1:2", "bb1:3b.h", "", [ "$bb" ] ],[ "r2:1", "bb1:7t.d", "", [ "$bb" ] ],[ "r2:2", "bb1:7b.h", "", [ "$bb" ] ],[ "r3:1", "bb1:11t.d", "", [ "$bb" ] ],[ "r3:2", "bb1:11b.h", "", [ "$bb" ] ],[ "uno:GND.1", "bb1:2t.d", "black", [ "v-19.2", "h-28.5" ] ],[ "bb1:2t.c", "bb1:6t.c", "green", [ "v0" ] ],[ "bb1:6t.d", "bb1:10t.c", "green", [ "v0" ] ],[ "uno:12", "bb1:3b.i", "green", [ "v-28.8", "h-37.9" ] ],[ "uno:11", "bb1:7b.i", "green", [ "v-38.4", "h-9" ] ],[ "uno:10", "bb1:11b.i", "green", [ "v-28.8", "h19.9" ] ]],"dependencies": {}}

author: Picuino
author_rank: Super Contributor
timestamp: April 03, 2025, 03:56:23 pm
content: If you want to switch the LEDs on and off at different times, here is a slightly more complex solution:Code:int led1 = 10;int led2 = 11;int led3 = 12;long int time1, time2, time3;int led1_state, led2_state, led3_state;void setup() {// Setup the 3 pins as OUTPUTpinMode(led1, OUTPUT);pinMode(led2, OUTPUT);pinMode(led3, OUTPUT);// Setup times and led statestime1 = time2 = time3 = 0;led1_state = led2_state = led3_state = LOW;}void loop() {long int now;now = millis();if (time1 < now) {time1 = now + 230; // On and off time = 230 msled1_state = ! led1_state;digitalWrite(led1, led1_state);}if (time2 < now) {if (led2_state == LOW) {led2_state = HIGH;time2 = now + 100; // ON time = 100 msdigitalWrite(led2, led2_state);}else {led2_state = LOW;time2 = now + 810; // OFF time = 810 msdigitalWrite(led2, led2_state);}}if (time3 < now) {if (led3_state == LOW) {led3_state = HIGH;time3 = now + 1200; // ON Time = 1200 msdigitalWrite(led3, led3_state);}else {led3_state = LOW;time3 = now + 300; // OFF Time = 300 msdigitalWrite(led3, led3_state);}}// Rest of the program}

author: Ian.M
author_rank: Super Contributor
timestamp: April 03, 2025, 04:02:41 pm
content: One needs to be careful using millis() if your runtime can ever approach 50 days, as it will overflow and wrap back to zero, which depending on how you've done your comparisons and other math, may cause a timing glitch or even a hang!Seehttp://www.gammon.com.au/millis

author: Picuino
author_rank: Super Contributor
timestamp: April 03, 2025, 04:15:55 pm
content: No glitch solution (with 1 led):Code:// Constantsconst int sensorPin1 = A0;const int led1 = 10;const unsigned long int HALF_TIME = 0x80000000;// Global variablesunsigned long int time1;char led1_state;void setup() {// Setup the pin as OUTPUTpinMode(led1, OUTPUT);// Setup times and led statestime1 = 0;led1_state = LOW;}void loop() {unsigned long int now;now = millis();if (now - time1 < HALF_TIME) {if (led1_state == LOW) {led1_state = HIGH;time1 = now + analogRead(sensorPin1) + 20; // HIGH time = analogRead() value}else {led1_state = LOW;time1 = now + analogRead(sensorPin1) + 20; // LOW time = 100 ms}digitalWrite(led1, led1_state);}// Rest of the program}EDIT:The maximum time it can be timed is 25 days (half the maximum time).

author: Picuino
author_rank: Super Contributor
timestamp: April 03, 2025, 04:42:01 pm
content: SIMULATION:https://wokwi.com/projects/427231355457607681CODE:Code:// Constantsconst int sensorPin1 = A0;const int led1 = 10;const int led2 = 11;const unsigned long int HALF_TIME = 0x80000000;// Global variablesunsigned long int time1, time2;char led1_state, led2_state;void setup() {// Setup the pins as OUTPUTpinMode(led1, OUTPUT);pinMode(led2, OUTPUT);// Setup times and led statestime1 = time2 = 0;led1_state = led2_state = LOW;}void loop() {unsigned long int now;now = millis();if (now - time1 < HALF_TIME) {if (led1_state == LOW) {led1_state = HIGH;time1 = now + analogRead(sensorPin1)*8 + 50; // HIGH time = Potentiometer value}else {led1_state = LOW;time1 = now + analogRead(sensorPin1)*8 + 50; // LOW time = Potentiometer value}digitalWrite(led1, led1_state);}if (now - time2 < HALF_TIME) {if (led2_state == LOW) {led2_state = HIGH;time2 = now + 500; // HIGH time = 500 ms}else {led2_state = LOW;time2 = now + 800; // LOW time = 800 ms}digitalWrite(led2, led2_state);}// Rest of the program}DIAGRAM:Code:{"version": 1,"author": "Anonymous maker","editor": "wokwi","parts": [{ "type": "wokwi-breadboard-mini", "id": "bb1", "top": -59, "left": 64.8, "attrs": {} },{ "type": "wokwi-arduino-uno", "id": "uno", "top": 96.6, "left": -0.6, "attrs": {} },{ "type": "wokwi-led", "id": "led1", "top": -80.4, "left": 71, "attrs": { "color": "red" } },{"type": "wokwi-led","id": "led2","top": -80.4,"left": 109.4,"attrs": { "color": "red" }},{"type": "wokwi-led","id": "led3","top": -80.4,"left": 147.8,"attrs": { "color": "red" }},{"type": "wokwi-resistor","id": "r1","top": 4.8,"left": 66.65,"rotate": 90,"attrs": { "value": "150" }},{"type": "wokwi-resistor","id": "r2","top": 4.8,"left": 105.05,"rotate": 90,"attrs": { "value": "150" }},{"type": "wokwi-resistor","id": "r3","top": 4.8,"left": 143.45,"rotate": 90,"attrs": { "value": "150" }},{ "type": "wokwi-potentiometer", "id": "pot1", "top": 209.9, "left": 287.8, "attrs": {} }],"connections": [[ "uno:GND.1", "bb1:2t.d", "black", [ "v-19.2", "h-28.5" ] ],[ "uno:12", "bb1:3b.i", "green", [ "v-28.8", "h-37.9" ] ],[ "uno:11", "bb1:7b.i", "green", [ "v-38.4", "h-9" ] ],[ "uno:10", "bb1:11b.i", "green", [ "v-28.8", "h19.9" ] ],[ "pot1:GND", "uno:GND.3", "black", [ "v38.4", "h-134.4" ] ],[ "pot1:VCC", "uno:5V", "red", [ "v57.6", "h-164" ] ],[ "pot1:SIG", "uno:A0", "green", [ "v48", "h-115.6" ] ],[ "bb1:2t.c", "bb1:6t.e", "black", [ "h19.2", "v19.2" ] ],[ "bb1:6t.c", "bb1:10t.c", "black", [ "v0" ] ],[ "led1:A", "bb1:3t.b", "", [ "$bb" ] ],[ "led1:C", "bb1:2t.b", "", [ "$bb" ] ],[ "led2:A", "bb1:7t.b", "", [ "$bb" ] ],[ "led2:C", "bb1:6t.b", "", [ "$bb" ] ],[ "led3:A", "bb1:11t.b", "", [ "$bb" ] ],[ "led3:C", "bb1:10t.b", "", [ "$bb" ] ],[ "r1:1", "bb1:3t.d", "", [ "$bb" ] ],[ "r1:2", "bb1:3b.h", "", [ "$bb" ] ],[ "r2:1", "bb1:7t.d", "", [ "$bb" ] ],[ "r2:2", "bb1:7b.h", "", [ "$bb" ] ],[ "r3:1", "bb1:11t.d", "", [ "$bb" ] ],[ "r3:2", "bb1:11b.h", "", [ "$bb" ] ]],"dependencies": {}}

author: Larsson55
author_rank: Regular Contributor
timestamp: April 03, 2025, 06:07:06 pm
content: Quote from: Ian.M on April 03, 2025, 03:10:41 pm

author: SteveThackery
author_rank: Super Contributor
timestamp: April 03, 2025, 08:38:48 pm
content: Quote from: Larsson55 on April 03, 2025, 06:07:06 pmOf course it can, and in fact the first real "project" nearly everyone does with Arduino is Blinky, which requires no hardware at all. Yes, it is trivial, but it's a starting point if you aren't familiar with coding and you can grow from there.Even now you seem to reject the idea of actually learning some code, and instead expect others to deliver a cut-and-paste solution for you. You say learning code "can't happen" on the first project, but this is absolute nonsense. It most certainly can, and it should. After all, the robot itself is just a kit: it's not like you need to use much brain power to put it together and you won't learn much from it apart from some soldering skills, maybe. So I don't buy your story that somehow you can't learn any code because it's your first project. I suspect in reality you don't want to be bothered, and just want the robot to work.Quote from: Larsson55 on April 03, 2025, 06:07:06 pmI don't believe you. You are saying that to justify your "I don't do code" position. It is still there in the back of your mind, and as you make the effort it will start to come back to you, I promise. I learned some Forth about 45 years ago, and quickly abandoned it, moving on to 'C', but if I think back I can still remember bits of it (the '.' character for 'print') and more would come back if I had a go at it now.If you really do want to learn Arduino, then start at the bottom of the learning curve instead of half way up like you did with the robot. The Internet is chock full of Arduino tutorials - you will find one to suit you.

author: Larsson55
author_rank: Regular Contributor
timestamp: April 03, 2025, 09:22:32 pm
content: Back again Ian, hopefully all will not forget anything and I would also like to mention that the included code has been revised by me with my limited knowledge and may contain mistakes but it works.Code:/** Firmware for the "2WD Ultrasonic Motor Robot Car Kit"** Stephen A. Edwards** Hardware configuration:* A pair of DC motors driven by an L298N H bridge motor driver* An HC-SR04 ultrasonic range sensor mounted atop a small hobby servo*/#include <Servo.h>// Ultrasonic Module pinsconst int trigPin = 13; // 10 microsecond high pulse causes chirp, wait 50 usconst int echoPin = 12; // Width of high pulse indicates distance// Servo motor that aims ultrasonic sensor.const int servoPin = 11; // PWM output for hobby servo// Motor control pins: L298N H bridgeconst int enAPin = 6; // Left motor PWM speed controlconst int in1Pin = 7; // Left motor Direction 1const int in2Pin = 5; // Left motor Direction 2const int in3Pin = 4; // Right motor Direction 1const int in4Pin = 2; // Right motor Direction 2const int enBPin = 3; // Right motor PWM speed controlServo servo;enum Motor { LEFT,RIGHT };// Set motor speed: 255 full ahead, -255 full reverse, 0 stopvoid go(enum Motor m, int speed) {digitalWrite(m == LEFT ? in1Pin : in3Pin, speed > 0 ? HIGH : LOW);digitalWrite(m == LEFT ? in2Pin : in4Pin, speed <= 0 ? HIGH : LOW);analogWrite(m == LEFT ? enAPin : enBPin, speed < 0 ? -speed : speed);}// Read distance from the ultrasonic sensor, return mm//// Speed of sound in dry air, 20C is 343 m/s// pulseIn returns time in microseconds (10^-6)// 2d = p * 10^-6 s * 343 m/s = p * 0.00343 m = p * 0.343 mm/usunsigned int readDistance() {digitalWrite(trigPin, HIGH);delayMicroseconds(10);digitalWrite(trigPin, LOW);unsigned long period = pulseIn(echoPin, HIGH);return period * 343 / 2000;}#define NUM_ANGLES 7unsigned char sensorAngle = { 60, 70, 80, 90, 100, 110, 120 };unsigned int distance;// Scan the area ahead by sweeping the ultrasonic sensor left and right// and recording the distance observed. This takes a reading, then// sends the servo to the next angle. Call repeatedly once every 100 ms or so.void readNextDistance() {static unsigned char angleIndex = 0;static signed char step = 1;distance = readDistance();angleIndex += step;if (angleIndex == NUM_ANGLES - 1) step = -1;else if (angleIndex == 0) step = 1;servo.write(sensorAngle);}// Initial motor test:// left motor forward then back// right motor forward then backvoid testMotors() {static int speed = { 128, 255, 128, 0,-128, -255, -128, 0 };go(RIGHT, 0);for (unsigned char i = 0; i < 8; i++)go(LEFT, speed), delay(200);for (unsigned char i = 0; i < 8; i++)go(RIGHT, speed), delay(200);}// Initial configuration:// Configure the input and output pins// Center the servo// Turn off the motors// Test the motors// Scan the surroundingsvoid setup() {pinMode(trigPin, OUTPUT);pinMode(echoPin, INPUT);digitalWrite(trigPin, LOW);pinMode(enAPin, OUTPUT);pinMode(in1Pin, OUTPUT);pinMode(in2Pin, OUTPUT);pinMode(in3Pin, OUTPUT);pinMode(in4Pin, OUTPUT);pinMode(enBPin, OUTPUT);servo.attach(servoPin);servo.write(90);go(LEFT, 0);go(RIGHT, 0);// Initial motor test: verify both left and right motors are working// and connected in the right directiontestMotors();// Scan the surroundings before starting offservo.write(sensorAngle);delay(200);for (unsigned char i = 0; i < NUM_ANGLES; i++)readNextDistance(), delay(200);}// Main loop:// Get the next sensor reading// If anything appears to be too close, back up// Otherwise, go forwardvoid loop() {readNextDistance();// See if something is too close at any angleunsigned char clear = 1;for (unsigned char i = 0; i < NUM_ANGLES; i++)if (distance < 300)clear = 0;if (clear) {// Nothing in our way: go forwardgo(LEFT, 255);go(RIGHT, 255);} else {// Something's nearby: back up leftgo(LEFT, -180);go(RIGHT, -80);}// Check the next direction in 50 msdelay(50);}And here is the link for the YouTube Video, not very good quality but you can see the robot workinghttps://youtu.be/gTlKTYUfj9cAnd finally the wiring schematic is attachedMany thanks

author: Ian.M
author_rank: Super Contributor
timestamp: April 04, 2025, 02:11:51 pm
content: Overall, good work so far, but there are a few issues.You've got the ultrasound sensor protruding past the front of the chassis. That's asking for trouble, as any failure to detect an obstacle, e.g. when turning sharply, can result in ramming the obstacle with the sensor, which sooner or later will break the servo/pan mount, or the sensor itself. If you are going to have stuff protruding over the chassis edge, you will need to add impact absorbing bumpers to the chassis extending out to protect them.The other clear issue is its definitely nose heavy, with the COG too high up. See video at 0:10 where it nose-dives coming off the edge of the ?carpet. That's down to battery placement. If you cant easily fix it, try adding a dense weight, right at the back, under the chassis at the caster.Lastly, your schematic isn't! Its some mashup of a wiring diagram and a list of connections. Seehttps://electronics.stackexchange.com/questions/105136/whats-a-schematic-compared-to-other-diagrams.A fritzing style wiring diagram is often very hard to follow and a lot of work to create.Where to go from here?You haven't done anything yet with the speed sensors. Back in reply#145, I posted a link to a DronebotWorkshops tutorial for them and noted that you would have to re-do the duPont wiring to the sensor shield for compatibility (and update the robot-car.ino sketch to match), as the speed sensors need the digital 2/INT0 and 3/INT1 pins which are currently used for the right motor.There are some other constraints:The only hardware PWM capable pins on an Arduino are digital pins 3, 5, 6, 9, 10, 11. Pins 5 & 6 are controlled by timer 0, pins 9 & 10 by timer 1 and pins 3 & 11 by timer 3.Timer 0 is used by millis(), micros() and delay() so changing the PWM frequency will mess with those. Pins 5 & 6 analogWrite() default 976 Hz PWM is fine for motor control.Timer 1 is used by the Servo library. You cannot use PWM on pins 9 or 10 while controlling a servo.That means the only viable PWM pins for driving the H-bridge enable pins, on a robot with speed sensors and one or more servos, are digital pins 5 and 6.Note that the DroneBot Workshop tutorial doesn't have a servo or ultrasound sensor, and they haveenaon pin 10 andin4on pin 6. If you want to add obstacle detection to their code, you'll need to swap those pins.For reference, here's my current (and preferred) 2WD robot duPont wiring hookup. Its not the same as the Prof. Edwards or DroneBot Workshop hookups, so you'd need to redefine the pins in their sketches if you chose to use it.Code:Current wiring table====================Left motor is A, right motor is B.<...<, and >...> indicate direction of signal in wire.Module PIN <wire> Module PIN (func) // comments-----------------------------------------------L298 ENA <orange< Uno/SS 5 (fast PWM)L298 ENB <l.gray< Uno/SS 6 (fast PWM)L298 IN1 <yellow< Uno/SS 7 (Left, FWD)L298 IN2 <green< Uno/SS 8 (Left, REV)L298 IN3 <blue< Uno/SS 9 (Right, REV)L298 IN4 <violet< Uno/SS 11 (Right, FWD)L.Opto.Int D0 >grey> Uno/SS 3 (INT)R.Opto.Int D0 >white> Uno/SS 2 (INT)L/R.Opto.Int Vcc <violet< SS V(d)L/R.Opto.Int GND <black< SS GServo Pulse <orange< Uno/SS 4Servo Vcc <red< SS V(d)Servo GND <brown< SS GHC-SR04 Echo >brown> Uno/SS A2HC-SR04 Pulse <white< Uno/SS A3HC-SR04 Vcc <red< SS V(a)HC-SR04 Gnd <black< SS GndVcc/5V and Gnd wiring comes from the SS V and Gnd pins closest to the associated signal pin.Optional wired Joystick=====================Joystick X-axis >---> Uno/SS A0Joystick Y-axis >---> Uno/SS A1Joystick SW >---> Uno/SS 12Joystick Gnd <---< SS GndJoystick Vcc <---< SS V(a)UNO/SS is the Sensor shield (on an UNO). V(d) is 5V from the sensor shield digital pin block, supplied from the H-bridge module, and noisy due to the high load of the servo motor. V(a) is 5V from the analog pin block, far less noisy as it comes from the Arduino onboard regulator which doesn't have any high current pulsed loads.I should probably move the speed sensors Vcc supply to V(a) pins to avoid speed jitter when the servo is moving.Some useful links:https://docs.arduino.cc/tutorials/generic/secrets-of-arduino-pwm/https://dronebotworkshop.com/robot-car-with-speed-sensors/https://docs.sunfounder.com/projects/sf-components/en/latest/component_l298n_module.htmlhttps://protosupplies.com/product/sensor-shield-v5-0/

author: Larsson55
author_rank: Regular Contributor
timestamp: April 04, 2025, 05:37:47 pm
content: You are very observant Ian, thanks for all your comments and linksRegarding the speed sensors I went to the site you mentioned in post #145 but he is using a different sensor than the ones I have which are LM393. The speed sensors are not so important at this stage since later on I plan to add, if possible, either a remote control or a joy stick which I have the parts from the Elegoo kit.I noticed the car is nose heavy and it will be good to add some weight at the back as you are suggesting.. I also revised the support of the ultrasonic sensor (see attached) from another similar robot I found.You don't like my schematic? LOL, you are right it's more like a combo of a block diagram and schematic and it needs more work which eventually will be done.I have printed your reply and will go over carefully to re do the speed sensors wiring and implement the revised codeMuch appreciated

author: Larsson55
author_rank: Regular Contributor
timestamp: April 04, 2025, 10:16:54 pm
content: Another version of the wiring schematic

author: Ian.M
author_rank: Super Contributor
timestamp: April 04, 2025, 11:04:47 pm
content: Nice block diagram / module level schematic. Together with a copy of the sensor shield pinout (from Proto Supplies) that's all one needs for anyone to easily reproduce your robot wiring.Although DroneBot Workshop are using different sensors, yours are sufficiently compatible*to use the same software. Just use their DO outputs, and connect them via the sensor shield.I'd turn the servo support the other way around with the upright near the batteries, and re-mount the servo horn to keep the sensor facing forward when centered. That gets it mostly back within the robot outline and reduces the risk of damage.* There is a possibility their sensor outputs are inverted, which would matter for a limit switch or similar beam break detection application, but as they are being used with an encoder wheel that would just shift the pulse from slot to spoke or visa versa.

author: Larsson55
author_rank: Regular Contributor
timestamp: April 04, 2025, 11:47:01 pm
content: Very happy you like my new diagram Ian,I understand about the DroneBot and I will follow their DO outputsI was planning of doing similar relocation on the servo support and will post new picture when done.Many thanks again for your support

author: Larsson55
author_rank: Regular Contributor
timestamp: April 05, 2025, 12:56:03 pm
content: Attached is the revised servo support, it even looks better,Reading the DroneBot page about the speed sensors I noticed he is using the same pins between the L298 and the SensorShield. The alternative I can think is to connect the speed sensors including the 2 wheels motors directly to UNO. Is this what I should do?

author: Ian.M
author_rank: Super Contributor
timestamp: April 05, 2025, 01:26:34 pm
content: Keep the sensor shield - it makes power and ground distribution to the sensors and sertvos *SO* much easier. Simply use the equivalent Arduino pin numbers from DroneBot Workshop to hook up to the sensor shield.Of course the L298 *CAN'T* share pins with the sensors and the sensors *MUST* be on INT0 and INT1. I discussed the pin conflicts and hardware constraints back in reply #169. If you don't mind patching all the sketches to match, you may wish to adopt my wiring, which resolves all the conflicts, and allows for adding additional sensors orI2C devices later.

author: Larsson55
author_rank: Regular Contributor
timestamp: April 05, 2025, 04:48:55 pm
content: There is a problem with the Forum? I have difficulty accessing the pages...Ok, I will adopt your wiring Ian as per your last post however I just remember I have no more Dupont terminals to do any work. I ordered a set of them in a kit and hope they are what I need. I didn't want to order a crimping tool because they are a myriad expensive choices and as hobbyist I don't know which one is good for me. I do have 2 crimping tools which I think they may do the job so I have to wait to get the terminals first and if my tools don't work I could use a needlenose plyers for now and then try to get a suitable tool later. Terminals will be here by April-28

author: Ian.M
author_rank: Super Contributor
timestamp: April 05, 2025, 06:08:21 pm
content: Yes, the official crimper for just about any major brand 0.1" pitch connector system will cost you an arm and a leg. Of the 'value' crimpers, a SN28B ratchet crimper withgooddies can do a reasonable (but not correct) crimp for far east 'duPont' contacts. A good TZ- or SN-4228B does the correct crimp, that fits in the connector shell without further work. However there are many crappy clones of these crimpers with out of tolerance dies that don't mate properly or even that have completely wrong profiles so fail to form a crimp that will pass a 'tug' test.Seehttps://www.eevblog.com/forum/reviews/affordable-crimp-tools-for-small-connectors-(dupont-etc-)/and make sure you buy from a supplier that will accept returns without hassle.

author: Larsson55
author_rank: Regular Contributor
timestamp: April 06, 2025, 09:51:26 am
content: Thanks for the info Ian regarding the crimper tool, I have one which looks similar to the SN28B so have to wait to receive the terminals first. The Dupont terminals will be here around the end of April and while waiting I'm planning to relocate the battery pack above the swivel wheel with some kind of a bracket which may protrude above and behind the swivel.Also I have a hard time inserting/removing the USB cable to Uno and I'm afraid I may brake the Uno board. Is there a trick or something to plug the USB cable there?Reading on the DBW site about the speed sensors I don't see the benefits I will get from these sensors. Knowing the actual speed, how far the robot traveled etc, is not of interest to me unless I miss something.However I would have liked to install if possible a remote control from the parts I have from the Elegoo kit (IR module and IR remote). Is it possible to have this remote control installed?

author: Ian.M
author_rank: Super Contributor
timestamp: April 06, 2025, 12:26:14 pm
content: I'd recommend *not* extending anything past the rear of the robot. As there are no rear facing sensors, there is a high risk of slamming it into any obstacle when manoeuvring. I would recommend my robot's layout, with the batteries as low as possible immediately in front of the Arduino + Sensor shield, and the H-bridge underneath, between the motors. However you will need the capability to make duPont cables to length to wire it up neatly with no risk of any cables dragging, so will need to wait for the terminals before moving stuff around.The USB cable should ease with use. However you could try a different cable. Any decent quality USB A to B (i.e. 'printer') cable should do. This is why you need FOUR standoffs and FOUR screws securing the Arduino!What the speed sensors give you is how far each wheel has turned in a particular direction. One motor will always be slightly faster than the other (at the same PWM duty cycle) due to slight differences in friction, so the robot tends to follow a slight curve rather than driving straight. If you use the speed sensors to determine the difference, and slow the faster motor down slightly so the speed sensors match the robot will run far straighter, with any remaining difference being due to slight differences in wheel diameter.Knowing the wheel's diameter and distance from the centerline, you can also calculate how much to turn them in opposite directions to turn the robot on the spot through aknownangle. This would be impossible without speed sensors as the speed of the motor is dependent on PWM, load and battery voltage, so the time to turn through a known angle is fairly variable.You can add IR remote functionality, and you can easily trigger different actions on receipt of a IR button code. However simple IR remotes aren't much use for 'live' robot control, as you cant accurately determine how long a button has been pressed so steering in particular is problematic. Also, you would have to write the code from scratch

author: Larsson55
author_rank: Regular Contributor
timestamp: April 06, 2025, 01:03:00 pm
content: Thanks Ian, I should have waited for your answer cause now the new battery location is too heavy at the rear. As you suggested I will relocate the H-bridge and do the layout as per yours.I will also install four standoffs on the Uno instead of the two I have now. I tried different USB cables but did not improve, perhaps as you say with time it will improve.I now understand that the speed sensors provide much more than I thought and regarding the IR remote it can wait for later.Many thanks

author: Ian.M
author_rank: Super Contributor
timestamp: April 07, 2025, 05:11:39 am
content: Yes. As you have found out, stability is a problem for 2WD robots with a rear caster. To avoid tipping, the center of gravity (COG) , vertically projected to ground level, must always be within a triangle formed by its three points of contact with the ground. This is complicated by the swing of the rear caster, which means the effective stability triangle is bounded by the line joining two wheels points of contact, and two crossing tangents to a circle defined by the castor's point of contact with the ground as it swings, extending to the wheels points of contact. Thus the rear point of the stability triangle is quite a bit forward of the caster contact circle. Then you have to consider dynamic stability, which requires the COG to be low enough and far enough within the triangle to resist toppling due to acceleration (i.e. braking or turning) or tilting due to uneven or inclined surfaces.

author: Langdon
author_rank: Frequent Contributor
timestamp: April 14, 2025, 02:15:31 pm
content: You can always use 22AWG solid core wire as a male dupont connector.

author: Larsson55
author_rank: Regular Contributor
timestamp: April 14, 2025, 09:34:36 pm
content: Quote from: Langdon on April 14, 2025, 02:15:31 pmGood to know I can use 22 wire gauge as a male Dupont connector, thanks

author: Larsson55
author_rank: Regular Contributor
timestamp: April 19, 2025, 12:10:25 pm
content: Finally the Battery pack and L298 Bridge are switched and looking much better but remains to do the re wiring.I also received my Dupont connectors and since I never used this kind of connectors I wonder how it works. The connectors are hard plastic so if I put a connector into the griper tool to my opinion the connector will crack when I squeeze the trigger. So how do you use these connectors?

author: pcprogrammer
author_rank: Super Contributor
timestamp: April 19, 2025, 12:23:11 pm
content: Quote from: Larsson55 on April 19, 2025, 12:10:25 pmThe Dupont connectors consist of two parts. The plastic housing is just an exterior shell to protect against shorts. The inner part is a metallic piece that has at one end the part that sits over the pin (or is the pin) and on the other end an open bit of metal that can be crimped around the wire. Actually there are two parts to that. The section that crimps over the bare wire and a smaller bit that crimps over the insulation.https://www.aliexpress.com/item/1005006626744976.htmlThis link shows what the internal bits look like. The bit that is attached to the long strip holding all of them together is where the wire goes. Your crimp tool will have a distinct shape that allows for the part that goes on the insulation to be crimped wider than what goes on the bare wire.

author: Ian.M
author_rank: Super Contributor
timestamp: April 19, 2025, 01:23:20 pm
content: The crimped contacts assembled on the wire ends should just slide into the housing shell, from the end with the bigger hole, and the little tongue on the side of the housing is pushed out slightly as the contact goes in, then drops back behind the square box section part of the contact to latch it in place. The formerly open side of the crimp must face the tongue*. If the crimper has the wrong (or out of tolerance) dies, the back (insulation crimp) section of the contact may be too wide to easily slide into the shell, so you may need to nip it sideways slightly to narrow it enough to go in without excessive force.N.B. to get the contact back out of the housing without damage you need to lift the tongue, e.g. with a fine mounted needle, and hold it up slightly while you pull on the wire to get the edge of the box section past the end of the tongue so you can slide the contact out.* This isn't difficult for single wires, but can be a PITA when terminating ribbon cable as you need to orient the crimps while making them to get the open side on the correct side for the housing. Its a particular nuisance when using a double row housing, and trying to match the pinout of an IDC connecter as every other contact must face the other way.

author: Larsson55
author_rank: Regular Contributor
timestamp: April 19, 2025, 03:15:25 pm
content: Now I got it, my thanks to both