Force Sensor + DC motor

hello everyone,

I’m a beginner with XOD and I have a project where I want to control the speed with DC motor or brushless motor with a Force sensor so as much power I apply on the sensor as much speed I get from the motor. However, I am finding difficulties in writing the program in XOD.
Please, can anyone help?

Thank you so much

I assume your force sensor is read using analog-read & motor speed is controlled using PWM through an H-bridge. Since output of analog-read is 0-1 and input for PWM 0-1, you can simply connect the two together. There are several analog nodes you might use for reading the input & at least one h-bridge node for controlling the motor.

1 Like

Maybe if you post your attempt then someone could advise

You may consider using the “map” node to hone in your sensor values to output signal

Thank you very much for your reply
here I uploaded 2 photos one for the code I’m using in XOD and in another comment I’ll upload a photo of the circuit - cuz I’m not allowed to post 2 photos - I’m following but instead of the button I need to put Force Sensor

xod-1%20
here is the photo of the circuit

It is not clear what everything is in your wiring diagram, so I’m not certain what you are doing. Are you using a mechanical relay for motor control? That is not going to be able to switch on & off fast enough to control speed. If the transistor is your “relay”, then it might work, but you want to use PWM output pin to control the transistor on/off for speed control.

The h-bridge node is assuming you have an h-bridge controller for the motor. The DR & PWM pins on the h-bridge need to be set to the pin numbers you’ve wired the h-bridge to. If you are just using a relay or transistor for motor control, then you don’t really need the h-bridge node.

The output for analog-read is between 0 & 1, so there is no need for the max node, and the less node comparing it to 500 will always be true.

On the H-bridge-dc-motor node, you probably want to set the PWM port different to the DIR (direction) signal output