# Force Sensor + DC motor

**URL:** <https://forum.xod.io/t/force-sensor-dc-motor/2899>\
**Category:** Uncategorized\
**Created:** [November 23, 2019, 8:37pm UTC](https://forum.xod.io/t/force-sensor-dc-motor/2899 "2019-11-23T20:37:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nadine-mahfoud](https://avatars.discourse-cdn.com/v4/letter/n/e19adc/32.png) [@nadine-mahfoud](https://forum.xod.io/u/nadine-mahfoud)\
**Post date:** [November 23, 2019, 8:37pm UTC](https://forum.xod.io/t/force-sensor-dc-motor/2899/1 "2019-11-23T20:37:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [November 24, 2019, 1:04am UTC](https://forum.xod.io/t/force-sensor-dc-motor/2899/2 "2019-11-24T01:04:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![robertspark](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@robertspark](https://forum.xod.io/u/robertspark)\
**Post date:** [November 24, 2019, 2:26pm UTC](https://forum.xod.io/t/force-sensor-dc-motor/2899/3 "2019-11-24T14:26:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nadine-mahfoud](https://avatars.discourse-cdn.com/v4/letter/n/e19adc/32.png) [@nadine-mahfoud](https://forum.xod.io/u/nadine-mahfoud)\
**Post date:** [November 24, 2019, 8:17pm UTC](https://forum.xod.io/t/force-sensor-dc-motor/2899/4 "2019-11-24T20:17:59Z")

</div>

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%20](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/5/5cf71839122e84f498cf3375d40412a93e64adf2.jpeg)

---

<div class="post-metadata">

**Author:** ![nadine-mahfoud](https://avatars.discourse-cdn.com/v4/letter/n/e19adc/32.png) [@nadine-mahfoud](https://forum.xod.io/u/nadine-mahfoud)\
**Post date:** [November 24, 2019, 8:18pm UTC](https://forum.xod.io/t/force-sensor-dc-motor/2899/5 "2019-11-24T20:18:37Z")

</div>

![xod-1%20](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/5/58e43a23a3a0afffbf68833b9b088a7af197100f.jpeg)  
here is the photo of the circuit

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [November 25, 2019, 1:40am UTC](https://forum.xod.io/t/force-sensor-dc-motor/2899/6 "2019-11-25T01:40:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![robertspark](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@robertspark](https://forum.xod.io/u/robertspark)\
**Post date:** [November 25, 2019, 3:23pm UTC](https://forum.xod.io/t/force-sensor-dc-motor/2899/7 "2019-11-25T15:23:42Z")

</div>

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