Electronic – How to simulate analogue output sensor with MCP3008 ADC. Can I use a 10K potentiometer with Raspberry Pi 3.3v

adcpotentiometerraspberry pisignal

I am working through a series of lessons with the Raspberry Pi 3 Model B and the next lesson is Raspberry Pi Starter Kit Lesson 10: Raspberry Pi SPI Ports which involves hooking up a MCP3008 ADC output to several pins on the Raspberry Pi and then connecting two of the ADC analogue input pins to the 3.3v rail and the GND rail with a reference voltage of 3.3v from the 3.3v rail.

connections graph for MCP3008 ADC and Raspberry Pi

What I would like to do is to be able to vary the input to the MCP3008 ADC to simulate a sensor such as an analogue temperature sensor.

I was wondering if I could do this by adding a 10K ohm potentiometer in connection between the 3.3v rail and CH0 of the MCP3008 ADC?

Addendum: adding PWM driven LED with varying levels

After adding in the potentiometer, connecting the wiper output to CH2, and looking at the numbers change as I changed the knob setting, I then modified the circuit by adding an LED to GPIO #18, the hardware PWM pin.

So the modified application used a loop to query the relative voltage level, 0 to 1023, from the MCP3008 on the channel to which the potentiometer was connected, CH2. The value was then used to set the Duty Cycle of the GPIO #18 pin which was provisioned as Pulse Width Modulation (PWM) with the default range of 1024. Changing the Duty Cycle in turn changed the illumination level of the LED. So as the knob on the potentiometer was twisted to a new setting, the LED brightness level changed.

Addendum: Use photo-resistor with MCP3008 as alternative

An alternative to using a potentiometer is to use a photo-resistor connected to ground with a 10K ohm pullup resistor connected to the 3.3v rail. A connection is then made between a channel pin of the MCP3008 and a connection point between the 10K ohm resistor and the photo-resistor.
enter image description here

The result of this circuit is to provide voltage levels that vary depending on the amount of light the photo-resistor sees. Light levels can be made to vary by using a shading device such as a physical paper tube over the photo-resistor or by using a flashlight to illuminate the photo-resistor.

Addendum: SPI protocol with MCP3008

Here is a nice tutorial and explanation of the MCP3008 and how to interface to it with SPI. Interfacing an SPI ADC (MCP3008) chip to the Raspberry Pi using C++ (spidev).

Best Answer

Yes, you can use a pot to provide a variable input to the ADC.

Connect one end of the pot to +3.3V, the other end to Ground, and the wiper to the input of the ADC. As you turn the pot, the voltage at the wiper will vary between 0 and 3.3 V.